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 ETL_CONSTEXPR
pair(
const std::pair<U1, U2>& other)
265 template <
typename U1,
typename U2>
266 ETL_CONSTEXPR
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);
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
493 #if ETL_CPP11_NOT_SUPPORTED
497 template <
typename T>
500 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 ETL_CONSTEXPR14 T
exchange(T&
object, U&& new_value)
517 ETL_NOEXCEPT_IF((etl::is_nothrow_move_constructible<T>::value && etl::is_nothrow_assignable<T&, U>::value))
519 T old_value = etl::move(
object);
520 object = etl::forward<U>(new_value);
528 template <
typename T,
typename U = T>
529 ETL_CONSTEXPR14 T
exchange(T&
object, U&& new_value)
530 ETL_NOEXCEPT_IF((etl::is_nothrow_move_constructible<T>::value && etl::is_nothrow_assignable<T&, U>::value))
532 return std::exchange(
object, etl::forward<U>(new_value));
539 template <
typename T>
549 template <
typename T, T... Integers>
550 class integer_sequence
554 ETL_STATIC_ASSERT(etl::is_integral<T>::value,
"Integral types only");
556 typedef T value_type;
558 static ETL_CONSTEXPR
size_t size() ETL_NOEXCEPT
560 return sizeof...(Integers);
564 namespace private_integer_sequence
566 template <
size_t Count,
typename IndexSeq>
567 struct make_index_sequence;
569 template <
size_t Count,
size_t... Indices>
570 struct make_index_sequence<Count, etl::integer_sequence<size_t, Indices...>>
572 using type =
typename make_index_sequence< Count - 1, etl::integer_sequence<size_t, Count - 1, Indices...>>::type;
575 template <
size_t... Indices>
576 struct make_index_sequence<0, etl::integer_sequence<size_t, Indices...>>
578 using type = etl::integer_sequence<size_t, Indices...>;
581 template <
size_t Offset,
typename IndexSeq>
582 struct offset_index_sequence;
584 template <
size_t Offset,
size_t... Indices>
585 struct offset_index_sequence<Offset, etl::integer_sequence<size_t, Indices...>>
587 using type = etl::integer_sequence<size_t, (Offset + Indices)...>;
594 template <
size_t Count>
595 using make_index_sequence =
typename private_integer_sequence::make_index_sequence< Count, etl::integer_sequence<size_t>>::type;
600 template <
size_t Offset,
size_t Count>
601 using make_index_sequence_with_offset =
typename private_integer_sequence::offset_index_sequence< Offset, etl::make_index_sequence<Count>>::type;
606 template <
typename... TTypes>
609 namespace private_make_index_sequence_for
612 template <
typename... TTypes>
615 using type =
typename private_integer_sequence::make_index_sequence<
sizeof...(TTypes), etl::integer_sequence<size_t>>::type;
619 template <
typename... TTypes>
620 struct impl<etl::type_list<TTypes...>> : impl<TTypes...>
630 template <
typename... TTypes>
631 using make_index_sequence_for =
typename private_make_index_sequence_for::impl<TTypes...>::type;
636 template <
size_t... Indices>
637 using index_sequence = etl::integer_sequence<size_t, Indices...>;
642 template <
typename... TTypes>
643 using index_sequence_for =
typename etl::make_index_sequence_for<TTypes...>;
648 template <
typename TIndexSequence1,
typename TIndexSequence2>
649 struct index_sequence_cat;
651 template <
size_t... Indices1,
size_t... Indices2>
652 struct index_sequence_cat<etl::index_sequence<Indices1...>, etl::index_sequence<Indices2...>>
654 using type = etl::index_sequence<Indices1..., Indices2...>;
657 template <
typename TIndexSequence1,
typename TIndexSequence2>
658 using index_sequence_cat_t =
typename index_sequence_cat<TIndexSequence1, TIndexSequence2>::type;
663 template <
typename TIndexSequence,
size_t Index>
664 struct index_sequence_push_front;
666 template <
size_t... Indices,
size_t Index>
667 struct index_sequence_push_front<etl::index_sequence<Indices...>, Index>
670 using type = etl::index_sequence<Index, Indices...>;
673 template <
typename TIndexSequence,
size_t Index>
674 using index_sequence_push_front_t =
typename index_sequence_push_front<TIndexSequence, Index>::type;
679 template <
typename TIndexSequence>
680 struct index_sequence_pop_front;
683 struct index_sequence_pop_front<etl::index_sequence<>>
685 using type = etl::index_sequence<>;
688 template <
size_t Index,
size_t... Indices>
689 struct index_sequence_pop_front<etl::index_sequence<Index, Indices...>>
693 using type = etl::index_sequence<Indices...>;
696 template <
typename TIndexSequence>
697 using index_sequence_pop_front_t =
typename index_sequence_pop_front<TIndexSequence>::type;
702 template <
typename TIndexSequence,
size_t Index>
703 struct index_sequence_push_back;
705 template <
size_t... Indices,
size_t Index>
706 struct index_sequence_push_back<etl::index_sequence<Indices...>, Index>
710 using type = etl::index_sequence<Indices..., Index>;
713 template <
typename TIndexSequence,
size_t Index>
714 using index_sequence_push_back_t =
typename index_sequence_push_back<TIndexSequence, Index>::type;
719 template <
typename TIndexSequence>
720 struct index_sequence_pop_back;
724 struct index_sequence_pop_back<etl::index_sequence<>>
726 using type = etl::index_sequence<>;
732 template <
size_t Index>
733 struct index_sequence_pop_back<etl::index_sequence<Index>>
735 using type = etl::index_sequence<>;
740 template <
size_t Index,
size_t... Indices>
741 struct index_sequence_pop_back<etl::index_sequence<Index, Indices...>>
746 using type = etl::index_sequence_cat_t< etl::index_sequence<Index>,
typename index_sequence_pop_back<etl::index_sequence<Indices...>>::type>;
749 template <
typename TIndexSequence>
750 using index_sequence_pop_back_t =
typename index_sequence_pop_back<TIndexSequence>::type;
755 template <
typename TIndexSequence,
size_t Nth>
756 struct index_sequence_at;
758 template <
size_t Nth>
759 struct index_sequence_at<etl::index_sequence<>, Nth>
766 static_assert(dependent_false<Nth>::value,
"Nth out of range for index_sequence_at");
771 template <
size_t Index,
size_t... Indices>
772 struct index_sequence_at<etl::index_sequence<Index, Indices...>, 0>
774 static constexpr size_t value = Index;
779 template <
size_t Index,
size_t... Indices,
size_t Nth>
780 struct index_sequence_at<etl::index_sequence<Index, Indices...>, Nth>
782 static_assert(Nth <
sizeof...(Indices) + 1U,
"Nth out of range for index_sequence_at");
784 static constexpr size_t value = index_sequence_at<etl::index_sequence<Indices...>, Nth - 1U>::value;
788 template <
typename TIndexSequence,
size_t Nth>
789 inline constexpr size_t index_sequence_at_v = index_sequence_at<TIndexSequence, Nth>::value;
795 template <
typename TIndexSequence,
size_t Value>
796 struct index_sequence_contains;
799 template <
size_t Value>
800 struct index_sequence_contains<etl::index_sequence<>, Value> :
etl::false_type
807 template <
size_t Index,
size_t... Indices,
size_t Value>
808 struct index_sequence_contains<etl::index_sequence<Index, Indices...>, Value>
809 : etl::integral_constant< bool, (Index == Value) || index_sequence_contains<etl::index_sequence<Indices...>, Value>::value>
814 template <
typename TIndexSequence,
size_t Value>
815 inline constexpr bool index_sequence_contains_v = index_sequence_contains<TIndexSequence, Value>::value;
822 namespace private_index_sequence
824 template <
typename TIndexSequence,
typename TUniqueIndices>
825 struct type_index_sequence_impl;
830 template <
size_t Index,
size_t... Indices,
size_t... UniqueIndices>
831 struct type_index_sequence_impl<etl::index_sequence<Index, Indices...>, etl::index_sequence<UniqueIndices...>>
836 typename etl::conditional_t< etl::index_sequence_contains<etl::index_sequence<UniqueIndices...>, Index>::value,
837 type_index_sequence_impl<etl::index_sequence<Indices...>, etl::index_sequence<UniqueIndices...>>,
838 type_index_sequence_impl< etl::index_sequence<Indices...>,
839 etl::index_sequence_push_back_t<etl::index_sequence<UniqueIndices...>, Index>>>::type;
843 template <
size_t... UniqueIndices>
844 struct type_index_sequence_impl<etl::index_sequence<>, etl::index_sequence<UniqueIndices...>>
846 using type = etl::index_sequence<UniqueIndices...>;
850 template <
typename T>
851 struct index_sequence_unique;
853 template <
size_t... Indices>
854 struct index_sequence_unique<etl::index_sequence<Indices...>>
856 using type =
typename private_index_sequence::type_index_sequence_impl< etl::index_sequence<Indices...>, etl::index_sequence<>>::type;
860 template <
typename TIndexSequence>
861 using index_sequence_unique_t =
typename etl::index_sequence_unique<TIndexSequence>::type;
867 template <
typename T>
868 struct index_sequence_is_unique;
870 template <
size_t... Indices>
871 struct index_sequence_is_unique<etl::index_sequence<Indices...>>
872 : etl::bool_constant< etl::is_same< etl::index_sequence<Indices...>, etl::index_sequence_unique_t<etl::index_sequence<Indices...>>>::value>
877 template <
typename TIndexSequence>
878 inline constexpr bool index_sequence_is_unique_v = index_sequence_is_unique<TIndexSequence>::type::value;
884 template <
typename T>
885 struct index_sequence_is_empty;
888 struct index_sequence_is_empty<etl::index_sequence<>> : etl::true_type
892 template <
size_t... Indices>
893 struct index_sequence_is_empty<etl::index_sequence<Indices...>> :
etl::false_type
898 template <
typename... TTypes>
899 inline constexpr bool index_sequence_is_empty_v = index_sequence_is_empty<TTypes...>::value;
906 template <
typename T>
909 ETL_CONSTEXPR coordinate_2d()
915 ETL_CONSTEXPR coordinate_2d(T x_, T y_)
921 friend bool operator==(
const coordinate_2d& lhs,
const coordinate_2d& rhs)
923 return (lhs.x == rhs.x) && (lhs.y == rhs.y);
926 friend bool operator!=(
const coordinate_2d& lhs,
const coordinate_2d& rhs)
928 return !(lhs == rhs);
942 explicit ETL_CONSTEXPR in_place_t() {}
950 template <
typename T>
951 struct in_place_type_t
953 explicit ETL_CONSTEXPR in_place_type_t() {}
957 template <
typename T>
962 template <
size_t Index>
963 struct in_place_index_t
965 explicit ETL_CONSTEXPR in_place_index_t() {}
969 template <
size_t Index>
980 template <
typename TReturn,
typename... TParams>
981 class ETL_DEPRECATED functor
988 constexpr functor(TReturn (*ptr_)(TParams...))
996 constexpr TReturn operator()(TParams... args)
const
998 return ptr(etl::forward<TParams>(args)...);
1004 TReturn (*ptr)(TParams...);
1013 template <
typename T>
1014 class member_function_wrapper;
1016 template <
typename TReturn,
typename... TParams>
1017 class ETL_DEPRECATED member_function_wrapper<TReturn(TParams...)>
1021 template <
typename T, T& Instance, TReturn (T::*Method)(TParams...)>
1022 static constexpr TReturn function(TParams... params)
1024 return (Instance.*Method)(etl::forward<TParams>(params)...);
1034 template <
typename T>
1035 class functor_wrapper;
1037 template <
typename TReturn,
typename... TParams>
1038 class functor_wrapper<TReturn(TParams...)>
1042 template <
typename TFunctor, TFunctor& Instance>
1043 static constexpr TReturn function(TParams... params)
1045 return Instance(etl::forward<TParams>(params)...);
1055 template <auto& Instance>
1056 struct functor_as_static
1058 template <
typename... TArgs>
1059 static constexpr auto call(TArgs&&... args)
1061 return (Instance.operator())(etl::forward<TArgs>(args)...);
1069 template <auto Method, auto& Instance>
1070 struct member_function_as_static
1072 template <
typename... TArgs>
1073 static constexpr auto call(TArgs&&... args)
1075 return (Instance.*Method)(etl::forward<TArgs>(args)...);
1083 template <auto Method, auto& Instance>
1084 class member_function_as_functor
1088 template <
typename... TArgs>
1089 constexpr auto operator()(TArgs&&... args)
const ->
decltype((Instance.*Method)(etl::forward<TArgs>(args)...))
1091 return (Instance.*Method)(etl::forward<TArgs>(args)...);
1099 template <auto Function>
1100 class function_as_functor
1104 template <
typename... TArgs>
1105 constexpr auto operator()(TArgs&&... args)
const ->
decltype(Function(etl::forward<TArgs>(args)...))
1107 return Function(etl::forward<TArgs>(args)...);
1117 template <
typename T>
1118 class function_ptr_as_functor;
1120 template <
typename TReturn,
typename... TArgs>
1121 class function_ptr_as_functor<TReturn(TArgs...)>
1128 constexpr function_ptr_as_functor(TReturn (*ptr_)(TArgs...))
1136 constexpr TReturn operator()(TArgs... args)
const
1138 return ptr(etl::forward<TArgs>(args)...);
1144 TReturn (*ptr)(TArgs...);
1148#if ETL_USING_CPP17 && !defined(ETL_FORCE_CPP11_NONTYPE)
1152 template <auto Value>
1155 static constexpr decltype(Value) value = Value;
1157#elif ETL_USING_CPP11
1161 template <
typename T, T Value>
1164 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.
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:1078
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:498
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1130
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:1144
ETL_CONSTEXPR14 bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1090
etl::add_const< T >::type & as_const(T &t)
as_const
Definition utility.h:540
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
in_place disambiguation tags.
Definition utility.h:941
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
T1 first
first is a copy of the first object
Definition utility.h:180
ETL_CONSTEXPR pair(const pair< T1, T2 > &other)
Copy constructor.
Definition utility.h:231
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
ETL_CONSTEXPR pair(const std::pair< U1, U2 > &other)
Constructing from std::pair.
Definition utility.h:257
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