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);
85 template <
typename T,
typename U>
88 etl::enable_if_t<etl::is_const<etl::remove_reference_t<T>>::value && etl::is_lvalue_reference<T>::value,
const etl::remove_reference_t<U>&>
89 forward_like(U&& u) ETL_NOEXCEPT
91 return static_cast<const etl::remove_reference_t<U>&
>(u);
97 template <
typename T,
typename U>
100 etl::enable_if_t<etl::is_const<etl::remove_reference_t<T>>::value && !etl::is_lvalue_reference<T>::value,
const etl::remove_reference_t<U>&&>
101 forward_like(U&& u) ETL_NOEXCEPT
103 return static_cast<const etl::remove_reference_t<U>&&
>(u);
109 template <
typename T,
typename U>
112 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>
124 etl::enable_if_t<!etl::is_const<etl::remove_reference_t<T>>::value && !etl::is_lvalue_reference<T>::value, etl::remove_reference_t<U>&&>
125 forward_like(U&& u) ETL_NOEXCEPT
127 return static_cast<etl::remove_reference_t<U>&&
>(u);
133 template <
typename T,
typename U>
134 using forward_like_t =
decltype(etl::forward_like<T>(etl::declval<U&>()));
140 template <
typename T>
141 ETL_CONSTEXPR
typename underlying_type<T>::type to_underlying(T value) ETL_NOEXCEPT
143 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>
199 ETL_CONSTEXPR14
pair(
const T1& a,
const T2& b)
209 template <
typename U1,
typename U2>
210 ETL_CONSTEXPR14
pair(U1&& a, U2&& b)
222 template <
typename U1,
typename U2>
238 template <
typename U1,
typename U2>
246#if defined(ETL_IN_UNIT_TEST) || ETL_USING_STL
248 template <
typename U1,
typename U2>
249 operator std::pair<U1, U2>()
255 template <
typename U1,
typename U2>
256 pair(
const std::pair<U1, U2>& other)
264 template <
typename U1,
typename U2>
265 pair(std::pair<U1, U2>&& other)
275 using ETL_OR_STD::swap;
289 template <
typename U1,
typename U2>
301 first = etl::forward<T1>(other.first);
302 second = etl::forward<T2>(other.second);
307 template <
typename U1,
typename U2>
310 first = etl::forward<U1>(other.first);
311 second = etl::forward<U2>(other.second);
327 template <
typename T1,
typename T2>
330 return pair<T1, T2>(etl::forward<T1>(a), etl::forward<T2>(b));
333 template <
typename T1,
typename T2>
342 template <
size_t Index,
typename T1,
typename T2>
343 struct tuple_element<Index, ETL_OR_STD::pair<T1, T2> >
345 ETL_STATIC_ASSERT(Index < 2U,
"pair has only 2 elements");
348 template <
typename T1,
typename T2>
349 struct tuple_element<0U, ETL_OR_STD::
pair<T1, T2> >
354 template <
typename T1,
typename T2>
355 struct tuple_element<1U, ETL_OR_STD::
pair<T1, T2> >
361 template <
typename T1,
typename T2>
362 struct tuple_size<ETL_OR_STD::
pair<T1, T2>> :
public etl::integral_constant<size_t, 2U>
368 template <
typename T1,
typename T2>
375 template <
typename T1,
typename T2>
379 return (a.first == b.first) && !(a.second < b.second) && !(a.second > b.second);
384 template <
typename T1,
typename T2>
390 template <
typename T1,
typename T2>
391 inline bool operator <(
const pair<T1, T2>& a,
const pair<T1, T2>& b)
393 return (a.first < b.first) ||
394 (!(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>
430 template <
typename TPair>
433 typedef typename TPair::first_type
type;
465 template <
typename TPair>
468 typedef typename TPair::second_type
type;
488#if ETL_NOT_USING_STL || ETL_CPP14_NOT_SUPPORTED
492 template <
typename T>
495 T old_value = object;
500 template <
typename T,
typename U>
501 T
exchange(T&
object,
const U& new_value)
503 T old_value = object;
511 template <
typename T,
typename U = T>
512 T
exchange(T&
object,
const U& new_value)
514 return std::exchange(
object, new_value);
521 template <
typename T>
531 template <
typename T, T... Integers>
532 class integer_sequence
536 ETL_STATIC_ASSERT(etl::is_integral<T>::value,
"Integral types only");
538 typedef T value_type;
540 static ETL_CONSTEXPR
size_t size() ETL_NOEXCEPT
542 return sizeof...(Integers);
546 namespace private_integer_sequence
548 template <
size_t Count,
typename IndexSeq>
549 struct make_index_sequence;
551 template <
size_t Count,
size_t... Indices>
552 struct make_index_sequence<Count, etl::integer_sequence<size_t, Indices...>>
554 using type =
typename make_index_sequence<Count - 1, etl::integer_sequence<size_t, Count - 1, Indices...>>::type;
557 template <
size_t... Indices>
558 struct make_index_sequence<0, etl::integer_sequence<size_t, Indices...>>
560 using type = etl::integer_sequence<size_t, Indices...>;
565 template <
size_t Count>
566 using make_index_sequence =
typename private_integer_sequence::make_index_sequence<Count, etl::integer_sequence<size_t>>::type;
568 template <
typename... TTypes>
569 using make_index_sequence_for =
typename private_integer_sequence::make_index_sequence<
sizeof...(TTypes), etl::integer_sequence<size_t>>::type;
572 template <
size_t... Indices>
573 using index_sequence = etl::integer_sequence<size_t, Indices...>;
575 template <
typename... TTypes>
576 using index_sequence_for =
typename etl::make_index_sequence_for<TTypes...>;
582 template <
typename T>
591 coordinate_2d(T x_, T y_)
597 friend bool operator ==(
const coordinate_2d& lhs,
const coordinate_2d& rhs)
599 return (lhs.x == rhs.x) && (lhs.y == rhs.y);
602 friend bool operator !=(
const coordinate_2d& lhs,
const coordinate_2d& rhs)
604 return !(lhs == rhs);
618 explicit ETL_CONSTEXPR in_place_t() {}
626 template <
typename T>
struct in_place_type_t
628 explicit ETL_CONSTEXPR in_place_type_t() {}
632 template <
typename T>
637 template <
size_t Index>
struct in_place_index_t
639 explicit ETL_CONSTEXPR in_place_index_t() {}
643 template <
size_t Index>
654 template <
typename TReturn,
typename... TParams>
655 class ETL_DEPRECATED functor
662 constexpr functor(TReturn(*ptr_)(TParams...))
670 constexpr TReturn operator()(TParams... args)
const
672 return ptr(etl::forward<TParams>(args)...);
678 TReturn(*ptr)(TParams...);
687 template <
typename T>
688 class member_function_wrapper;
690 template <
typename TReturn,
typename... TParams>
691 class ETL_DEPRECATED member_function_wrapper<TReturn(TParams...)>
695 template <
typename T, T& Instance, TReturn(T::* Method)(TParams...)>
696 static constexpr TReturn function(TParams... params)
698 return (Instance.*Method)(etl::forward<TParams>(params)...);
708 template <
typename T>
709 class functor_wrapper;
711 template <
typename TReturn,
typename... TParams>
712 class functor_wrapper<TReturn(TParams...)>
716 template <
typename TFunctor, TFunctor& Instance>
717 static constexpr TReturn function(TParams... params)
719 return Instance(etl::forward<TParams>(params)...);
729 template <auto& Instance>
730 struct functor_as_static
732 template <
typename... TArgs>
733 static constexpr auto call(TArgs&&... args)
735 return (Instance.operator())(etl::forward<TArgs>(args)...);
743 template <auto Method, auto& Instance>
744 struct member_function_as_static
746 template <
typename... TArgs>
747 static constexpr auto call(TArgs&&... args)
749 return (Instance.*Method)(etl::forward<TArgs>(args)...);
757 template <auto Method, auto& Instance>
758 class member_function_as_functor
762 template <
typename... TArgs>
763 constexpr auto operator()(TArgs&&... args)
const ->
decltype((Instance.*Method)(etl::forward<TArgs>(args)...))
765 return (Instance.*Method)(etl::forward<TArgs>(args)...);
773 template <auto Function>
774 class function_as_functor
778 template<
typename... TArgs>
779 constexpr auto operator()(TArgs&&... args)
const ->
decltype(Function(etl::forward<TArgs>(args)...))
781 return Function(etl::forward<TArgs>(args)...);
791 template <
typename T>
792 class function_ptr_as_functor;
794 template <
typename TReturn,
typename... TArgs>
795 class function_ptr_as_functor<TReturn(TArgs...)>
802 constexpr function_ptr_as_functor(TReturn(*ptr_)(TArgs...))
810 constexpr TReturn operator()(TArgs... args)
const
812 return ptr(etl::forward<TArgs>(args)...);
818 TReturn(*ptr)(TArgs...);
822#if ETL_USING_CPP17 && !defined(ETL_FORCE_CPP11_NONTYPE)
826 template <auto Value>
829 static constexpr decltype(Value) value = Value;
835 template <
typename T, T Value>
838 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:650
Two pairs of the same type are equal if their members are equal.
bitset_ext
Definition absolute.h:39
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:838
pair< T1, T2 > make_pair(T1 a, T2 b)
A convenience wrapper for creating a pair from two objects.
Definition utility.h:334
T exchange(T &object, const T &new_value)
exchange (const)
Definition utility.h:493
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1190
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1202
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1151
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1139
etl::add_const< T >::type & as_const(T &t)
as_const
Definition utility.h:522
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1163
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1178
in_place disambiguation tags.
Definition utility.h:617
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:256
T1 first
first is a copy of the first object
Definition utility.h:180
ETL_CONSTEXPR pair()
Default constructor.
Definition utility.h:188
ETL_CONSTEXPR14 pair(const T1 &a, const T2 &b)
Constructor from parameters.
Definition utility.h:199
ETL_CONSTEXPR14 pair(const pair< U1, U2 > &other)
Copy constructor.
Definition utility.h:223
pair(const pair< T1, T2 > &other)
Copy constructor.
Definition utility.h:230
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:432
type & operator()(TPair &p) const
Function call that return p.first.
Definition utility.h:439
const type & operator()(const TPair &p) const
Function call that return p.first.
Definition utility.h:447
TPair::first_type type
type of member pair::first.
Definition utility.h:433
Functor to select pair::second.
Definition utility.h:467
type & operator()(TPair &p) const
Function call. The return value is p.second.
Definition utility.h:474
const type & operator()(const TPair &p) const
Function call. The return value is p.second.
Definition utility.h:482
TPair::second_type type
type of member pair::second.
Definition utility.h:468
Definition tuple_size.h:38