diff options
| author | Eric Fiselier <eric@efcs.ca> | 2016-12-14 21:29:29 +0000 |
|---|---|---|
| committer | Eric Fiselier <eric@efcs.ca> | 2016-12-14 21:29:29 +0000 |
| commit | 4ffd08cae91e6bfbf1519420aeb096964d27fd39 (patch) | |
| tree | 14d8bd3bb9ab233e6ed25243c132f2ada96a8c59 /libcxx/include/scoped_allocator | |
| parent | fec6be9c8150244c98bc2ac2bcac326fce49001a (diff) | |
| download | bcm5719-llvm-4ffd08cae91e6bfbf1519420aeb096964d27fd39.tar.gz bcm5719-llvm-4ffd08cae91e6bfbf1519420aeb096964d27fd39.zip | |
[libcxx] Fix PR24075, PR23841 - Add scoped_allocator_adaptor::construct(pair<T, U>*, ...) overloads.
Summary:
For more information see:
* https://llvm.org/bugs/show_bug.cgi?id=23841
* https://llvm.org/bugs/show_bug.cgi?id=24075
I hope you have as much fun reviewing as I did writing these insane tests!
Reviewers: mclow.lists, AlisdairM, EricWF
Subscribers: AlisdairM, Potatoswatter, cfe-commits
Differential Revision: https://reviews.llvm.org/D27612
llvm-svn: 289710
Diffstat (limited to 'libcxx/include/scoped_allocator')
| -rw-r--r-- | libcxx/include/scoped_allocator | 87 |
1 files changed, 83 insertions, 4 deletions
diff --git a/libcxx/include/scoped_allocator b/libcxx/include/scoped_allocator index 04e73864590..605f70b472f 100644 --- a/libcxx/include/scoped_allocator +++ b/libcxx/include/scoped_allocator @@ -498,8 +498,58 @@ public: template <class _Tp, class... _Args> _LIBCPP_INLINE_VISIBILITY void construct(_Tp* __p, _Args&& ...__args) - {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type, _Args...>(), + {__construct(__uses_alloc_ctor<_Tp, inner_allocator_type&, _Args...>(), __p, _VSTD::forward<_Args>(__args)...);} + + template <class _T1, class _T2, class... _Args1, class... _Args2> + void construct(pair<_T1, _T2>* __p, piecewise_construct_t, + tuple<_Args1...> __x, tuple<_Args2...> __y) + { + typedef __outermost<outer_allocator_type> _OM; + allocator_traits<typename _OM::type>::construct( + _OM()(outer_allocator()), __p, piecewise_construct + , __transform_tuple( + typename __uses_alloc_ctor< + _T1, inner_allocator_type&, _Args1... + >::type() + , _VSTD::move(__x) + , typename __make_tuple_indices<sizeof...(_Args1)>::type{} + ) + , __transform_tuple( + typename __uses_alloc_ctor< + _T2, inner_allocator_type&, _Args2... + >::type() + , _VSTD::move(__y) + , typename __make_tuple_indices<sizeof...(_Args2)>::type{} + ) + ); + } + + template <class _T1, class _T2> + void construct(pair<_T1, _T2>* __p) + { construct(__p, piecewise_construct, tuple<>{}, tuple<>{}); } + + template <class _T1, class _T2, class _Up, class _Vp> + void construct(pair<_T1, _T2>* __p, _Up&& __x, _Vp&& __y) { + construct(__p, piecewise_construct, + _VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x)), + _VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__y))); + } + + template <class _T1, class _T2, class _Up, class _Vp> + void construct(pair<_T1, _T2>* __p, const pair<_Up, _Vp>& __x) { + construct(__p, piecewise_construct, + _VSTD::forward_as_tuple(__x.first), + _VSTD::forward_as_tuple(__x.second)); + } + + template <class _T1, class _T2, class _Up, class _Vp> + void construct(pair<_T1, _T2>* __p, pair<_Up, _Vp>&& __x) { + construct(__p, piecewise_construct, + _VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x.first)), + _VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__x.second))); + } + template <class _Tp> _LIBCPP_INLINE_VISIBILITY void destroy(_Tp* __p) @@ -515,6 +565,7 @@ public: private: + template <class _OuterA2, class = typename enable_if< is_constructible<outer_allocator_type, _OuterA2>::value @@ -545,9 +596,7 @@ private: allocator_traits<typename _OM::type>::construct ( _OM()(outer_allocator()), - __p, - allocator_arg, - inner_allocator(), + __p, allocator_arg, inner_allocator(), _VSTD::forward<_Args>(__args)... ); } @@ -566,6 +615,36 @@ private: ); } + template <class ..._Args, size_t ..._Idx> + _LIBCPP_INLINE_VISIBILITY + tuple<_Args&&...> + __transform_tuple(integral_constant<int, 0>, tuple<_Args...>&& __t, + __tuple_indices<_Idx...>) + { + return _VSTD::forward_as_tuple(_VSTD::get<_Idx>(_VSTD::move(__t))...); + } + + template <class ..._Args, size_t ..._Idx> + _LIBCPP_INLINE_VISIBILITY + tuple<allocator_arg_t, inner_allocator_type&, _Args&&...> + __transform_tuple(integral_constant<int, 1>, tuple<_Args...> && __t, + __tuple_indices<_Idx...>) + { + using _Tup = tuple<allocator_arg_t, inner_allocator_type&, _Args&&...>; + return _Tup(allocator_arg, inner_allocator(), + _VSTD::get<_Idx>(_VSTD::move(__t))...); + } + + template <class ..._Args, size_t ..._Idx> + _LIBCPP_INLINE_VISIBILITY + tuple<_Args&&..., inner_allocator_type&> + __transform_tuple(integral_constant<int, 2>, tuple<_Args...> && __t, + __tuple_indices<_Idx...>) + { + using _Tup = tuple<_Args&&..., inner_allocator_type&>; + return _Tup(_VSTD::get<_Idx>(_VSTD::move(__t))..., inner_allocator()); + } + template <class...> friend class __scoped_allocator_storage; }; |

