31#ifndef ETL_UTILITY_INCLUDED
32#define ETL_UTILITY_INCLUDED
40#if defined(ETL_IN_UNIT_TEST) || ETL_USING_STL
56 constexpr typename etl::remove_reference<T>::type&& move(T&& t) ETL_NOEXCEPT
58 return static_cast<typename etl::remove_reference<T>::type&&
>(t);
63 constexpr T&& forward(
typename etl::remove_reference<T>::type& t) ETL_NOEXCEPT
65 return static_cast<T&&
>(t);
69 constexpr T&& forward(
typename etl::remove_reference<T>::type&& t) ETL_NOEXCEPT
71 ETL_STATIC_ASSERT(!etl::is_lvalue_reference<T>::value,
"Invalid rvalue to lvalue conversion");
72 return static_cast<T&&
>(t);
88 template <
typename T,
typename U>
90 ETL_CONSTEXPR etl::enable_if_t<etl::is_const<etl::remove_reference_t<T>>::value && etl::is_lvalue_reference<T>::value,
91 const etl::remove_reference_t<U>&> forward_like(U&& u) ETL_NOEXCEPT
93 return static_cast<const etl::remove_reference_t<U>&
>(u);
99 template <
typename T,
typename U>
101 ETL_CONSTEXPR etl::enable_if_t<etl::is_const<etl::remove_reference_t<T>>::value && !etl::is_lvalue_reference<T>::value,
102 const etl::remove_reference_t<U>&&> forward_like(U&& u) ETL_NOEXCEPT
104 return static_cast<const etl::remove_reference_t<U>&&
>(u);
110 template <
typename T,
typename U>
112 ETL_CONSTEXPR etl::enable_if_t<!etl::is_const<etl::remove_reference_t<T>>::value && etl::is_lvalue_reference<T>::value, etl::remove_reference_t<U>&>
113 forward_like(U&& u) ETL_NOEXCEPT
115 return static_cast<etl::remove_reference_t<U>&
>(u);
121 template <
typename T,
typename U>
123 ETL_CONSTEXPR etl::enable_if_t<!etl::is_const<etl::remove_reference_t<T>>::value && !etl::is_lvalue_reference<T>::value, etl::remove_reference_t<U>&&>
124 forward_like(U&& u) ETL_NOEXCEPT
126 return static_cast<etl::remove_reference_t<U>&&
>(u);
132 template <
typename T,
typename U>
133 using forward_like_t =
decltype(etl::forward_like<T>(etl::declval<U&>()));
139 template <
typename T>
140 ETL_CONSTEXPR
typename underlying_type<T>::type to_underlying(T value) ETL_NOEXCEPT
142 return static_cast<typename underlying_type<T>::type
>(value);
148#if ETL_NOT_USING_STL && !defined(ETL_IN_UNIT_TEST)
151 template <
typename T>
152 ETL_CONSTEXPR14
void swap(T& a, T& b) ETL_NOEXCEPT
159 template <
class T,
size_t Size >
160 ETL_CONSTEXPR14
void swap(T (&a)[Size], T (&b)[Size]) ETL_NOEXCEPT
162 for (
size_t i = 0UL; i < Size; ++i)
174 template <
typename T1,
typename T2>
200 ETL_CONSTEXPR14
pair(
const T1& a,
const T2& b)
210 template <
typename U1,
typename U2>
211 ETL_CONSTEXPR14
pair(U1&& a, U2&& b)
223 template <
typename U1,
typename U2>
239 template <
typename U1,
typename U2>
247#if defined(ETL_IN_UNIT_TEST) || ETL_USING_STL
249 template <
typename U1,
typename U2>
250 operator std::pair<U1, U2>()
256 template <
typename U1,
typename U2>
257 pair(
const std::pair<U1, U2>& other)
265 template <
typename U1,
typename U2>
266 pair(std::pair<U1, U2>&& other)
276 using ETL_OR_STD::swap;
290 template <
typename U1,
typename U2>
302 first = etl::forward<T1>(other.first);
303 second = etl::forward<T2>(other.second);
308 template <
typename U1,
typename U2>
311 first = etl::forward<U1>(other.first);
312 second = etl::forward<U2>(other.second);
328 template <
typename T1,
typename T2>
331 return pair<T1, T2>(etl::forward<T1>(a), etl::forward<T2>(b));
334 template <
typename T1,
typename T2>
343 template <
size_t Index,
typename T1,
typename T2>
344 struct tuple_element<Index, ETL_OR_STD::pair<T1, T2> >
346 ETL_STATIC_ASSERT(Index < 2U,
"pair has only 2 elements");
349 template <
typename T1,
typename T2>
350 struct tuple_element<0U, ETL_OR_STD::
pair<T1, T2> >
355 template <
typename T1,
typename T2>
356 struct tuple_element<1U, ETL_OR_STD::
pair<T1, T2> >
362 template <
typename T1,
typename T2>
363 struct tuple_size<ETL_OR_STD::
pair<T1, T2>> :
public etl::integral_constant<size_t, 2U>
369 template <
typename T1,
typename T2>
376 template <
typename T1,
typename T2>
380 return (a.first == b.first) && !(a.second < b.second) && !(a.second > b.second);
385 template <
typename T1,
typename T2>
391 template <
typename T1,
typename T2>
392 inline bool operator<(
const pair<T1, T2>& a,
const pair<T1, T2>& b)
394 return (a.first < b.first) || (!(b.first < a.first) && (a.second < b.second));
398 template <
typename T1,
typename T2>
405 template <
typename T1,
typename T2>
412 template <
typename T1,
typename T2>
432 template <
typename TPair>
435 typedef typename TPair::first_type
type;
469 template <
typename TPair>
472 typedef typename TPair::second_type
type;
492#if ETL_NOT_USING_STL || ETL_CPP14_NOT_SUPPORTED
496 template <
typename T>
499 T old_value = object;
504 template <
typename T,
typename U>
505 T
exchange(T&
object,
const U& new_value)
507 T old_value = object;
515 template <
typename T,
typename U = T>
516 T
exchange(T&
object,
const U& new_value)
518 return std::exchange(
object, new_value);
525 template <
typename T>
535 template <
typename T, T... Integers>
536 class integer_sequence
540 ETL_STATIC_ASSERT(etl::is_integral<T>::value,
"Integral types only");
542 typedef T value_type;
544 static ETL_CONSTEXPR
size_t size() ETL_NOEXCEPT
546 return sizeof...(Integers);
550 namespace private_integer_sequence
552 template <
size_t Count,
typename IndexSeq>
553 struct make_index_sequence;
555 template <
size_t Count,
size_t... Indices>
556 struct make_index_sequence<Count, etl::integer_sequence<size_t, Indices...>>
558 using type =
typename make_index_sequence< Count - 1, etl::integer_sequence<size_t, Count - 1, Indices...>>::type;
561 template <
size_t... Indices>
562 struct make_index_sequence<0, etl::integer_sequence<size_t, Indices...>>
564 using type = etl::integer_sequence<size_t, Indices...>;
567 template <
size_t Offset,
typename IndexSeq>
568 struct offset_index_sequence;
570 template <
size_t Offset,
size_t... Indices>
571 struct offset_index_sequence<Offset, etl::integer_sequence<size_t, Indices...>>
573 using type = etl::integer_sequence<size_t, (Offset + Indices)...>;
580 template <
size_t Count>
581 using make_index_sequence =
typename private_integer_sequence::make_index_sequence< Count, etl::integer_sequence<size_t>>::type;
586 template <
size_t Offset,
size_t Count>
587 using make_index_sequence_with_offset =
typename private_integer_sequence::offset_index_sequence< Offset, etl::make_index_sequence<Count>>::type;
592 template <
typename... TTypes>
595 namespace private_make_index_sequence_for
598 template <
typename... TTypes>
601 using type =
typename private_integer_sequence::make_index_sequence<
sizeof...(TTypes), etl::integer_sequence<size_t>>::type;
605 template <
typename... TTypes>
606 struct impl<etl::type_list<TTypes...>> : impl<TTypes...>
616 template <
typename... TTypes>
617 using make_index_sequence_for =
typename private_make_index_sequence_for::impl<TTypes...>::type;
622 template <
size_t... Indices>
623 using index_sequence = etl::integer_sequence<size_t, Indices...>;
628 template <
typename... TTypes>
629 using index_sequence_for =
typename etl::make_index_sequence_for<TTypes...>;
634 template <
typename TIndexSequence1,
typename TIndexSequence2>
635 struct index_sequence_cat;
637 template <
size_t... Indices1,
size_t... Indices2>
638 struct index_sequence_cat<etl::index_sequence<Indices1...>, etl::index_sequence<Indices2...>>
640 using type = etl::index_sequence<Indices1..., Indices2...>;
643 template <
typename TIndexSequence1,
typename TIndexSequence2>
644 using index_sequence_cat_t =
typename index_sequence_cat<TIndexSequence1, TIndexSequence2>::type;
649 template <
typename TIndexSequence,
size_t Index>
650 struct index_sequence_push_front;
652 template <
size_t... Indices,
size_t Index>
653 struct index_sequence_push_front<etl::index_sequence<Indices...>, Index>
656 using type = etl::index_sequence<Index, Indices...>;
659 template <
typename TIndexSequence,
size_t Index>
660 using index_sequence_push_front_t =
typename index_sequence_push_front<TIndexSequence, Index>::type;
665 template <
typename TIndexSequence>
666 struct index_sequence_pop_front;
669 struct index_sequence_pop_front<etl::index_sequence<>>
671 using type = etl::index_sequence<>;
674 template <
size_t Index,
size_t... Indices>
675 struct index_sequence_pop_front<etl::index_sequence<Index, Indices...>>
679 using type = etl::index_sequence<Indices...>;
682 template <
typename TIndexSequence>
683 using index_sequence_pop_front_t =
typename index_sequence_pop_front<TIndexSequence>::type;
688 template <
typename TIndexSequence,
size_t Index>
689 struct index_sequence_push_back;
691 template <
size_t... Indices,
size_t Index>
692 struct index_sequence_push_back<etl::index_sequence<Indices...>, Index>
696 using type = etl::index_sequence<Indices..., Index>;
699 template <
typename TIndexSequence,
size_t Index>
700 using index_sequence_push_back_t =
typename index_sequence_push_back<TIndexSequence, Index>::type;
705 template <
typename TIndexSequence>
706 struct index_sequence_pop_back;
710 struct index_sequence_pop_back<etl::index_sequence<>>
712 using type = etl::index_sequence<>;
718 template <
size_t Index>
719 struct index_sequence_pop_back<etl::index_sequence<Index>>
721 using type = etl::index_sequence<>;
726 template <
size_t Index,
size_t... Indices>
727 struct index_sequence_pop_back<etl::index_sequence<Index, Indices...>>
732 using type = etl::index_sequence_cat_t< etl::index_sequence<Index>,
typename index_sequence_pop_back<etl::index_sequence<Indices...>>::type>;
735 template <
typename TIndexSequence>
736 using index_sequence_pop_back_t =
typename index_sequence_pop_back<TIndexSequence>::type;
741 template <
typename TIndexSequence,
size_t Nth>
742 struct index_sequence_at;
744 template <
size_t Nth>
745 struct index_sequence_at<etl::index_sequence<>, Nth>
752 static_assert(dependent_false<Nth>::value,
"Nth out of range for index_sequence_at");
757 template <
size_t Index,
size_t... Indices>
758 struct index_sequence_at<etl::index_sequence<Index, Indices...>, 0>
760 static constexpr size_t value = Index;
765 template <
size_t Index,
size_t... Indices,
size_t Nth>
766 struct index_sequence_at<etl::index_sequence<Index, Indices...>, Nth>
768 static_assert(Nth <
sizeof...(Indices) + 1U,
"Nth out of range for index_sequence_at");
770 static constexpr size_t value = index_sequence_at<etl::index_sequence<Indices...>, Nth - 1U>::value;
774 template <
typename TIndexSequence,
size_t Nth>
775 inline constexpr size_t index_sequence_at_v = index_sequence_at<TIndexSequence, Nth>::value;
781 template <
typename TIndexSequence,
size_t Value>
782 struct index_sequence_contains;
785 template <
size_t Value>
786 struct index_sequence_contains<etl::index_sequence<>, Value> :
etl::false_type
793 template <
size_t Index,
size_t... Indices,
size_t Value>
794 struct index_sequence_contains<etl::index_sequence<Index, Indices...>, Value>
795 : etl::integral_constant< bool, (Index == Value) || index_sequence_contains<etl::index_sequence<Indices...>, Value>::value>
800 template <
typename TIndexSequence,
size_t Value>
801 inline constexpr bool index_sequence_contains_v = index_sequence_contains<TIndexSequence, Value>::value;
808 namespace private_index_sequence
810 template <
typename TIndexSequence,
typename TUniqueIndices>
811 struct type_index_sequence_impl;
816 template <
size_t Index,
size_t... Indices,
size_t... UniqueIndices>
817 struct type_index_sequence_impl<etl::index_sequence<Index, Indices...>, etl::index_sequence<UniqueIndices...>>
822 typename etl::conditional_t< etl::index_sequence_contains<etl::index_sequence<UniqueIndices...>, Index>::value,
823 type_index_sequence_impl<etl::index_sequence<Indices...>, etl::index_sequence<UniqueIndices...>>,
824 type_index_sequence_impl< etl::index_sequence<Indices...>,
825 etl::index_sequence_push_back_t<etl::index_sequence<UniqueIndices...>, Index>>>::type;
829 template <
size_t... UniqueIndices>
830 struct type_index_sequence_impl<etl::index_sequence<>, etl::index_sequence<UniqueIndices...>>
832 using type = etl::index_sequence<UniqueIndices...>;
836 template <
typename T>
837 struct index_sequence_unique;
839 template <
size_t... Indices>
840 struct index_sequence_unique<etl::index_sequence<Indices...>>
842 using type =
typename private_index_sequence::type_index_sequence_impl< etl::index_sequence<Indices...>, etl::index_sequence<>>::type;
846 template <
typename TIndexSequence>
847 using index_sequence_unique_t =
typename etl::index_sequence_unique<TIndexSequence>::type;
853 template <
typename T>
854 struct index_sequence_is_unique;
856 template <
size_t... Indices>
857 struct index_sequence_is_unique<etl::index_sequence<Indices...>>
858 : etl::bool_constant< etl::is_same< etl::index_sequence<Indices...>, etl::index_sequence_unique_t<etl::index_sequence<Indices...>>>::value>
863 template <
typename TIndexSequence>
864 inline constexpr bool index_sequence_is_unique_v = index_sequence_is_unique<TIndexSequence>::type::value;
870 template <
typename T>
871 struct index_sequence_is_empty;
874 struct index_sequence_is_empty<etl::index_sequence<>> : etl::true_type
878 template <
size_t... Indices>
879 struct index_sequence_is_empty<etl::index_sequence<Indices...>> :
etl::false_type
884 template <
typename... TTypes>
885 inline constexpr bool index_sequence_is_empty_v = index_sequence_is_empty<TTypes...>::value;
892 template <
typename T>
901 coordinate_2d(T x_, T y_)
907 friend bool operator==(
const coordinate_2d& lhs,
const coordinate_2d& rhs)
909 return (lhs.x == rhs.x) && (lhs.y == rhs.y);
912 friend bool operator!=(
const coordinate_2d& lhs,
const coordinate_2d& rhs)
914 return !(lhs == rhs);
928 explicit ETL_CONSTEXPR in_place_t() {}
936 template <
typename T>
937 struct in_place_type_t
939 explicit ETL_CONSTEXPR in_place_type_t() {}
943 template <
typename T>
948 template <
size_t Index>
949 struct in_place_index_t
951 explicit ETL_CONSTEXPR in_place_index_t() {}
955 template <
size_t Index>
966 template <
typename TReturn,
typename... TParams>
967 class ETL_DEPRECATED functor
974 constexpr functor(TReturn (*ptr_)(TParams...))
982 constexpr TReturn operator()(TParams... args)
const
984 return ptr(etl::forward<TParams>(args)...);
990 TReturn (*ptr)(TParams...);
999 template <
typename T>
1000 class member_function_wrapper;
1002 template <
typename TReturn,
typename... TParams>
1003 class ETL_DEPRECATED member_function_wrapper<TReturn(TParams...)>
1007 template <
typename T, T& Instance, TReturn (T::*Method)(TParams...)>
1008 static constexpr TReturn function(TParams... params)
1010 return (Instance.*Method)(etl::forward<TParams>(params)...);
1020 template <
typename T>
1021 class functor_wrapper;
1023 template <
typename TReturn,
typename... TParams>
1024 class functor_wrapper<TReturn(TParams...)>
1028 template <
typename TFunctor, TFunctor& Instance>
1029 static constexpr TReturn function(TParams... params)
1031 return Instance(etl::forward<TParams>(params)...);
1041 template <auto& Instance>
1042 struct functor_as_static
1044 template <
typename... TArgs>
1045 static constexpr auto call(TArgs&&... args)
1047 return (Instance.operator())(etl::forward<TArgs>(args)...);
1055 template <auto Method, auto& Instance>
1056 struct member_function_as_static
1058 template <
typename... TArgs>
1059 static constexpr auto call(TArgs&&... args)
1061 return (Instance.*Method)(etl::forward<TArgs>(args)...);
1069 template <auto Method, auto& Instance>
1070 class member_function_as_functor
1074 template <
typename... TArgs>
1075 constexpr auto operator()(TArgs&&... args)
const ->
decltype((Instance.*Method)(etl::forward<TArgs>(args)...))
1077 return (Instance.*Method)(etl::forward<TArgs>(args)...);
1085 template <auto Function>
1086 class function_as_functor
1090 template <
typename... TArgs>
1091 constexpr auto operator()(TArgs&&... args)
const ->
decltype(Function(etl::forward<TArgs>(args)...))
1093 return Function(etl::forward<TArgs>(args)...);
1103 template <
typename T>
1104 class function_ptr_as_functor;
1106 template <
typename TReturn,
typename... TArgs>
1107 class function_ptr_as_functor<TReturn(TArgs...)>
1114 constexpr function_ptr_as_functor(TReturn (*ptr_)(TArgs...))
1122 constexpr TReturn operator()(TArgs... args)
const
1124 return ptr(etl::forward<TArgs>(args)...);
1130 TReturn (*ptr)(TArgs...);
1134#if ETL_USING_CPP17 && !defined(ETL_FORCE_CPP11_NONTYPE)
1138 template <auto Value>
1141 static constexpr decltype(Value) value = Value;
1143#elif ETL_USING_CPP11
1147 template <
typename T, T Value>
1150 static constexpr T value = Value;
void swap(etl::array_view< T > &lhs, etl::array_view< T > &rhs) ETL_NOEXCEPT
Swaps the values.
Definition array_view.h:692
Two pairs of the same type are equal if their members are equal.
bitset_ext
Definition absolute.h:40
ETL_CONSTEXPR14 void swap(etl::typed_storage_ext< T > &lhs, etl::typed_storage_ext< T > &rhs) ETL_NOEXCEPT
Swap two etl::typed_storage_ext.
Definition alignment.h:856
ETL_CONSTEXPR14 bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1081
pair< T1, T2 > make_pair(T1 a, T2 b)
A convenience wrapper for creating a pair from two objects.
Definition utility.h:335
T exchange(T &object, const T &new_value)
exchange (const)
Definition utility.h:497
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1133
integral_constant< bool, false > false_type
integral_constant specialisations
Definition type_traits.h:80
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1147
ETL_CONSTEXPR14 bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1093
etl::add_const< T >::type & as_const(T &t)
as_const
Definition utility.h:526
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1106
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1120
in_place disambiguation tags.
Definition utility.h:927
pair holds two objects of arbitrary type
Definition utility.h:176
T1 first_type
first_type is the first bound type
Definition utility.h:177
pair(const std::pair< U1, U2 > &other)
Constructing from std::pair.
Definition utility.h:257
T1 first
first is a copy of the first object
Definition utility.h:180
ETL_CONSTEXPR pair()
Default constructor.
Definition utility.h:189
ETL_CONSTEXPR14 pair(const T1 &a, const T2 &b)
Constructor from parameters.
Definition utility.h:200
ETL_CONSTEXPR14 pair(const pair< U1, U2 > &other)
Copy constructor.
Definition utility.h:224
pair(const pair< T1, T2 > &other)
Copy constructor.
Definition utility.h:231
T2 second
second is a copy of the second object
Definition utility.h:181
T2 second_type
second_type is the second bound type
Definition utility.h:178
Functor to select pair::first.
Definition utility.h:434
type & operator()(TPair &p) const
Function call that return p.first.
Definition utility.h:441
const type & operator()(const TPair &p) const
Function call that return p.first.
Definition utility.h:449
TPair::first_type type
type of member pair::first.
Definition utility.h:435
Functor to select pair::second.
Definition utility.h:471
type & operator()(TPair &p) const
Function call. The return value is p.second.
Definition utility.h:478
const type & operator()(const TPair &p) const
Function call. The return value is p.second.
Definition utility.h:486
TPair::second_type type
type of member pair::second.
Definition utility.h:472
Definition tuple_size.h:38