// Allocator traits -*- C++ -*-
-// Copyright (C) 2011, 2012 Free Software Foundation, Inc.
+// Copyright (C) 2011, 2012, 2013 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
+ template<typename _Tp>
+ class allocator;
+
template<typename _Alloc, typename _Tp>
class __alloctr_rebind_helper
{
template<typename _Tp, typename... _Args>
static typename
- enable_if<!__construct_helper<_Tp, _Args...>::value, void>::type
+ enable_if<__and_<__not_<__construct_helper<_Tp, _Args...>>,
+ is_constructible<_Tp, _Args...>>::value, void>::type
_S_construct(_Alloc&, _Tp* __p, _Args&&... __args)
{ ::new((void*)__p) _Tp(std::forward<_Args>(__args)...); }
* arguments @a __args...
*/
template<typename _Tp, typename... _Args>
- static void construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
+ static auto construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
+ -> decltype(_S_construct(__a, __p, std::forward<_Args>(__args)...))
{ _S_construct(__a, __p, std::forward<_Args>(__args)...); }
/**
__do_alloc_on_swap(__one, __two, __pocs());
}
+ template<typename _Alloc>
+ class __is_copy_insertable_impl
+ {
+ typedef allocator_traits<_Alloc> _Traits;
+
+ template<typename _Up, typename
+ = decltype(_Traits::construct(std::declval<_Alloc&>(),
+ std::declval<_Up*>(),
+ std::declval<const _Up&>()))>
+ static true_type
+ _M_select(int);
+
+ template<typename _Up>
+ static false_type
+ _M_select(...);
+
+ public:
+ typedef decltype(_M_select<typename _Alloc::value_type>(0)) type;
+ };
+
+ // true if _Alloc::value_type is CopyInsertable into containers using _Alloc
+ template<typename _Alloc>
+ struct __is_copy_insertable
+ : __is_copy_insertable_impl<_Alloc>::type
+ { };
+
+ // std::allocator<_Tp> just requires CopyConstructible
+ template<typename _Tp>
+ struct __is_copy_insertable<allocator<_Tp>>
+ : is_copy_constructible<_Tp>
+ { };
+
+ // Used to allow copy construction of unordered containers
+ template<bool> struct __allow_copy_cons { };
+
+ // Used to delete copy constructor of unordered containers
+ template<>
+ struct __allow_copy_cons<false>
+ {
+ __allow_copy_cons() = default;
+ __allow_copy_cons(const __allow_copy_cons&) = delete;
+ __allow_copy_cons(__allow_copy_cons&&) = default;
+ __allow_copy_cons& operator=(const __allow_copy_cons&) = default;
+ __allow_copy_cons& operator=(__allow_copy_cons&&) = default;
+ };
+
+ template<typename _Alloc>
+ using __check_copy_constructible
+ = __allow_copy_cons<__is_copy_insertable<_Alloc>::value>;
+
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace std