31#ifndef ETL_UTILITY_INCLUDED
32#define ETL_UTILITY_INCLUDED
37#if defined(ETL_IN_UNIT_TEST) || ETL_USING_STL
53 constexpr typename etl::remove_reference<T>::type&& move(T&& t) ETL_NOEXCEPT
55 return static_cast<typename etl::remove_reference<T>::type&&
>(t);
60 constexpr T&& forward(
typename etl::remove_reference<T>::type& t) ETL_NOEXCEPT
62 return static_cast<T&&
>(t);
66 constexpr T&& forward(
typename etl::remove_reference<T>::type&& t) ETL_NOEXCEPT
69 return static_cast<T&&
>(t);
82 template <
typename T,
typename U>
86 forward_like(U&& u) ETL_NOEXCEPT
88 return static_cast<const etl::remove_reference_t<U>&
>(u);
94 template <
typename T,
typename U>
98 forward_like(U&& u) ETL_NOEXCEPT
100 return static_cast<const etl::remove_reference_t<U>&&
>(u);
106 template <
typename T,
typename U>
110 forward_like(U&& u) ETL_NOEXCEPT
112 return static_cast<etl::remove_reference_t<U>&
>(u);
118 template <
typename T,
typename U>
122 forward_like(U&& u) ETL_NOEXCEPT
124 return static_cast<etl::remove_reference_t<U>&&
>(u);
130 template <
typename T,
typename U>
131 using forward_like_t =
decltype(etl::forward_like<T>(etl::declval<U&>()));
136#if ETL_NOT_USING_STL && !defined(ETL_IN_UNIT_TEST)
139 template <
typename T>
140 ETL_CONSTEXPR14
void swap(T& a, T& b) ETL_NOEXCEPT
147 template<
class T,
size_t N >
148 ETL_CONSTEXPR14
void swap(T(&a)[N], T(&b)[N]) ETL_NOEXCEPT
150 for (
size_t i = 0UL; i < N; ++i)
162 template <
typename T1,
typename T2>
187 ETL_CONSTEXPR14
pair(
const T1& a,
const T2& b)
197 template <
typename U1,
typename U2>
198 ETL_CONSTEXPR14
pair(U1&& a, U2&& b)
210 template <
typename U1,
typename U2>
226 template <
typename U1,
typename U2>
234#if defined(ETL_IN_UNIT_TEST) || ETL_USING_STL
236 template <
typename U1,
typename U2>
237 operator std::pair<U1, U2>()
243 template <
typename U1,
typename U2>
244 pair(
const std::pair<U1, U2>& other)
252 template <
typename U1,
typename U2>
253 pair(std::pair<U1, U2>&& other)
261 void swap(pair<T1, T2>& other)
263 using ETL_OR_STD::swap;
265 swap(
first, other.first);
266 swap(
second, other.second);
269 pair<T1, T2>& operator =(
const pair<T1, T2>& other)
277 template <
typename U1,
typename U2>
278 pair<U1, U2>& operator =(
const pair<U1, U2>& other)
287 pair<T1, T2>& operator =(pair<T1, T2>&& other)
289 first = etl::forward<T1>(other.first);
290 second = etl::forward<T2>(other.second);
295 template <
typename U1,
typename U2>
296 pair<U1, U2>& operator =(pair<U1, U2>&& other)
298 first = etl::forward<U1>(other.first);
299 second = etl::forward<U2>(other.second);
315 template <
typename T1,
typename T2>
316 inline pair<T1, T2>
make_pair(T1&& a, T2&& b)
318 return pair<T1, T2>(etl::forward<T1>(a), etl::forward<T2>(b));
321 template <
typename T1,
typename T2>
329 template <
typename T1,
typename T2>
330 inline void swap(pair<T1, T2>& a, pair<T1, T2>& b)
336 template <
typename T1,
typename T2>
343 template <
typename T1,
typename T2>
349 template <
typename T1,
typename T2>
350 inline bool operator <(
const pair<T1, T2>& a,
const pair<T1, T2>& b)
352 return (a.first < b.first) ||
353 (!(b.first < a.first) && (a.second < b.second));
357 template <
typename T1,
typename T2>
364 template <
typename T1,
typename T2>
371 template <
typename T1,
typename T2>
389 template <
typename TPair>
392 typedef typename TPair::first_type
type;
424 template <
typename TPair>
427 typedef typename TPair::second_type
type;
447#if ETL_NOT_USING_STL || ETL_CPP14_NOT_SUPPORTED
451 template <
typename T>
454 T old_value = object;
459 template <
typename T,
typename U>
460 T
exchange(T&
object,
const U& new_value)
462 T old_value = object;
470 template <
typename T,
typename U = T>
471 T
exchange(T&
object,
const U& new_value)
473 return std::exchange(
object, new_value);
480 template <
typename T>
490 template <
typename T, T... Integers>
491 class integer_sequence
497 typedef T value_type;
499 static ETL_CONSTEXPR
size_t size() ETL_NOEXCEPT
501 return sizeof...(Integers);
505 namespace private_integer_sequence
507 template <
size_t N,
typename IndexSeq>
508 struct make_index_sequence;
510 template <
size_t N,
size_t... Indices>
511 struct make_index_sequence<N,
etl::integer_sequence<size_t, Indices...>>
513 typedef typename make_index_sequence<N - 1, etl::integer_sequence<size_t, N - 1, Indices...>>::type type;
516 template <
size_t... Indices>
517 struct make_index_sequence<0,
etl::integer_sequence<size_t, Indices...>>
519 typedef etl::integer_sequence<size_t, Indices...> type;
525 using make_index_sequence =
typename private_integer_sequence::make_index_sequence<N, etl::integer_sequence<size_t>>::type;
528 template <
size_t... Indices>
529 using index_sequence = etl::integer_sequence<size_t, Indices...>;
535 template <
typename T>
552 return (lhs.x == rhs.x) && (lhs.y == rhs.y);
557 return !(lhs == rhs);
585 template <
typename T>
604 template <
typename TReturn,
typename... TParams>
612 constexpr functor(TReturn(*ptr_)(TParams...))
620 constexpr TReturn operator()(TParams... args)
const
622 return ptr(etl::forward<TParams>(args)...);
628 TReturn(*ptr)(TParams...);
637 template <
typename T>
638 class member_function_wrapper;
640 template <
typename TReturn,
typename... TParams>
641 class member_function_wrapper<TReturn(TParams...)>
645 template <
typename T, T& Instance, TReturn(T::* Method)(TParams...)>
646 static constexpr TReturn function(TParams... params)
648 return (Instance.*Method)(etl::forward<TParams>(params)...);
658 template <
typename T>
659 class functor_wrapper;
661 template <
typename TReturn,
typename... TParams>
662 class functor_wrapper<TReturn(TParams...)>
666 template <
typename TFunctor, TFunctor& Instance>
667 static constexpr TReturn function(TParams... params)
669 return Instance(etl::forward<TParams>(params)...);
is_integral
Definition: type_traits_generator.h:1001
is_lvalue_reference
Definition: type_traits_generator.h:1121
bitset_ext
Definition: absolute.h:38
pair< T1, T2 > make_pair(T1 a, T2 b)
A convenience wrapper for creating a pair from two objects.
Definition: utility.h:322
T exchange(T &object, const T &new_value)
exchange (const)
Definition: utility.h:452
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:684
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:696
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:645
void swap(etl::array< T, SIZE > &lhs, etl::array< T, SIZE > &rhs)
Template deduction guides.
Definition: array.h:621
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:633
etl::add_const< T >::type & as_const(T &t)
as_const
Definition: utility.h:481
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:657
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:672
integer_sequence
Definition: utility.h:537
Definition: utility.h:591
in_place disambiguation tags.
Definition: utility.h:570
Definition: utility.h:580
pair holds two objects of arbitrary type
Definition: utility.h:164
T1 first_type
first_type is the first bound type
Definition: utility.h:165
pair(const std::pair< U1, U2 > &other)
Constructing from std::pair.
Definition: utility.h:244
T1 first
first is a copy of the first object
Definition: utility.h:168
ETL_CONSTEXPR pair()
Default constructor.
Definition: utility.h:176
pair(const pair< T1, T2 > &other)
Copy constructor.
Definition: utility.h:218
T2 second
second is a copy of the second object
Definition: utility.h:169
T2 second_type
second_type is the second bound type
Definition: utility.h:166
Functor to select pair::first.
Definition: utility.h:391
type & operator()(TPair &p) const
Function call that return p.first.
Definition: utility.h:398
const type & operator()(const TPair &p) const
Function call that return p.first.
Definition: utility.h:406
TPair::first_type type
type of member pair::first.
Definition: utility.h:392
Functor to select pair::second.
Definition: utility.h:426
type & operator()(TPair &p) const
Function call. The return value is p.second.
Definition: utility.h:433
const type & operator()(const TPair &p) const
Function call. The return value is p.second.
Definition: utility.h:441
TPair::second_type type
type of member pair::second.
Definition: utility.h:427