Skip to content

Commit 5caede0

Browse files
committed
Example conversion for deque, using [[trivially_relocatable(bool)]].
1 parent 0533994 commit 5caede0

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

include/__config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,14 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
12811281
#define _LIBCPP_HAS_NO_IS_AGGREGATE
12821282
#endif
12831283

1284+
#ifndef _LIBCPP_TRIVIALLY_RELOCATABLE
1285+
#if __has_extension(trivially_relocatable)
1286+
#define _LIBCPP_TRIVIALLY_RELOCATABLE(x) [[clang::trivially_relocatable(x)]]
1287+
#else
1288+
#define _LIBCPP_TRIVIALLY_RELOCATABLE(x)
1289+
#endif
1290+
#endif
1291+
12841292
#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L
12851293
#define _LIBCPP_HAS_NO_COROUTINES
12861294
#endif

include/deque

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,22 @@ __deque_base_common<__b>::__throw_out_of_range() const
920920
_VSTD::__throw_out_of_range("deque");
921921
}
922922

923+
template <class _Allocator>
924+
struct __deque_allow_trivial_relocation {
925+
typedef _Allocator allocator_type;
926+
typedef allocator_traits<allocator_type> __alloc_traits;
927+
typedef typename __alloc_traits::pointer pointer;
928+
typedef typename __alloc_traits::size_type size_type;
929+
typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator;
930+
931+
typedef integral_constant<bool,
932+
is_trivially_relocatable<pointer>::value &&
933+
is_trivially_relocatable<__pointer_allocator>::value &&
934+
is_trivially_relocatable<size_type>::value &&
935+
is_trivially_relocatable<allocator_type>::value
936+
> type;
937+
};
938+
923939
template <class _Tp, class _Allocator>
924940
class __deque_base
925941
: protected __deque_base_common<true>
@@ -1191,7 +1207,7 @@ __deque_base<_Tp, _Allocator>::clear() _NOEXCEPT
11911207
}
11921208

11931209
template <class _Tp, class _Allocator /*= allocator<_Tp>*/>
1194-
class _LIBCPP_TEMPLATE_VIS deque
1210+
class _LIBCPP_TEMPLATE_VIS _LIBCPP_TRIVIALLY_RELOCATABLE(__deque_allow_trivial_relocation<_Allocator>::type::value) deque
11951211
: private __deque_base<_Tp, _Allocator>
11961212
{
11971213
public:

0 commit comments

Comments
 (0)