Skip to content
Permalink
Browse files

Example conversion for `deque`, using [[trivially_relocatable(bool)]].

  • Loading branch information...
Quuxplusone committed Jan 15, 2019
1 parent 0533994 commit 5caede0e633dc64fb89ed46c4f8be447f2859008
Showing with 25 additions and 1 deletion.
  1. +8 −0 include/__config
  2. +17 −1 include/deque
@@ -1281,6 +1281,14 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
#define _LIBCPP_HAS_NO_IS_AGGREGATE
#endif

#ifndef _LIBCPP_TRIVIALLY_RELOCATABLE
#if __has_extension(trivially_relocatable)
#define _LIBCPP_TRIVIALLY_RELOCATABLE(x) [[clang::trivially_relocatable(x)]]
#else
#define _LIBCPP_TRIVIALLY_RELOCATABLE(x)
#endif
#endif

#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L
#define _LIBCPP_HAS_NO_COROUTINES
#endif
@@ -920,6 +920,22 @@ __deque_base_common<__b>::__throw_out_of_range() const
_VSTD::__throw_out_of_range("deque");
}

template <class _Allocator>
struct __deque_allow_trivial_relocation {
typedef _Allocator allocator_type;
typedef allocator_traits<allocator_type> __alloc_traits;
typedef typename __alloc_traits::pointer pointer;
typedef typename __alloc_traits::size_type size_type;
typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator;

typedef integral_constant<bool,
is_trivially_relocatable<pointer>::value &&
is_trivially_relocatable<__pointer_allocator>::value &&
is_trivially_relocatable<size_type>::value &&
is_trivially_relocatable<allocator_type>::value
> type;
};

template <class _Tp, class _Allocator>
class __deque_base
: protected __deque_base_common<true>
@@ -1191,7 +1207,7 @@ __deque_base<_Tp, _Allocator>::clear() _NOEXCEPT
}

template <class _Tp, class _Allocator /*= allocator<_Tp>*/>
class _LIBCPP_TEMPLATE_VIS deque
class _LIBCPP_TEMPLATE_VIS _LIBCPP_TRIVIALLY_RELOCATABLE(__deque_allow_trivial_relocation<_Allocator>::type::value) deque
: private __deque_base<_Tp, _Allocator>
{
public:

0 comments on commit 5caede0

Please sign in to comment.
You can’t perform that action at this time.