31#ifndef ETL_MEMORY_INCLUDED
32#define ETL_MEMORY_INCLUDED
47#if defined(ETL_IN_UNIT_TEST) || ETL_USING_STL
71 template <
typename Iterator>
72 ETL_CONSTEXPR
typename Iterator::pointer
to_address(
const Iterator& itr) ETL_NOEXCEPT
77#if ETL_USING_STL && ETL_USING_CPP17 && defined(__cpp_lib_launder)
89 ETL_NODISCARD ETL_CONSTEXPR17 T*
launder(T* p) ETL_NOEXCEPT
93 ETL_STATIC_ASSERT(!etl::is_function<T>::value,
"etl::launder argument must not be a function type");
95 ETL_STATIC_ASSERT(!etl::is_void<T>::value,
"etl::launder argument must not be a void type");
97 #if defined(__has_builtin) && !defined(ETL_COMPILER_MICROSOFT)
98 #if __has_builtin(__builtin_launder)
99 return __builtin_launder(p);
103 #elif ETL_USING_GCC_COMPILER && (ETL_COMPILER_FULL_VERSION >= 70000)
105 return __builtin_launder(p);
112#if ETL_USING_STL && ETL_USING_CPP23 && defined(__cpp_lib_start_lifetime_as)
113 using std::start_lifetime_as;
114 using std::start_lifetime_as_array;
116 namespace private_memory
122 template <
typename T>
130 return static_cast<T*
>(p);
133 #if ETL_USING_BUILTIN_MEMMOVE
134 void*
const q = __builtin_memmove(p, p,
sizeof(T) * n);
136 void*
const q = ::memmove(p, p,
sizeof(T) * n);
150 template <
typename T>
154 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"T must be trivially copyable");
158 template <
typename T>
162 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"T must be trivially copyable");
166 template <
typename T>
170 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"T must be trivially copyable");
171 return etl::private_memory::start_lifetime_as_impl<volatile T>(
const_cast<void*
>(p), 1U);
174 template <
typename T>
178 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"T must be trivially copyable");
179 return etl::private_memory::start_lifetime_as_impl<const volatile T>(
const_cast<void*
>(p), 1U);
190 template <
typename T>
194 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"T must be trivially copyable");
198 template <
typename T>
202 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"T must be trivially copyable");
206 template <
typename T>
210 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"T must be trivially copyable");
211 return etl::private_memory::start_lifetime_as_impl<volatile T>(
const_cast<void*
>(p), n);
214 template <
typename T>
218 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"T must be trivially copyable");
219 return etl::private_memory::start_lifetime_as_impl<const volatile T>(
const_cast<void*
>(p), n);
223#if ETL_USING_STL && ETL_USING_CPP11
224 using std::pointer_traits;
227 namespace private_memory
235 template <
typename T>
236 struct pointer_traits_template;
238 template <
template <
typename,
typename...>
class Pointer,
typename Element,
typename... Args>
239 struct pointer_traits_template<Pointer<Element, Args...> >
241 typedef Element type;
243 template <
typename U>
246 typedef Pointer<U, Args...> type;
254 template <
typename T,
typename =
void>
255 struct pointer_traits_element_type
257 typedef typename pointer_traits_template<T>::type type;
260 template <
typename T>
261 struct pointer_traits_element_type<T, etl::void_t<typename T::element_type> >
263 typedef typename T::element_type type;
274 template <
typename T>
279 typedef typename private_memory::pointer_traits_element_type<T>::type element_type;
281 typedef typename T::element_type element_type;
283 typedef ptrdiff_t difference_type;
286 template <
typename U>
287 using rebind =
typename private_memory::pointer_traits_template<T>::template rebind<U>::type;
291 static ETL_CONSTEXPR pointer pointer_to(element_type& r) ETL_NOEXCEPT
293 return T::pointer_to(r);
302 template <
typename T>
306 typedef T element_type;
307 typedef ptrdiff_t difference_type;
310 template <
typename U>
315 static ETL_CONSTEXPR pointer pointer_to(element_type& r) ETL_NOEXCEPT
322#if ETL_USING_STL && ETL_USING_CPP11
334 inline void*
align(
size_t alignment,
size_t size,
void*& ptr,
size_t& space) ETL_NOEXCEPT
336 const uintptr_t p =
reinterpret_cast<uintptr_t
>(ptr);
337 const uintptr_t aligned = (p + (alignment - 1U)) & ~(
static_cast<uintptr_t
>(alignment) - 1U);
338 const size_t padding =
static_cast<size_t>(aligned - p);
340 if ((padding > space) || (
size > (space - padding)))
346 ptr =
reinterpret_cast<void*
>(aligned);
352#if ETL_USING_STL && ETL_USING_CPP20 && defined(__cpp_lib_assume_aligned)
353 using std::assume_aligned;
362 template <
size_t N,
typename T>
365 #if defined(__has_builtin) && !defined(ETL_COMPILER_MICROSOFT)
366 #if __has_builtin(__builtin_assume_aligned)
367 return static_cast<T*
>(__builtin_assume_aligned(ptr, N));
377#if ETL_USING_STL && ETL_USING_CPP26 && defined(__cpp_lib_is_sufficiently_aligned)
378 using std::is_sufficiently_aligned;
386 template <
size_t Alignment,
typename T>
390 return (
reinterpret_cast<uintptr_t
>(ptr) % Alignment) == 0U;
401 template <
typename TOutputIterator,
typename T>
404 std::uninitialized_fill(o_begin, o_end, value);
415 template <
typename TOutputIterator,
typename T,
typename TCounter>
416 TOutputIterator
uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end,
const T& value, TCounter& count)
418 count +=
static_cast<TCounter
>(etl::distance(o_begin, o_end));
420 std::uninitialized_fill(o_begin, o_end, value);
430 template <
typename TOutputIterator,
typename T>
431 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value, TOutputIterator>
::type
434 etl::fill(o_begin, o_end, value);
444 template <
typename TOutputIterator,
typename T>
445 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
446 TOutputIterator>::type
449 typedef typename etl::iterator_traits<TOutputIterator>::value_type
value_type;
451 while (o_begin != o_end)
466 template <
typename TOutputIterator,
typename T,
typename TCounter>
467 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value, TOutputIterator>::type
468 uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end,
const T& value, TCounter& count)
470 count +=
static_cast<TCounter
>(etl::distance(o_begin, o_end));
472 etl::fill(o_begin, o_end, value);
483 template <
typename TOutputIterator,
typename T,
typename TCounter>
484 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
485 TOutputIterator>::type
486 uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end,
const T& value, TCounter& count)
488 count +=
static_cast<TCounter
>(etl::distance(o_begin, o_end));
496#if ETL_USING_STL && ETL_USING_CPP11
502 template <
typename TOutputIterator,
typename TSize,
typename T>
505 return std::uninitialized_fill_n(o_begin, n, value);
514 template <
typename TOutputIterator,
typename TSize,
typename T,
typename TCounter>
515 TOutputIterator
uninitialized_fill_n(TOutputIterator o_begin, TSize n,
const T& value, TCounter& count)
519 return std::uninitialized_fill_n(o_begin, n, value);
527 template <
typename TOutputIterator,
typename TSize,
typename T>
539 template <
typename TOutputIterator,
typename TSize,
typename T,
typename TCounter>
554 template <
typename TInputIterator,
typename TOutputIterator>
555 TOutputIterator
uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
557 return std::uninitialized_copy(i_begin, i_end, o_begin);
566 template <
typename TInputIterator,
typename TOutputIterator,
typename TCounter>
567 TOutputIterator
uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
569 count +=
static_cast<TCounter
>(etl::distance(i_begin, i_end));
571 return std::uninitialized_copy(i_begin, i_end, o_begin);
579 template <
typename TInputIterator,
typename TOutputIterator>
580 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value, TOutputIterator>
::type
581 uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
583 return etl::copy(i_begin, i_end, o_begin);
591 template <
typename TInputIterator,
typename TOutputIterator>
592 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
593 TOutputIterator>::type
594 uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
596 typedef typename etl::iterator_traits<TOutputIterator>::value_type
value_type;
598 TOutputIterator o_end = o_begin;
600 while (i_begin != i_end)
616 template <
typename TInputIterator,
typename TOutputIterator,
typename TCounter>
617 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value, TOutputIterator>::type
618 uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
620 TOutputIterator o_end = etl::copy(i_begin, i_end, o_begin);
621 count +=
static_cast<TCounter
>(etl::distance(i_begin, i_end));
632 template <
typename TInputIterator,
typename TOutputIterator,
typename TCounter>
633 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
634 TOutputIterator>::type
635 uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
639 count +=
static_cast<TCounter
>(etl::distance(i_begin, i_end));
653 struct uninitialized_copy_fn
655 template <
class I,
class S1,
class O,
class S2,
typename = etl::enable_if_t<!etl::is_range_v<I>>>
656 ranges::uninitialized_copy_result<I, O> operator()(I ifirst, S1 ilast, O ofirst, S2 olast)
const
658 using value_type =
typename etl::iterator_traits<O>::value_type;
660 O ofirst_original = ofirst;
662 #if ETL_USING_EXCEPTIONS
666 for (; ifirst != ilast && ofirst != olast; ++ifirst, ++ofirst)
668 ::new (
static_cast<void*
>(
etl::to_address(ofirst))) value_type(*ifirst);
671 return {etl::move(ifirst), etl::move(ofirst)};
672 #if ETL_USING_EXCEPTIONS
676 for (; ofirst_original != ofirst; ++ofirst_original)
685 template <
class IR,
class OR,
typename = etl::enable_if_t<etl::is_range_v<IR>>>
686 ranges::uninitialized_copy_result<ranges::borrowed_iterator_t<IR>, ranges::borrowed_iterator_t<OR>> operator()(IR&& in_range,
687 OR&& out_range)
const
689 return (*
this)(ranges::begin(in_range), ranges::end(in_range), ranges::begin(out_range), ranges::end(out_range));
700 struct uninitialized_copy_n_fn
702 template <
class I,
class O,
class S,
typename = etl::enable_if_t<!etl::is_range_v<I>>>
703 ranges::uninitialized_copy_n_result<I, O> operator()(I ifirst, etl::iter_difference_t<I> n, O ofirst, S olast)
const
705 using value_type =
typename etl::iterator_traits<O>::value_type;
707 O ofirst_original = ofirst;
709 #if ETL_USING_EXCEPTIONS
713 for (; n > 0 && ofirst != olast; ++ifirst, ++ofirst, --n)
715 ::new (
static_cast<void*
>(
etl::to_address(ofirst))) value_type(*ifirst);
718 return {etl::move(ifirst), etl::move(ofirst)};
719 #if ETL_USING_EXCEPTIONS
723 for (; ofirst_original != ofirst; ++ofirst_original)
740 struct uninitialized_fill_fn
742 template <
class I,
class S,
class T,
typename = etl::enable_if_t<!etl::is_range_v<I>>>
743 I operator()(I first, S last,
const T& value)
const
745 using value_type =
typename etl::iterator_traits<I>::value_type;
749 #if ETL_USING_EXCEPTIONS
753 for (; current != last; ++current)
755 ::new (
static_cast<void*
>(
etl::to_address(current))) value_type(value);
759 #if ETL_USING_EXCEPTIONS
763 for (; first != current; ++first)
772 template <
class R,
class T,
typename = etl::enable_if_t<etl::is_range_v<R>>>
773 ranges::borrowed_iterator_t<R> operator()(R&& r,
const T& value)
const
775 return (*
this)(ranges::begin(r), ranges::end(r), value);
786 struct uninitialized_fill_n_fn
788 template <
class I,
class T>
789 I operator()(I first, etl::iter_difference_t<I> n,
const T& value)
const
791 using value_type =
typename etl::iterator_traits<I>::value_type;
795 #if ETL_USING_EXCEPTIONS
799 for (; n > 0; ++current, --n)
801 ::new (
static_cast<void*
>(
etl::to_address(current))) value_type(value);
805 #if ETL_USING_EXCEPTIONS
809 for (; first != current; ++first)
823#if ETL_USING_STL && ETL_USING_CPP11
829 template <
typename TInputIterator,
typename TSize,
typename TOutputIterator>
832 return std::uninitialized_copy_n(i_begin, n, o_begin);
841 template <
typename TInputIterator,
typename TSize,
typename TOutputIterator,
typename TCounter>
842 TOutputIterator
uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count)
846 return std::uninitialized_copy_n(i_begin, n, o_begin);
854 template <
typename TInputIterator,
typename TSize,
typename TOutputIterator>
866 template <
typename TInputIterator,
typename TSize,
typename TOutputIterator,
typename TCounter>
867 TOutputIterator
uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count)
876 #if ETL_USING_STL && ETL_USING_CPP17
882 template <
typename TInputIterator,
typename TOutputIterator>
883 TOutputIterator
uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
887 return std::uninitialized_move(i_begin, i_end, o_begin);
897 template <
typename TInputIterator,
typename TOutputIterator,
typename TCounter>
898 TOutputIterator
uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
900 count +=
static_cast<TCounter
>(etl::distance(i_begin, i_end));
903 return std::uninitialized_move(i_begin, i_end, o_begin);
912 template <
typename TInputIterator,
typename TOutputIterator>
913 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value, TOutputIterator>::type
914 uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
916 return etl::move(i_begin, i_end, o_begin);
924 template <
typename TInputIterator,
typename TOutputIterator>
925 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
926 TOutputIterator>::type
927 uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
929 typedef typename etl::iterator_traits<TOutputIterator>::value_type
value_type;
931 TOutputIterator o_end = o_begin;
933 while (i_begin != i_end)
949 template <
typename TInputIterator,
typename TOutputIterator,
typename TCounter>
950 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value, TOutputIterator>::type
951 uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
953 TOutputIterator o_end = etl::move(i_begin, i_end, o_begin);
954 count +=
static_cast<TCounter
>(etl::distance(i_begin, i_end));
965 template <
typename TInputIterator,
typename TOutputIterator,
typename TCounter>
966 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
967 TOutputIterator>::type
968 uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
972 count +=
static_cast<TCounter
>(etl::distance(i_begin, i_end));
984 template <
typename TInputIterator,
typename TOutputIterator>
985 TOutputIterator
uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
988 return ETL_OR_STD::uninitialized_copy(i_begin, i_end, o_begin);
997 template <
typename TInputIterator,
typename TOutputIterator,
typename TCounter>
998 TOutputIterator
uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, TCounter& count)
1000 count +=
static_cast<TCounter
>(etl::distance(i_begin, i_end));
1003 return ETL_OR_STD::uninitialized_copy(i_begin, i_end, o_begin);
1008 #if ETL_USING_STL && ETL_USING_CPP17
1014 template <
typename TInputIterator,
typename TSize,
typename TOutputIterator>
1017 return std::uninitialized_move(i_begin, i_begin + n, o_begin);
1026 template <
typename TInputIterator,
typename TSize,
typename TOutputIterator,
typename TCounter>
1027 TOutputIterator
uninitialized_move_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count)
1029 count += TCounter(n);
1031 return std::uninitialized_move(i_begin, i_begin + n, o_begin);
1039 template <
typename TInputIterator,
typename TSize,
typename TOutputIterator>
1040 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value, TOutputIterator>::type
1043 return etl::move(i_begin, i_begin + n, o_begin);
1051 template <
typename TInputIterator,
typename TSize,
typename TOutputIterator>
1052 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
1053 TOutputIterator>::type
1056 typedef typename etl::iterator_traits<TOutputIterator>::value_type
value_type;
1058 TOutputIterator o_end = o_begin;
1076 template <
typename TInputIterator,
typename TSize,
typename TOutputIterator,
typename TCounter>
1077 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value, TOutputIterator>::type
1078 uninitialized_move_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count)
1080 TOutputIterator o_end = etl::move(i_begin, i_begin + n, o_begin);
1081 count += TCounter(n);
1092 template <
typename TInputIterator,
typename TSize,
typename TOutputIterator,
typename TCounter>
1093 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
1094 TOutputIterator>::type
1095 uninitialized_move_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin, TCounter& count)
1099 count += TCounter(n);
1111 template <
typename TInputIterator,
typename TSize,
typename TOutputIterator>
1124 template <
typename TInputIterator,
typename TSize,
typename TOutputIterator,
typename TCounter>
1127 count += TCounter(n);
1142 struct uninitialized_move_fn
1144 template <
class I,
class S1,
class O,
class S2,
typename = etl::enable_if_t<!etl::is_range_v<I>>>
1145 ranges::uninitialized_move_result<I, O> operator()(I ifirst, S1 ilast, O ofirst, S2 olast)
const
1147 using value_type =
typename etl::iterator_traits<O>::value_type;
1149 O ofirst_original = ofirst;
1151 #if ETL_USING_EXCEPTIONS
1155 for (; ifirst != ilast && ofirst != olast; ++ifirst, ++ofirst)
1157 ::new (
static_cast<void*
>(
etl::to_address(ofirst))) value_type(etl::move(*ifirst));
1160 return {etl::move(ifirst), etl::move(ofirst)};
1161 #if ETL_USING_EXCEPTIONS
1165 for (; ofirst_original != ofirst; ++ofirst_original)
1174 template <
class IR,
class OR,
typename = etl::enable_if_t<etl::is_range_v<IR>>>
1175 ranges::uninitialized_move_result<ranges::borrowed_iterator_t<IR>, ranges::borrowed_iterator_t<OR>> operator()(IR&& in_range,
1176 OR&& out_range)
const
1178 return (*
this)(ranges::begin(in_range), ranges::end(in_range), ranges::begin(out_range), ranges::end(out_range));
1189 struct uninitialized_move_n_fn
1191 template <
class I,
class O,
class S,
typename = etl::enable_if_t<!etl::is_range_v<I>>>
1192 ranges::uninitialized_move_n_result<I, O> operator()(I ifirst, etl::iter_difference_t<I> n, O ofirst, S olast)
const
1194 using value_type =
typename etl::iterator_traits<O>::value_type;
1196 O ofirst_original = ofirst;
1198 #if ETL_USING_EXCEPTIONS
1202 for (; n > 0 && ofirst != olast; ++ifirst, ++ofirst, --n)
1204 ::new (
static_cast<void*
>(
etl::to_address(ofirst))) value_type(etl::move(*ifirst));
1207 return {etl::move(ifirst), etl::move(ofirst)};
1208 #if ETL_USING_EXCEPTIONS
1212 for (; ofirst_original != ofirst; ++ofirst_original)
1226#if ETL_USING_STL && ETL_USING_CPP17
1232 template <
typename TOutputIterator>
1233 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
void>::type
1236 std::uninitialized_default_construct(o_begin, o_end);
1245 template <
typename TOutputIterator,
typename TCounter>
1246 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
void>::type
1249 count =
static_cast<TCounter
>(etl::distance(o_begin, o_end));
1251 std::uninitialized_default_construct(o_begin, o_end);
1259 template <
typename TOutputIterator>
1260 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
void>::type
1271 template <
typename TOutputIterator>
1272 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
void>
::type
1275 typedef typename etl::iterator_traits<TOutputIterator>::value_type
value_type;
1277 while (o_begin != o_end)
1290 template <
typename TOutputIterator,
typename TCounter>
1291 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
void>
::type
1294 count =
static_cast<TCounter
>(etl::distance(o_begin, o_end));
1303 template <
typename TOutputIterator,
typename TCounter>
1304 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
void>
::type
1307 count +=
static_cast<TCounter
>(etl::distance(o_begin, o_end));
1313#if ETL_USING_STL && ETL_USING_CPP17
1319 template <
typename TOutputIterator,
typename TSize>
1322 return std::uninitialized_default_construct_n(o_begin, n);
1331 template <
typename TOutputIterator,
typename TSize,
typename TCounter>
1336 return std::uninitialized_default_construct_n(o_begin, n);
1344 template <
typename TOutputIterator,
typename TSize>
1345 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value, TOutputIterator>::type
1348 TOutputIterator o_end = o_begin + n;
1357 template <
typename TOutputIterator,
typename TSize>
1358 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
1362 TOutputIterator o_end = o_begin + n;
1375 template <
typename TOutputIterator,
typename TSize,
typename TCounter>
1376 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value, TOutputIterator>
::type
1379 TOutputIterator o_end = o_begin + n;
1392 template <
typename TOutputIterator,
typename TSize,
typename TCounter>
1393 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
1397 TOutputIterator o_end = o_begin + n;
1415 struct uninitialized_default_construct_fn
1417 template <
class I,
class S,
typename = etl::enable_if_t<!etl::is_range_v<I>>>
1418 I operator()(I first, S last)
const
1420 using value_type =
typename etl::iterator_traits<I>::value_type;
1424 #if ETL_USING_EXCEPTIONS
1428 for (; current != last; ++current)
1434 #if ETL_USING_EXCEPTIONS
1438 for (; first != current; ++first)
1447 template <
class R,
typename = etl::enable_if_t<etl::is_range_v<R>>>
1448 ranges::borrowed_iterator_t<R> operator()(R&& r)
const
1450 return (*
this)(ranges::begin(r), ranges::end(r));
1461 struct uninitialized_default_construct_n_fn
1464 I operator()(I first, etl::iter_difference_t<I> n)
const
1466 using value_type =
typename etl::iterator_traits<I>::value_type;
1470 #if ETL_USING_EXCEPTIONS
1474 for (; n > 0; ++current, --n)
1480 #if ETL_USING_EXCEPTIONS
1484 for (; first != current; ++first)
1498#if ETL_USING_STL && ETL_USING_CPP17
1504 template <
typename TOutputIterator>
1507 std::uninitialized_value_construct(o_begin, o_end);
1516 template <
typename TOutputIterator,
typename TCounter>
1519 count +=
static_cast<TCounter
>(etl::distance(o_begin, o_end));
1521 std::uninitialized_value_construct(o_begin, o_end);
1529 template <
typename TOutputIterator>
1530 typename etl::enable_if< etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
void>::type
1533 typedef typename etl::iterator_traits<TOutputIterator>::value_type
value_type;
1543 template <
typename TOutputIterator>
1544 typename etl::enable_if< !etl::is_trivially_constructible< typename etl::iterator_traits<TOutputIterator>::value_type>::value,
void>
::type
1547 typedef typename etl::iterator_traits<TOutputIterator>::value_type
value_type;
1549 while (o_begin != o_end)
1562 template <
typename TOutputIterator,
typename TCounter>
1565 count +=
static_cast<TCounter
>(etl::distance(o_begin, o_end));
1571#if ETL_USING_STL && ETL_USING_CPP17
1577 template <
typename TOutputIterator,
typename TSize>
1580 return std::uninitialized_value_construct_n(o_begin, n);
1589 template <
typename TOutputIterator,
typename TSize,
typename TCounter>
1594 return std::uninitialized_value_construct_n(o_begin, n);
1602 template <
typename TOutputIterator,
typename TSize>
1605 TOutputIterator o_end = o_begin + n;
1618 template <
typename TOutputIterator,
typename TSize,
typename TCounter>
1621 TOutputIterator o_end = o_begin + n;
1639 struct uninitialized_value_construct_fn
1641 template <
class I,
class S,
typename = etl::enable_if_t<!etl::is_range_v<I>>>
1642 I operator()(I first, S last)
const
1644 using value_type =
typename etl::iterator_traits<I>::value_type;
1648 #if ETL_USING_EXCEPTIONS
1652 for (; current != last; ++current)
1658 #if ETL_USING_EXCEPTIONS
1662 for (; first != current; ++first)
1671 template <
class R,
typename = etl::enable_if_t<etl::is_range_v<R>>>
1672 ranges::borrowed_iterator_t<R> operator()(R&& r)
const
1674 return (*
this)(ranges::begin(r), ranges::end(r));
1685 struct uninitialized_value_construct_n_fn
1688 I operator()(I first, etl::iter_difference_t<I> n)
const
1690 using value_type =
typename etl::iterator_traits<I>::value_type;
1694 #if ETL_USING_EXCEPTIONS
1698 for (; n > 0; ++current, --n)
1704 #if ETL_USING_EXCEPTIONS
1708 for (; first != current; ++first)
1722#if ETL_USING_STL && ETL_USING_CPP20
1728 template <
typename T,
typename... TArgs>
1731 return std::construct_at(p, etl::forward<TArgs>(args)...);
1733#elif ETL_USING_CPP11
1739 template <
typename T,
typename... TArgs>
1742 return ::new (
const_cast<void*
>(
static_cast<const volatile void*
>(p))) T(etl::forward<TArgs>(args)...);
1750 template <
typename T>
1753 return ::new (
const_cast<void*
>(
static_cast<const volatile void*
>(p))) T();
1760 template <
typename T,
typename TArg>
1763 return ::new (
const_cast<void*
>(
static_cast<const volatile void*
>(p))) T(arg);
1775 struct construct_at_fn
1777 template <
class T,
class... Args>
1778 constexpr T* operator()(T* p, Args&&... args)
const
1788#if ETL_USING_STL && ETL_USING_CPP20
1794 template <
typename T>
1806 template <
typename T,
typename TCounter>
1807 ETL_CONSTEXPR20
void destroy_at(T* p, TCounter& count)
1818 template <
typename T>
1828 template <
typename T>
1829 typename etl::enable_if<!etl::is_trivially_destructible<T>::value,
void>
::type destroy_at(T* p)
1840 template <
typename T,
typename TCounter>
1841 typename etl::enable_if<etl::is_trivially_destructible<T>::value,
void>
::type destroy_at(T* , TCounter& count)
1852 template <
typename T,
typename TCounter>
1853 typename etl::enable_if<!etl::is_trivially_destructible<T>::value,
void>
::type destroy_at(T* p, TCounter& count)
1860#if ETL_USING_STL && ETL_USING_CPP17
1866 template <
typename TIterator>
1867 void destroy(TIterator i_begin, TIterator i_end)
1869 std::destroy(i_begin, i_end);
1878 template <
typename TIterator,
typename TCounter>
1879 void destroy(TIterator i_begin, TIterator i_end, TCounter& count)
1881 count -=
static_cast<TCounter
>(etl::distance(i_begin, i_end));
1883 std::destroy(i_begin, i_end);
1891 template <
typename TIterator>
1892 typename etl::enable_if< etl::is_trivially_destructible< typename etl::iterator_traits<TIterator>::value_type>::value,
void>::type
1902 template <
typename TIterator>
1903 typename etl::enable_if< !etl::is_trivially_destructible< typename etl::iterator_traits<TIterator>::value_type>::value,
void>
::type
1906 while (i_begin != i_end)
1919 template <
typename TIterator,
typename TCounter>
1920 typename etl::enable_if< etl::is_trivially_destructible< typename etl::iterator_traits<TIterator>::value_type>::value,
void>
::type
1921 destroy(TIterator i_begin, TIterator i_end, TCounter& count)
1923 count -=
static_cast<TCounter
>(etl::distance(i_begin, i_end));
1932 template <
typename TIterator,
typename TCounter>
1933 typename etl::enable_if< !etl::is_trivially_destructible< typename etl::iterator_traits<TIterator>::value_type>::value,
void>
::type
1934 destroy(TIterator i_begin, TIterator i_end, TCounter& count)
1936 count -=
static_cast<TCounter
>(etl::distance(i_begin, i_end));
1938 while (i_begin != i_end)
1946#if ETL_USING_STL && ETL_USING_CPP17
1952 template <
typename TIterator,
typename TSize>
1953 TIterator
destroy_n(TIterator i_begin, TSize n)
1955 return std::destroy_n(i_begin, n);
1964 template <
typename TIterator,
typename TSize,
typename TCounter>
1965 TIterator
destroy_n(TIterator i_begin, TSize n, TCounter& count)
1969 return std::destroy_n(i_begin, n);
1977 template <
typename TIterator,
typename TSize>
1978 typename etl::enable_if< etl::is_trivially_destructible< typename etl::iterator_traits<TIterator>::value_type>::value, TIterator>::type
1989 template <
typename TIterator,
typename TSize>
1990 typename etl::enable_if< !etl::is_trivially_destructible< typename etl::iterator_traits<TIterator>::value_type>::value, TIterator>
::type
2009 template <
typename TIterator,
typename TSize,
typename TCounter>
2010 typename etl::enable_if< etl::is_trivially_destructible< typename etl::iterator_traits<TIterator>::value_type>::value, TIterator>
::type
2023 template <
typename TIterator,
typename TSize,
typename TCounter>
2024 typename etl::enable_if< !etl::is_trivially_destructible< typename etl::iterator_traits<TIterator>::value_type>::value, TIterator>
::type
2048 struct destroy_at_fn
2051 constexpr void operator()(T* p)
const
2066 template <
class I,
class S,
typename = etl::enable_if_t<!etl::is_range_v<I>>>
2067 I operator()(I first, S last)
const
2069 for (; first != last; ++first)
2077 template <
class R,
typename = etl::enable_if_t<etl::is_range_v<R>>>
2078 ranges::borrowed_iterator_t<R> operator()(R&& r)
const
2080 return (*
this)(ranges::begin(r), ranges::end(r));
2084 inline constexpr destroy_fn destroy{};
2094 I operator()(I first, etl::iter_difference_t<I> n)
const
2096 for (; n > 0; ++first, --n)
2105 inline constexpr destroy_n_fn
destroy_n{};
2118 template <
typename T>
2119 typename etl::enable_if<etl::is_trivially_relocatable<T>::value && !etl::is_const<T>::value, T*>::type trivially_relocate(T* first, T* last,
2122 if (first == result)
2127 const size_t count =
static_cast<size_t>(last - first);
2132 ::memmove(
static_cast<void*
>(result),
static_cast<const void*
>(first), count *
sizeof(T));
2135 return result + count;
2147 template <
typename T>
2148 typename etl::enable_if<etl::is_trivially_relocatable<T>::value, T*>::type relocate_impl(T* first, T* last, T* result)
2150 return etl::trivially_relocate(first, last, result);
2158 template <
typename T>
2159 typename etl::enable_if<!etl::is_trivially_relocatable<T>::value, T*>::type relocate_impl(T* first, T* last, T* result)
2161 const ptrdiff_t count = last - first;
2164 if (result < first || result >= last)
2171 ::new (
static_cast<void*
>(dst)) T(etl::move(*src));
2181 T* dst = result + count;
2182 while (src != first)
2186 ::new (
static_cast<void*
>(dst)) T(etl::move(*src));
2191 return result + count;
2205 template <
typename T>
2206 typename etl::enable_if<etl::is_nothrow_relocatable<T>::value && !etl::is_const<T>::value, T*>::type relocate(T* first, T* last, T* result)
2209 if (first == result || first == last)
2211 return (first == result) ? last : result;
2216 return relocate_impl(first, last, result);
2226 template <
typename T>
2227 struct default_delete
2230 ETL_CONSTEXPR default_delete() ETL_NOEXCEPT
2235 template <
typename U>
2236 ETL_CONSTEXPR default_delete(
const default_delete<U>&) ETL_NOEXCEPT
2241 void operator()(T* p)
const ETL_NOEXCEPT
2253 template <
typename T>
2254 struct default_delete<T[]>
2257 ETL_CONSTEXPR default_delete() ETL_NOEXCEPT
2262 template <
typename U>
2263 ETL_CONSTEXPR default_delete(
const default_delete<U>&) ETL_NOEXCEPT
2269 void operator()(U* p)
const
2281 template <
typename T,
typename TDeleter = etl::default_delete<T> >
2286 typedef T element_type;
2288 typedef T& reference;
2291 ETL_CONSTEXPR unique_ptr() ETL_NOEXCEPT
2297 ETL_CONSTEXPR
explicit unique_ptr(pointer p_) ETL_NOEXCEPT
2304 unique_ptr(unique_ptr&& other) ETL_NOEXCEPT
2308 p = other.release();
2309 deleter = etl::move(other.deleter);
2314 unique_ptr(unique_ptr& other) ETL_NOEXCEPT
2318 p = other.release();
2319 deleter = other.deleter;
2325 unique_ptr(pointer p_,
typename etl::conditional< etl::is_reference<TDeleter>::value, TDeleter,
2326 typename etl::add_lvalue_reference<const TDeleter>::type>
::type deleter_) ETL_NOEXCEPT
2334 unique_ptr(pointer p_,
typename etl::remove_reference<TDeleter>::type&& deleter_) ETL_NOEXCEPT
2336 , deleter(etl::move(deleter_))
2340 template <
typename U,
typename E>
2341 unique_ptr(unique_ptr<U, E>&& u) ETL_NOEXCEPT
2343 , deleter(etl::forward<E>(u.get_deleter()))
2351 if (p != ETL_NULLPTR)
2358 ETL_CONSTEXPR pointer get()
const ETL_NOEXCEPT
2364 TDeleter& get_deleter() ETL_NOEXCEPT
2370 const TDeleter& get_deleter()
const ETL_NOEXCEPT
2376 pointer release() ETL_NOEXCEPT
2385 void reset(pointer p_ = pointer()) ETL_NOEXCEPT
2387 if (p_ == ETL_NULLPTR || p_ != p)
2392 if (value != ETL_NULLPTR)
2400 void swap(unique_ptr& value) ETL_NOEXCEPT
2402 using ETL_OR_STD::swap;
2405 swap(deleter, value.deleter);
2409 ETL_CONSTEXPR
operator bool()
const ETL_NOEXCEPT
2411 return (p != ETL_NULLPTR);
2427 unique_ptr& operator=(unique_ptr&& other) ETL_NOEXCEPT
2431 reset(other.release());
2432 deleter = etl::move(other.deleter);
2439 unique_ptr& operator=(unique_ptr& other) ETL_NOEXCEPT
2443 reset(other.release());
2444 deleter = other.deleter;
2452 ETL_CONSTEXPR reference operator*()
const
2458 ETL_CONSTEXPR pointer operator->()
const ETL_NOEXCEPT
2464 ETL_CONSTEXPR reference operator[](
size_t i)
const
2472 unique_ptr(
const unique_ptr&) ETL_DELETE;
2473 unique_ptr& operator=(
const unique_ptr&) ETL_DELETE;
2485 template <
typename T,
typename TDeleter>
2486 class unique_ptr<T[], TDeleter>
2490 typedef T element_type;
2492 typedef T& reference;
2495 ETL_CONSTEXPR unique_ptr() ETL_NOEXCEPT
2501 ETL_CONSTEXPR
explicit unique_ptr(pointer p_) ETL_NOEXCEPT
2508 unique_ptr(unique_ptr&& other) ETL_NOEXCEPT
2512 p = other.release();
2513 deleter = etl::move(other.deleter);
2518 unique_ptr(unique_ptr& other) ETL_NOEXCEPT
2522 p = other.release();
2523 deleter = other.deleter;
2529 unique_ptr(pointer p_,
typename etl::conditional< etl::is_reference<TDeleter>::value, TDeleter,
2530 typename etl::add_lvalue_reference<const TDeleter>::type>
::type deleter_) ETL_NOEXCEPT
2538 unique_ptr(pointer p_,
typename etl::remove_reference<TDeleter>::type&& deleter_) ETL_NOEXCEPT
2540 , deleter(etl::move(deleter_))
2544 template <
typename U,
typename E>
2545 unique_ptr(unique_ptr<U, E>&& u) ETL_NOEXCEPT
2547 , deleter(etl::forward<E>(u.get_deleter()))
2555 if (p != ETL_NULLPTR)
2562 ETL_CONSTEXPR pointer get()
const ETL_NOEXCEPT
2568 TDeleter& get_deleter() ETL_NOEXCEPT
2574 const TDeleter& get_deleter()
const ETL_NOEXCEPT
2580 pointer release() ETL_NOEXCEPT
2588 void reset(pointer p_) ETL_NOEXCEPT
2595 if (value != ETL_NULLPTR)
2608 void swap(unique_ptr& v) ETL_NOEXCEPT
2610 using ETL_OR_STD::swap;
2613 swap(deleter, v.deleter);
2617 ETL_CONSTEXPR
operator bool()
const ETL_NOEXCEPT
2619 return (p != ETL_NULLPTR);
2632 unique_ptr& operator=(unique_ptr&& other) ETL_NOEXCEPT
2636 reset(other.release());
2637 deleter = etl::move(other.deleter);
2644 unique_ptr& operator=(unique_ptr& other) ETL_NOEXCEPT
2648 reset(other.release());
2649 deleter = other.deleter;
2657 ETL_CONSTEXPR reference operator*()
const
2663 ETL_CONSTEXPR pointer operator->()
const ETL_NOEXCEPT
2669 ETL_CONSTEXPR reference operator[](
size_t i)
const
2677 unique_ptr(
const unique_ptr&) ETL_DELETE;
2678 unique_ptr& operator=(
const unique_ptr&) ETL_DELETE;
2687 template <
typename T1,
typename TD1,
typename T2,
typename TD2>
2690 return lhs.get() == rhs.get();
2694 template <
typename T1,
typename TD1,
typename T2,
typename TD2>
2697 return reinterpret_cast<char*
>(lhs.get()) <
reinterpret_cast<char*
>(rhs.get());
2701 template <
typename T1,
typename TD1,
typename T2,
typename TD2>
2702 bool operator<=(
const etl::unique_ptr<T1, TD1>& lhs,
const etl::unique_ptr<T2, TD2>& rhs)
2704 return !(rhs < lhs);
2708 template <
typename T1,
typename TD1,
typename T2,
typename TD2>
2709 bool operator>(
const etl::unique_ptr<T1, TD1>& lhs,
const etl::unique_ptr<T2, TD2>& rhs)
2715 template <
typename T1,
typename TD1,
typename T2,
typename TD2>
2716 bool operator>=(
const etl::unique_ptr<T1, TD1>& lhs,
const etl::unique_ptr<T2, TD2>& rhs)
2718 return !(lhs < rhs);
2724 template <
typename T>
2733 template <
typename T,
typename TCounter>
2743 template <
typename T>
2753 template <
typename T,
typename TCounter>
2764 template <
typename T>
2774 template <
typename T,
typename TCounter>
2785 template <
typename T>
2796 template <
typename T>
2799 ::new (p) T(etl::move(value));
2807 template <
typename T,
typename TCounter>
2818 template <
typename T>
2822 return *
reinterpret_cast<T*
>(p);
2829 template <
typename T,
typename TCounter>
2834 return *
reinterpret_cast<T*
>(p);
2841 template <
typename T>
2845 return *
reinterpret_cast<T*
>(p);
2853 template <
typename T>
2856 ::new (p) T(etl::move(other));
2857 return *
reinterpret_cast<T*
>(p);
2865 template <
typename T,
typename TCounter>
2870 return *
reinterpret_cast<T*
>(p);
2877 template <
typename T,
typename TParameter>
2881 return *
reinterpret_cast<T*
>(p);
2889 template <
typename T,
typename TParameter>
2892 ::new (p) T(etl::move(value));
2893 return *
reinterpret_cast<T*
>(p);
2901 template <
typename T,
typename TParameter,
typename TCounter>
2906 return *
reinterpret_cast<T*
>(p);
2914 template <
typename T>
2917 void create_copy_at(
void* p)
2919 new (p) T(
static_cast<const T&
>(*
this));
2922 template <
typename TCounter>
2923 void create_copy_at(
void* p, TCounter& count)
2925 new (p) T(
static_cast<const T&
>(*
this));
2929 T& make_copy_at(
void* p)
2931 new (p) T(
static_cast<const T&
>(*
this));
2932 return *
reinterpret_cast<T*
>(p);
2935 template <
typename TCounter>
2936 T& make_copy_at(
void* p, TCounter& count)
2938 new (p) T(
static_cast<const T&
>(*
this));
2940 return *
reinterpret_cast<T*
>(p);
2959#if defined(ETL_COMPILER_GCC) || defined(ETL_COMPILER_CLANG)
2960 __asm__ __volatile__(
"" : : :
"memory");
2961#elif defined(ETL_COMPILER_MICROSOFT)
2962 _ReadWriteBarrier();
2972 template <
typename T>
2975 memory_clear(
reinterpret_cast<volatile char*
>(&
object),
sizeof(T));
2985 template <
typename T>
2998 template <
typename T>
3001 const size_t n =
static_cast<size_t>(etl::distance(
begin,
end));
3028 template <
typename T>
3031 memory_set(
reinterpret_cast<volatile char*
>(&
object),
sizeof(T), value);
3042 template <
typename T>
3045 memory_set(
reinterpret_cast<volatile char*
>(
begin), n *
sizeof(T), value);
3056 template <
typename T>
3059 const size_t n =
static_cast<size_t>(etl::distance(
begin,
end));
3071 template <
typename T>
3085 template <
size_t VObject_Size,
size_t VN_Objects,
size_t VAlignment>
3090 static ETL_CONSTANT
size_t Object_Size = VObject_Size;
3091 static ETL_CONSTANT
size_t N_Objects = VN_Objects;
3092 static ETL_CONSTANT
size_t Alignment = VAlignment;
3095 template <
typename T>
3098 ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)),
"Incompatible alignment");
3099 return *
reinterpret_cast<T*
>(raw);
3103 template <
typename T>
3104 operator const T&()
const
3106 ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)),
"Incompatible alignment");
3107 return *
reinterpret_cast<const T*
>(raw);
3111 template <
typename T>
3114 ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)),
"Incompatible alignment");
3115 return reinterpret_cast<T*
>(raw);
3119 template <
typename T>
3120 operator const T*()
const
3122 ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)),
"Incompatible alignment");
3123 return reinterpret_cast<const T*
>(raw);
3126#if ETL_USING_CPP11 && !defined(ETL_COMPILER_ARM5) && !defined(ETL_UNINITIALIZED_BUFFER_FORCE_CPP03_IMPLEMENTATION)
3127 alignas(VAlignment)
char raw[Object_Size * N_Objects];
3131 char raw[VObject_Size * VN_Objects];
3132 typename etl::type_with_alignment<Alignment>::type etl_alignment_type;
3138 template <
size_t VObject_Size,
size_t VN_Objects,
size_t VAlignment>
3139 ETL_CONSTANT
size_t uninitialized_buffer<VObject_Size, VN_Objects, VAlignment>::Object_Size;
3141 template <
size_t VObject_Size,
size_t VN_Objects,
size_t VAlignment>
3142 ETL_CONSTANT
size_t uninitialized_buffer<VObject_Size, VN_Objects, VAlignment>::N_Objects;
3144 template <
size_t VObject_Size,
size_t VN_Objects,
size_t VAlignment>
3145 ETL_CONSTANT
size_t uninitialized_buffer<VObject_Size, VN_Objects, VAlignment>::Alignment;
3151 template <
typename T,
size_t VN_Objects>
3156 typedef T value_type;
3157 typedef T& reference;
3158 typedef const T& const_reference;
3160 typedef const T* const_pointer;
3161 typedef T* iterator;
3162 typedef const T* const_iterator;
3164 static ETL_CONSTANT
size_t Object_Size =
sizeof(T);
3165 static ETL_CONSTANT
size_t N_Objects = VN_Objects;
3166 static ETL_CONSTANT
size_t Alignment = etl::alignment_of<T>::value;
3171 return reinterpret_cast<T*
>(this->raw)[i];
3177 return reinterpret_cast<const T*
>(this->raw)[i];
3183 return *
reinterpret_cast<T*
>(raw);
3187 operator const T&()
const
3189 return *
reinterpret_cast<const T*
>(raw);
3196 return reinterpret_cast<T*
>(raw);
3200 operator const T*()
const
3202 return reinterpret_cast<const T*
>(raw);
3207 return reinterpret_cast<T*
>(raw);
3210 const T* begin()
const
3212 return reinterpret_cast<const T*
>(raw);
3217 return reinterpret_cast<T*
>(raw + (
sizeof(T) * N_Objects));
3220 const T* end()
const
3222 return reinterpret_cast<const T*
>(raw + (
sizeof(T) * N_Objects));
3225#if ETL_USING_CPP11 && !defined(ETL_COMPILER_ARM5) && !defined(ETL_UNINITIALIZED_BUFFER_FORCE_CPP03_IMPLEMENTATION)
3226 alignas(Alignment)
char raw[
sizeof(T) * N_Objects];
3230 char raw[
sizeof(T) * N_Objects];
3231 typename etl::type_with_alignment<Alignment>::type etl_alignment_type;
3237 template <
typename T,
size_t VN_Objects>
3238 ETL_CONSTANT
size_t uninitialized_buffer_of<T, VN_Objects>::Object_Size;
3240 template <
typename T,
size_t VN_Objects>
3241 ETL_CONSTANT
size_t uninitialized_buffer_of<T, VN_Objects>::N_Objects;
3243 template <
typename T,
size_t VN_Objects>
3244 ETL_CONSTANT
size_t uninitialized_buffer_of<T, VN_Objects>::Alignment;
3247 template <
typename T,
size_t N_Objects>
3259 template <
typename T>
3260 T*
mem_copy(
const T* sb,
const T* se, T* db) ETL_NOEXCEPT
3262 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"Cannot mem_copy a non trivially copyable type");
3264#if ETL_USING_BUILTIN_MEMCPY
3265 __builtin_memcpy(
reinterpret_cast<void*
>(db),
reinterpret_cast<const void*
>(sb),
sizeof(T) *
static_cast<size_t>(se - sb));
3267 ::memcpy(
reinterpret_cast<void*
>(db),
reinterpret_cast<const void*
>(sb),
sizeof(T) *
static_cast<size_t>(se - sb));
3280 template <
typename T>
3283 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"Cannot mem_copy a non trivially copyable type");
3285#if ETL_USING_BUILTIN_MEMCPY
3286 __builtin_memcpy(
reinterpret_cast<void*
>(db),
reinterpret_cast<const void*
>(sb),
sizeof(T) * n);
3288 ::memcpy(
reinterpret_cast<void*
>(db),
reinterpret_cast<const void*
>(sb),
sizeof(T) * n);
3301 template <
typename T>
3302 T*
mem_move(
const T* sb,
const T* se, T* db) ETL_NOEXCEPT
3304 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"Cannot mem_move a non trivially copyable type");
3306#if ETL_USING_BUILTIN_MEMMOVE
3307 __builtin_memmove(
reinterpret_cast<void*
>(db),
reinterpret_cast<const void*
>(sb),
sizeof(T) *
static_cast<size_t>(se - sb));
3309 ::memmove(
reinterpret_cast<void*
>(db),
reinterpret_cast<const void*
>(sb),
sizeof(T) *
static_cast<size_t>(se - sb));
3322 template <
typename T>
3325 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"Cannot mem_move a non trivially copyable type");
3327#if ETL_USING_BUILTIN_MEMMOVE
3330 __builtin_memmove(
reinterpret_cast<void*
>(db),
reinterpret_cast<const void*
>(sb),
sizeof(T) * n);
3333 ::memmove(
reinterpret_cast<void*
>(db),
reinterpret_cast<const void*
>(sb),
sizeof(T) * n);
3351 template <
typename T>
3355 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"Cannot mem_compare a non trivially copyable type");
3357#if ETL_USING_BUILTIN_MEMCMP
3358 return __builtin_memcmp(
reinterpret_cast<const void*
>(db),
reinterpret_cast<const void*
>(sb),
sizeof(T) *
static_cast<size_t>(se - sb));
3360 return ::memcmp(
reinterpret_cast<const void*
>(db),
reinterpret_cast<const void*
>(sb),
sizeof(T) *
static_cast<size_t>(se - sb));
3376 template <
typename T>
3380 ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value,
"Cannot mem_compare a non trivially copyable type");
3382#if ETL_USING_BUILTIN_MEMCMP
3383 return __builtin_memcmp(
reinterpret_cast<const void*
>(db),
reinterpret_cast<const void*
>(sb),
sizeof(T) * n);
3385 return ::memcmp(
reinterpret_cast<const void*
>(db),
reinterpret_cast<const void*
>(sb),
sizeof(T) * n);
3396 template <
typename TPo
inter,
typename T>
3397 typename etl::enable_if<etl::is_pointer<TPointer>::value && !etl::is_const<TPointer>::value && etl::is_integral<T>::value &&
sizeof(T) == 1,
3399 mem_set(TPointer db,
const TPointer de, T value) ETL_NOEXCEPT
3401 ETL_STATIC_ASSERT(etl::is_trivially_copyable<
typename etl::iterator_traits<TPointer>::value_type>::value,
3402 "Cannot mem_set a non trivially copyable type");
3404#if ETL_USING_BUILTIN_MEMSET
3405 __builtin_memset(
reinterpret_cast<void*
>(db),
static_cast<char>(value),
3406 sizeof(
typename etl::iterator_traits<TPointer>::value_type) *
static_cast<size_t>(de - db));
3408 ::memset(
reinterpret_cast<void*
>(db),
static_cast<char>(value),
3409 sizeof(
typename etl::iterator_traits<TPointer>::value_type) *
static_cast<size_t>(de - db));
3422 template <
typename TPo
inter,
typename T>
3423 typename etl::enable_if<etl::is_pointer<TPointer>::value && !etl::is_const<TPointer>::value && etl::is_integral<T>::value &&
sizeof(T) == 1,
3425 mem_set(TPointer db,
size_t n, T value) ETL_NOEXCEPT
3427 ETL_STATIC_ASSERT(etl::is_trivially_copyable<
typename etl::iterator_traits<TPointer>::value_type>::value,
3428 "Cannot mem_set a non trivially copyable type");
3430#if ETL_USING_BUILTIN_MEMSET
3431 __builtin_memset(
reinterpret_cast<void*
>(db),
static_cast<char>(value),
sizeof(
typename etl::iterator_traits<TPointer>::value_type) * n);
3433 ::memset(
reinterpret_cast<void*
>(db),
static_cast<char>(value),
sizeof(
typename etl::iterator_traits<TPointer>::value_type) * n);
3446 template <
typename TPo
inter,
typename T>
3449 && etl::is_integral<T>::value &&
sizeof(T) == 1,
3452#if ETL_USING_BUILTIN_MEMCHR
3453 void* result = __builtin_memchr(
reinterpret_cast<void*
>(sb),
static_cast<char>(value),
3454 sizeof(
typename etl::iterator_traits<TPointer>::value_type) *
static_cast<size_t>(se - sb));
3456 return (result == 0U) ?
reinterpret_cast<char*
>(se) :
reinterpret_cast<char*
>(result);
3458 void* result = ::memchr(
reinterpret_cast<void*
>(sb),
static_cast<char>(value),
3459 sizeof(
typename etl::iterator_traits<TPointer>::value_type) *
static_cast<size_t>(se - sb));
3461 return (result == 0U) ?
reinterpret_cast<char*
>(se) :
reinterpret_cast<char*
>(result);
3472 template <
typename TPo
inter,
typename T>
3475 && etl::is_integral<T>::value &&
sizeof(T) == 1,
3478#if ETL_USING_BUILTIN_MEMCHR
3479 const void* result = __builtin_memchr(
reinterpret_cast<const void*
>(sb),
static_cast<char>(value),
3480 sizeof(
typename etl::iterator_traits<TPointer>::value_type) *
static_cast<size_t>(se - sb));
3482 return (result == 0U) ?
reinterpret_cast<const char*
>(se) :
reinterpret_cast<const char*
>(result);
3484 const void* result = ::memchr(
reinterpret_cast<const void*
>(sb),
static_cast<char>(value),
3485 sizeof(
typename etl::iterator_traits<TPointer>::value_type) *
static_cast<size_t>(se - sb));
3487 return (result == 0U) ?
reinterpret_cast<const char*
>(se) :
reinterpret_cast<const char*
>(result);
3498 template <
typename TPo
inter,
typename T>
3501 && etl::is_integral<T>::value &&
sizeof(T) == 1,
3504#if ETL_USING_BUILTIN_MEMCHR
3506 __builtin_memchr(
reinterpret_cast<void*
>(sb),
static_cast<char>(value),
sizeof(
typename etl::iterator_traits<TPointer>::value_type) * n);
3508 return (result == 0U) ?
reinterpret_cast<char*
>(sb + n) :
reinterpret_cast<char*
>(result);
3510 void* result = ::memchr(
reinterpret_cast<void*
>(sb),
static_cast<char>(value),
sizeof(
typename etl::iterator_traits<TPointer>::value_type) * n);
3512 return (result == 0U) ?
reinterpret_cast<char*
>(sb + n) :
reinterpret_cast<char*
>(result);
3523 template <
typename TPo
inter,
typename T>
3526 && etl::is_integral<T>::value &&
sizeof(T) == 1,
3529#if ETL_USING_BUILTIN_MEMCHR
3530 const void* result =
3531 __builtin_memchr(
reinterpret_cast<const void*
>(sb),
static_cast<char>(value),
sizeof(
typename etl::iterator_traits<TPointer>::value_type) * n);
3533 return (result == 0U) ?
reinterpret_cast<const char*
>(sb + n) :
reinterpret_cast<const char*
>(result);
3535 const void* result =
3536 ::memchr(
reinterpret_cast<const void*
>(sb),
static_cast<char>(value),
sizeof(
typename etl::iterator_traits<TPointer>::value_type) * n);
3538 return (result == 0U) ?
reinterpret_cast<const char*
>(sb + n) :
reinterpret_cast<const char*
>(result);
3546 template <
typename TObject>
3549 #if ETL_IS_DEBUG_BUILD
3553 return *
etl::construct_at(
reinterpret_cast<typename etl::remove_reference<TObject>::type*
>(p), etl::forward<TObject>(other));
3559 template <
typename TObject,
typename... TArgs>
3562 #if ETL_IS_DEBUG_BUILD
3566 return *
etl::construct_at(
reinterpret_cast<TObject*
>(p), etl::forward<TArgs>(args)...);
3572 template <
typename TObject>
3575 #if ETL_IS_DEBUG_BUILD
3585 template <
typename TObject>
3588 #if ETL_IS_DEBUG_BUILD
3598 template <
typename TObject,
typename TArg>
3601 #if ETL_IS_DEBUG_BUILD
3612 template <
typename TObject>
3615#if ETL_IS_DEBUG_BUILD
3619 return *
reinterpret_cast<TObject*
>(p);
3625 template <
typename TObject>
3628#if ETL_IS_DEBUG_BUILD
3632 return *
reinterpret_cast<const TObject*
>(p);
3639 template <
typename TObject>
3642#if ETL_IS_DEBUG_BUILD
Memory misalignment exception.
Definition alignment.h:66
T & operator[](int i)
Index operator.
Definition memory.h:3169
const T & operator[](int i) const
Index operator.
Definition memory.h:3175
#define ETL_ASSERT(b, e)
Definition error_handler.h:511
TOutputIterator uninitialized_fill(TOutputIterator o_begin, TOutputIterator o_end, const T &value)
Definition memory.h:402
etl::enable_if< etl::is_trivially_constructible< typenameetl::iterator_traits< TOutputIterator >::value_type >::value, void >::type uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end)
Definition memory.h:1531
ETL_CONSTEXPR17 etl::enable_if<!etl::is_same< T, etl::nullptr_t >::value, T >::type * addressof(T &t)
Definition addressof.h:52
void memory_set_range(volatile T *begin, size_t n, const char value)
Definition memory.h:3043
TOutputIterator uninitialized_value_construct_n(TOutputIterator o_begin, TSize n)
Definition memory.h:1603
ETL_NODISCARD T * start_lifetime_as(void *p) ETL_NOEXCEPT
Definition memory.h:152
etl::enable_if< etl::is_trivially_constructible< T >::value, void >::type create_default_at(T *)
Definition memory.h:2725
etl::enable_if< etl::is_trivially_constructible< typenameetl::iterator_traits< TOutputIterator >::value_type >::value, TOutputIterator >::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n)
Definition memory.h:1346
T * construct_at(T *p)
Definition memory.h:1751
void create_copy_at(T *p, const T &value)
Definition memory.h:2786
void create_value_at(T *p)
Definition memory.h:2765
T & make_value_at(T *p, const TParameter &value)
Definition memory.h:2878
etl::enable_if< etl::is_trivially_destructible< typenameetl::iterator_traits< TIterator >::value_type >::value, void >::type destroy(TIterator, TIterator)
Definition memory.h:1893
etl::enable_if< etl::is_trivially_destructible< T >::value, void >::type destroy_at(T *)
Definition memory.h:1819
void memory_clear_range(volatile T *begin, size_t n)
Definition memory.h:2986
void memory_set(volatile char *p, size_t n, char value)
Definition memory.h:3013
TOutputIterator uninitialized_move_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin)
Definition memory.h:1112
TOutputIterator uninitialized_copy_n(TInputIterator i_begin, TSize n, TOutputIterator o_begin)
Definition memory.h:855
ETL_NODISCARD T * start_lifetime_as_array(void *p, size_t n) ETL_NOEXCEPT
Definition memory.h:192
ETL_NODISCARD ETL_CONSTEXPR T * assume_aligned(T *ptr) ETL_NOEXCEPT
Definition memory.h:363
etl::enable_if< etl::is_trivially_destructible< typenameetl::iterator_traits< TIterator >::value_type >::value, TIterator >::type destroy_n(TIterator i_begin, TSize n)
Definition memory.h:1979
T & make_default_at(T *p)
Definition memory.h:2819
TOutputIterator uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
Definition memory.h:985
T & make_copy_at(T *p, const T &other)
Definition memory.h:2842
void * align(size_t alignment, size_t size, void *&ptr, size_t &space) ETL_NOEXCEPT
Definition memory.h:334
void memory_clear(volatile char *p, size_t n)
Definition memory.h:2950
TOutputIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
Definition memory.h:555
ETL_NODISCARD ETL_CONSTEXPR17 T * launder(T *p) ETL_NOEXCEPT
Definition memory.h:89
etl::enable_if< etl::is_trivially_constructible< typenameetl::iterator_traits< TOutputIterator >::value_type >::value, void >::type uninitialized_default_construct(TOutputIterator, TOutputIterator)
Definition memory.h:1261
TOutputIterator uninitialized_fill_n(TOutputIterator o_begin, TSize n, const T &value)
Definition memory.h:528
ETL_NODISCARD bool is_sufficiently_aligned(T *ptr) ETL_NOEXCEPT
Definition memory.h:388
ETL_NODISCARD T * start_lifetime_as_impl(void *p, size_t n) ETL_NOEXCEPT
Definition memory.h:124
ETL_CONSTEXPR14 bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1078
T * mem_move(const T *sb, const T *se, T *db) ETL_NOEXCEPT
Definition memory.h:3302
ETL_NODISCARD int mem_compare(const T *sb, const T *se, const T *db) ETL_NOEXCEPT
Definition memory.h:3353
void destroy_object_at(void *p)
Definition memory.h:3640
etl::enable_if< etl::is_pointer< TPointer >::value &&!etl::is_const< TPointer >::value &&etl::is_integral< T >::value &&sizeof(T)==1, TPointer >::type mem_set(TPointer db, const TPointer de, T value) ETL_NOEXCEPT
Definition memory.h:3399
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1130
TObject & construct_object_at(void *p)
Default construct the container at 'p'.
Definition memory.h:3573
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1144
bool is_aligned(const void *p, size_t required_alignment)
Check that 'p' has 'required_alignment'.
Definition alignment.h:91
ETL_NODISCARD etl::enable_if< etl::is_pointer< TPointer >::value &&!etl::is_const< typenameetl::remove_pointer< TPointer >::type >::value &&etl::is_integral< T >::value &&sizeof(T)==1, char * >::type mem_char(TPointer sb, TPointer se, T value) ETL_NOEXCEPT
Definition memory.h:3450
ETL_CONSTEXPR T * to_address(T *p) ETL_NOEXCEPT
Definition memory.h:61
ETL_CONSTEXPR TContainer::size_type size(const TContainer &container)
Definition iterator.h:1434
TContainer::iterator end(TContainer &container)
Definition iterator.h:1166
T * mem_copy(const T *sb, const T *se, T *db) ETL_NOEXCEPT
Definition memory.h:3260
TContainer::iterator begin(TContainer &container)
Definition iterator.h:1136
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1103
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1117
TObject & get_object_at(void *p)
Get the container at 'p'.
Definition memory.h:3613
is_const
Definition type_traits.h:213