More documentation updates

This commit is contained in:
John Wellbelove 2026-05-11 13:21:35 +01:00
parent 6fdfee41de
commit d69acc57b8
26 changed files with 2341 additions and 1563 deletions

View File

@ -0,0 +1,6 @@
---
title: "Views"
weight: 100
---
View like containers.

View File

@ -0,0 +1,291 @@
---
title: "multi_range"
---
A lightweight, chainable range system that simulates nested loops over multiple ranges, with customisable stepping and end conditions.
`etl::multi_range<T>` is a composable range-iteration helper that can chain multiple ranges to produce nested-loop style iteration. It lets you build “outer/inner” ranges and iterate across all combinations, while customizing stepping and termination logic.
Each range is defined as an `etl::multi_range` which may be linked to create nested multiple ranges.
```cpp
template <typename T>
class multi_range
```
All multi_range<T> classes derive from `imulti_range`.
By default, each call to next() will invoke either the forward_step or reverse_step types.
If the type is an arithmetic or pointer type then the default stepper will be automatically selected, dependent on the first and last parameters. If not, the default will be `forward_step`.
If a custom stepper for the type is required, then it may be defined in the constructor.
By default, each call to `completed()` will invoke `not_equal_compare` against the terminating range value. If a custom incrementor for the type is required, then it may be defined in the constructor.
## Types
`value_type`
The type of the range.
`const_reference`
The const reference type of the range.
---
`step_type`
Pure abstract base.
Inherit from this to define custom step functionality.
`forward_step`
A pre-defined step type that calls the type's `operator++()`.
This is the default step type if the type is arithmetic or random access iterator and the range is ascending, or the type is not an arithmetic or pointer.
`forward_step_by`
A pre-defined step type that calls the type's `operator+=()`.
The constructor requires the step value to add.
`reverse_step`
A pre-defined step type that calls the type's `operator--()`.
This is the default step type if the type is arithmetic or random access iterator and the range is descending.
`reverse_step_by`
A pre-defined step type that calls the type's `operator-=()`.
The constructor requires the step value to subtract.
---
`compare_type`
Pure abstract base.
Inherit from this to define custom compare functionality.
`not_equal_compare`
A pre-defined step type that calls etl::not_equal_to.
This is the default compare type.
`less_than_compare`
A pre-defined step type that calls `etl::less`.
`greater_than_compare`
A pre-defined step type that calls `etl::greater`.
## Constructor
```cpp
multi_range(value_type start,
value_type last)
```
**Description**
Initialises the loop where start is the initial value and last is the terminate value.
---
```cpp
multi_range(value_type first,
value_type last,
step_type& stepper)
```
**Description**
Initialises the loop where start is the initial value and last is the terminate value.
stepper will be called to increment the current range value.
---
```cpp
multi_range(value_type first,
value_type last,
compare_type& compare)
```
**Description**
Initialises the loop where start is the initial value and last is the terminate value.
compare will be called to compare with the terminating value.
---
```cpp
multi_range(value_type first,
value_type last,
step_type& stepper,
compare_type& compare)
```
**Description**
Initialises the loop where start is the initial value and last is the terminate value.
stepper will be called to increment the current range value.
compare will be called to compare with the terminate value.
## Modifiers
The nested ranges may be constructed in a variety of ways.
```cpp
imulti_range& append(imulti_range& inner_ranges)
```
**Description**
Appends inner loop(s) to the current range(s).
If the current range, **A**, is linked to ranges **B** & **C** in the order **A** -> **B** -> **C** and the new linked ranges are **D** -> **E**,
`A.append(D)` will result in **A** -> **B** -> **C** -> **D** -> **E**.
---
```cpp
imulti_range& insert(imulti_range& inner_ranges)
```
**Description**
Inserts inner range(s) after the current range.
If the current range, **A**, is linked to ranges **B** & **C** in the order **A** -> **B** -> **C** and the new linked ranges are **D** -> **E**,
`A.insert(D)` will result in **A** -> **D** -> **E** -> **B** -> **C**.
---
```cpp
void detach()
```
**Description**
Unlinks this range from its inner ranges.
---
```cpp
void detach_all()
```
**Description**
Unlinks this range and all its inner ranges from each other.
## Access
```cpp
const_reference value() const;
```
**Description**
Gets a const reference to the current value
---
```cpp
const_reference begin() const;
```
**Description**
Gets a const reference to the first value
---
```cpp
const_reference end() const;
```
**Description**
Gets a const reference to the terminate value
---
```cpp
bool completed() const
```
**Description**
Returns true if the range, and all of its inner ranges, have completed.
---
```cpp
size_t number_of_ranges() const
```
**Description**
Returns the number of linked ranges, starting from this.
For linked ranges **A** -> **B** -> **C** -> **D** -> **E**, `B.number_of_ranges()` returns `4`.
---
```cpp
size_t number_of_iterations()
```
**Description**
Returns the total number of iterations for all linked ranges, starting from this.
For linked ranges **A** -> **B** -> **C** -> **D** -> **E**, and a range size of `5` for each one,
`B.number_of_iterations()` returns `625` (`5 * 5 * 5 * 5`).
This function is not const as it must simulate the running of all of the nested ranges.
## Operations
```cpp
void start()
```
**Description**
Resets the range, and all its linked inner ranges to the starting conditions, with each range reset to its begin value.
---
```cpp
void next()
```
**Description**
Moves to the next iteration of the nested range.
---
## Example
```cpp
using Iterator = std::forward_list<std::string>::const_iterator;
// Less Than compare type
using LessThanCompare = etl::multi_range<const short*>::less_than_compare;
// Decrementing step type
using DecrementPtr = etl::multi_range<const short*>::reverse_step;
using Outer = etl::multi_range<int>; // Incrementing int
using Middle = etl::multi_range<const short*>; // Decrementing const short*
using Inner = etl::multi_range<Iterator>; // Incrementing const_iterator
const short data[4] = { 0, 1, 2, 3 };
std::forward_list<std::string> strings =
{
"zero", "one", "two", "three"
};
LessThanCompare lessThan;
DecrementPtr decrementPtr;
// Setup the loops.
Outer outer(0, 4, lessThan);
Middle middle(data + 3, data - 1, decrementPtr);
Inner inner(strings.begin(), strings.end());
outer.append(middle).append(inner);
size_t n_outer_loops = outer.number_of_loops(); // == 3
size_t n_middle_loops = middle.number_of_loops(); // == 2
size_t n_inner_loops = inner.number_of_loops(); // == 1
size_t n_outer_iterations = outer.number_of_iterations(); // == 64
size_t n_middle_iterations = middle.number_of_iterations(); // == 16
size_t n_inner_iterations = inner.number_of_iterations(); // == 4
// Create const references to the loop values.
const int& value_outer = outer.value();
const short*& value_middle = middle.value();
const Iterator& value_inner = inner.value();
// Iterate through the nested loops.
int i = 0;
for (outer.start(); !outer.completed(); outer.next())
{
std::cout << "Iteration " << i++ << " : "
<< "Outer = " << value_outer << " : "
<< "Middle = " << *value_middle << " : "
<< "Inner = " << *value_inner
<< "\n";
}
// Just iterate through the two nested loops.
i = 0;
for (middle.start(); !middle.completed(); middle.next())
{
std::cout << "Iteration " << i++ << " : "
<< "Middle = " << *value_middle << " : "
<< "Inner = " << *value_inner
<< "\n";
}
```

View File

@ -7,7 +7,9 @@ title: "visitor"
{{< /callout >}}
A set of template classes to enable the easy creation of objects using the Visitor pattern.
The purpose of these classes is to create a base classes with pure virtual functions for each supplied type.
Any derived class that tries to instantiate an object from it will then be forced to supply an overridden version for each and every function.
There are two templated classes; `visitor` and `visitable`.

View File

@ -1,207 +0,0 @@
Callback Timer Locked
A software timer class that can manage up to 254 timers. Each one may be repeating or single shot.
When a timer triggers it will call the selected function. The function may be a class member or free function.
The timers are driven from a call to tick(uint32_t count). This call would normally be made from a high priority interrupt routine. The destination function will receive the callback in the same context as the tick call.
The call to tick has a low overhead when a timer is not 'due'. Internally the timers are stored in 'first timeout' order so only the head of the list needs to be checked.
Each timer may have a period of up to 232-2 ticks (4,294,967,294).
At 1ms per tick this would equate to just over 49 days.
Defines the following classes:-
etl::icallback_timer_locked
etl::callback_timer_locked
The access to the timers is controlled by three external functions, supplied to the timer by the
member function set_locks.
The three delegate parameters are:-
Try Lock Attempts to set the lock. Returns true if successful, otherwise false.
Lock Sets the lock.
Unlock Resets the lock.
Uses definitions from timer.h
Important:
For correct operation of the timer framework, the routine that calls tick must not be pre-emptible by another routine that calls a timer function. Also, calls to the timer framework may only be made from the caller of tick and one other, lower priority, thread of execution
____________________________________________________________________________________________________
icallback_timer_locked
The base class for all timer controllers.
Type definitions
callback_type etl::delegate<void(void)>
The function type used for callbacks.
try_lock_type etl::delegate<bool(void)>
The function type used for 'try lock'.
lock_type etl::delegate<void(void)>
The function type used for 'lock'.
unlock_type etl::delegate<void(void)>
The function type used for 'unlock'.
____________________________________________________________________________________________________
Member functions
etl::timer::id::type register_timer(callback_type callback),
uint32_t period,
bool repeating)
Registers a timer calling a free or static function.
callback A delegate to the callback free funtion that will be callled when the timer expires.
period The timer period in ticks.
repeating false if single shot, true if repeating.
Returns the allocated timer id or etl::timer::mode::NO_TIMER if one was not available.
____________________________________________________________________________________________________
bool unregister_timer(etl::timer::id::type id)
Unregisters a timer.
If the timer is active then it will be stopped.
Returns true if a timer with the id was successfully unregistered.
___________________________________________________________________________________________________
void enable(bool state)
Enables or disables the timer manager according to the state.
____________________________________________________________________________________________________
bool is_running() const
Returns true if the timer manager is enabled.
____________________________________________________________________________________________________
void clear()
Clears the callback timer back to the initial state. All timers will be stopped and unregistered.
____________________________________________________________________________________________________
bool tick(uint32_t count)
This function updates the internal tick counter (if enabled) and must pass the number of ticks that have occurred since the last call. If the count encompasses more than one period of a repeating timer then the timer will be triggered multiple times in one call to tick.
Returns true if the tick counter was updated, otherwise false. This may be used by the calling routine to accumulate unprocessed tick counts.
____________________________________________________________________________________________________
bool start(etl::timer::id::type id, bool immediate = false)
Starts the timer with the specified id.
If the timer is already running then the timer Is restarted from the current tick count.
If immediate is true then the timer is triggered on the next call to tick(). Note: Single shot timers will only trigger once.
If the id does not correspond to a registered timer then returns false.
____________________________________________________________________________________________________
bool stop(etl::timer::id::type id)
Stops the timer with the specified id.
Does nothing if the timer is already stopped.
if the id does not correspond to a registered timer then returns false.
____________________________________________________________________________________________________
bool set_period(etl::timer::id::type id, uint32_t period)
Stops the timer with the specified id.
Sets a new timer period.
Returns true if successful.
____________________________________________________________________________________________________
bool set_mode(etl::timer::id::type id, bool repeating)
Stops the timer with the specified id.
Sets a new timer mode.
Returns true if successful.
____________________________________________________________________________________________________
void set_locks(try_lock_type try_lock_, lock_type lock_, lock_type unlock_)
Sets the try-lock, lock and unlock delegates.
____________________________________________________________________________________________________
etl::timer::id::type time_to_next()
Returns the time to the next timeout.
20.38.0
____________________________________________________________________________________________________
Constants
MAX_TIMERS
The maximum number of timers that can be handled.
____________________________________________________________________________________________________
callback_timer_locked
Template parameters
MAX_TIMERS The number of timers to be supported. The maximum number is 254.
A value of 255 will result in a compile error.
callback_timer_locked()
Default construct.
The lock callback delegates are not set.
____________________________________________________________________________________________________
callback_timer_locked(try_lock_type try_lock, lock_type lock, unlock_type unlock)
Construct from lock callback delegates.
____________________________________________________________________________________________________
Example
//***************************************************************************
// Class callback via etl::function
//***************************************************************************
class Test
{
public:
Test()
: ticks(0)
{
}
void callback()
{
++ticks;
}
int ticks;
};
using callback_type = etl::icallback_timer_atomic::callback_type;
callback_type member_callback = callback_type::create<Test, test, &Test::callback> member_callback;
//***************************************************************************
// Free function callback via etl::function
//***************************************************************************
int free_ticks1 = 0;
void free_callback1()
{
++free_ticks;
}
callback_type free_callback1 = callback_type::create<free_function_callback>();
//***************************************************************************
// Timer controller.
//***************************************************************************
etl::callback_timer<2> timer_controller;
//***************************************************************************
// The main loop.
//***************************************************************************
int main()
{
etl::timer::id::type id1 = timer_controller.register_timer(member_callback,
1000,
etl::timer::mode::SINGLE_SHOT);
etl::timer::id::type id2 = timer_controller.register_timer(free_function_callback,
100,
etl::timer::mode::REPEATING);
timer_controller.start(id1);
timer_controller.start(id2);
timer_controller.start(id3);
timer_controller.enable(true);
// Start timer interrupts here.
while (true)
{
// Loop forever.
}
return 0;
}
//***************************************************************************
// The interrupt timer callback.
//***************************************************************************
void timer_interrupt()
{
const uint32_t TICK = 1;
static uint32_t nticks = TICK;
if (timer_controller.tick(nticks))
{
nticks = TICK;
}
else
{
nticks += TICK;
}
}

View File

@ -1,79 +0,0 @@
Type List
Defines a tuple of types, but unlike a tuple, does not contain any values.
This is an empty class.
Valid for C++11 and above.
____________________________________________________________________________________________________
type_list
etl::type_select<typename... TTypes>
Creates a tuple of types from a set of template type parameters.
____________________________________________________________________________________________________
Member types
index_sequence_type
The index_sequence type for this type_list.
____________________________________________________________________________________________________
Type list creation
____________________________________________________________________________________________________
Using global types
template <typename TTypeList, size_t... Indices>
type_list_select
Defines a new type_list by selecting types from a given type_list, according to an index sequence.
____________________________________________________________________________________________________
template <typename... TTypeLists>
type_list_cat
Defines a new type list by concatenating a list of etl::type_list objects.
std::tuple style access.
____________________________________________________________________________________________________
Type list properties
____________________________________________________________________________________________________
Using member types
static constexpr size_t size();
Returns the number of types in the type list.
____________________________________________________________________________________________________
Using global types
template <typename TTypelist>
type_list_size
Defines value as the size of the type list.
tuple style access.
template <typename TTypelist>
type_list_size_v C++17 and above
____________________________________________________________________________________________________
etl::nth_type<size_t N, typename TTypeList>
Defines the nth type in the type list.
____________________________________________________________________________________________________
template <typename TFromList, typename TToList>
type_lists_are_convertible
Checks that types in a type_list are convertible to the type in another.
Defines value as true or false.
20.43.0
template <typename TFromList, typename TToList>
type_lists_are_convertible_v C++17 and above
20.43.0
____________________________________________________________________________________________________
Examples
using TypeList1 = etl::type_list<char, short, int, long>
using TypeList2 = etl::type_list<float, double>
using TypeList3 = etl::type_list<unsigned char, unsigned short>
____________________________________________________________________________________________________
Using member types
// Get the size of TypeList1
constexpr size_t typeList1Size = TypeList1::size();
____________________________________________________________________________________________________
Using tuple style global types
// Get the size of TypeList1
constexpr size_t typeList1Size = etl::type_list_size_v<TypeList1>;
// Define the type list
// etl::type_list<char, short, int, long, float, double, unsigned char, unsigned short>
using Concatenated = etl::type_list_cat<TypeList1, TypeList2, TypeList3>

View File

@ -1,366 +0,0 @@
Utility
A few useful utility functions and classes.
____________________________________________________________________________________________________
pair
template <typename T1, typename T2>
struct pair
A clone of std::pair
C++03
template <typename T1, typename T2>
pair<T1, T2> make_pair(T1 a, T2 b)
C++11 and above
template <typename T1, typename T2>
pair<T1, T2> make_pair(T1&& a, T2&& b)
Returns a pair.
____________________________________________________________________________________________________
template <size_t Index, typename T1, typename T2>
struct tuple_element<Index, ETL_OR_STD::pair<T1, T2>>
Specialisation for pair.
Gets the type in the pair at Index.
Static asserts if Index is not 0 or 1.
20.40.1
template <typename T1, typename T2>
struct tuple_size<ETL_OR_STD::pair<T1, T2>>
Specialisation for pair.
Gets the size of the pair, which is always 2.
20.40.1
____________________________________________________________________________________________________
Template deduction guides
C++17 and above
template <typename T1, typename T2>
pair(T1, T2) ->pair<T1, T2>;
____________________________________________________________________________________________________
exchange
template <typename T, typename U = T>
T exchange(T& object, const U& new_value)
Copies the new value to object and returns the old value.
Note: This is not an atomic operation.
__________________________________________________________________________________________________
add_const
template <typename T>
typename etl::add_const<T>::type& as_const(T& t)
Returns a value of type T as a const T.
__________________________________________________________________________________________________
coordinate_2d
template <typename T>
struct coordinate_2d
Member types
T x;
T y;
__________________________________________________________________________________________________
In_place disambiguation tags.
struct in_place_t
inline constexpr in_place_t in_place{}; // C++17
____________________________________________________________________________________________________
template <typename T> struct in_place_type_t
template <typename T>
inline constexpr in_place_type_t<T> in_place_type{}; // C++17
____________________________________________________________________________________________________
template <size_t I> struct in_place_index_t
template <size_t I>
inline constexpr in_place_index_t<I> in_place_index{}; // C++17
__________________________________________________________________________________________________
declval
template <typename T>
typename etl::add_rvalue_reference<T>::type declval() ETL_NOEXCEPT;
C++11
__________________________________________________________________________________________________
functor
For C++11 and above.
20.27.0
template <typename TReturn, typename... TParams>
class functor
Wraps a free/global function in a functor.
____________________________________________________________________________________________________
constexpr functor(TReturn(*ptr_)(TParams...))
Constructs a functor from a function pointer.
____________________________________________________________________________________________________
constexpr TReturn operator()(TParams... args) const
Function operator.
Calls the wrapped function with the forwarded parameters.
____________________________________________________________________________________________________
Example
void int Function(int i)
{
return i;
}
// Note that the functor deduces the template parameters.
constexpr etl::functor f(Function);
__________________________________________________________________________________________________
member_function_wrapper
For C++11 and above.
20.27.0
template <typename TReturn, typename... TParams>
class member_function_wrapper<TReturn(TParams...)>
Wraps a member function in a static member function.
____________________________________________________________________________________________________
template <typename T, T& Instance, TReturn(T::* Method)(TParams...)>
static constexpr TReturn function(TParams... params)
The static function that calls the member function.
____________________________________________________________________________________________________
Example
class MyClass
{
public:
int MemberFunction(int i)
{
return 2 * i;
}
};
MyClass test;
constexpr int(*pf)(int)
= &etl::member_function_wrapper<int(int)>::function<MyClass, test, &MyClass::MemberFunction>;
// Call
int result = pf(1);
__________________________________________________________________________________________________
functor_wrapper
For C++11 and above.
20.27.0
template <typename TReturn, typename... TParams>
class functor_wrapper<TReturn(TParams...)>
Wraps a functor in a static member function.
____________________________________________________________________________________________________
template <typename TFunctor, TFunctor& Instance>
static constexpr TReturn function(TParams... params)
The static function that calls the member function.
____________________________________________________________________________________________________
Example
class MyClass
{
public:
int operator()(int i)
{
return 2 * i;
}
};
MyClass test;
constexpr int(*pf)(int) = &etl::functor_wrapper<int(int)>::function<MyClass, test>;
// Call
int result = pf(1);
__________________________________________________________________________________________________
functor_as_static
For C++17 and above.
20.40.0
Wraps a functor with a static free function at compile time.
Creates a static member 'call' that calls the specified functor.
template <auto& Instance>
struct functor_as_static
____________________________________________________________________________________________________
template <typename... TArgs>
static constexpr auto call(TArgs&&... args)
Member static function that calls the functor
____________________________________________________________________________________________________
Example
struct Test
{
int operator()(int i)
{
return 2 * i;
}
};
Test test;
using fas_t = etl::functor_as_static<test>;
fas_t::call(1));
__________________________________________________________________________________________________
member_function_as_static
For C++17 and above.
20.40.0
Wraps a member function with a static free function at compile time.
Creates a static member function that calls the specified member function.
template <auto Method, auto& Instance>
struct member_function_as_static
____________________________________________________________________________________________________
template <typename... TArgs>
static constexpr auto call(TArgs&&... args)
Member static function that calls the member function.
____________________________________________________________________________________________________
Example
struct Test
{
int Function()(int i)
{
return 2 * i;
}
};
Test test;
using mfas_t = etl::functor_as_static<&Test::Function, test>;
mfas_t::call(1));
__________________________________________________________________________________________________
member_function_as_functor
For C++17 and above.
20.40.0
Wraps a member function with a functor at compile time.
Creates a functor that calls the specified member function.
template <auto Method, auto& Instance>
class member_function_as_functor
template <typename... TArgs>
constexpr auto operator()(TArgs&&... args) const
Calls the functor.
____________________________________________________________________________________________________
Example
struct Test
{
int Function()(int i)
{
return 2 * i;
}
};
constexpr etl::member_function_as_functor<&Test::Function, test> mfaf;
mfaf(1);
__________________________________________________________________________________________________
function_as_functor
For C++17 and above.
20.40.0
Wraps a function with a functor at compile time.
Creates a functor that calls the specified free function.
template <auto Function>
class function_as_functor
____________________________________________________________________________________________________
constexpr auto operator()(TArgs&&... args) const
Calls the functor.
____________________________________________________________________________________________________
Example
int Function()(int i)
{
return 2 * i;
}
constexpr etl::function_as_functor<Function> faf;
faf(1);
__________________________________________________________________________________________________
function_ptr_as_functor
For C++11 and above.
20.40.0
Wraps a function pointer with a functor at run time.
Creates a functor that calls the specified free function.
template <typename TReturn, typename... TArgs>
class function_ptr_as_functor
____________________________________________________________________________________________________
constexpr function_ptr_as_functor(TReturn(*ptr_)(TArgs...))
Construct from a function pointer.
____________________________________________________________________________________________________
constexpr TReturn operator()(TArgs... args) const
Function operator.
____________________________________________________________________________________________________
Example
int Function()(int i)
{
return 2 * i;
}
using function_type = decltype(Function);
constexpr function_type* fptr = Function;
constexpr etl::function_ptr_as_functor<function_type> fpaf(fptr)
__________________________________________________________________________________________________
integer_sequence
20.14.0
template <typename T, T... Integers>
class integer_sequence
__________________________________________________________________________________________________
index_sequence
20.14.0
template <size_t... Indices>
using index_sequence = etl::integer_sequence<size_t, Indices...>;
template <size_t N>
make_index_sequence
__________________________________________________________________________________________________
select1st
select2nd
select1st is a functor object that takes a single argument, a pair, and returns the pair::first element.
select2nd is a functor object that takes a single argument, a pair, and returns the pair::second element.
____________________________________________________________________________________________________
size_of_type
20.36.0
template <typename T>
ETL_CONSTEXPR size_t size_of_type()
Returns the size of the type defined in T.
____________________________________________________________________________________________________
template <typename T>
ETL_CONSTEXPR size_t size_of_type(const T&)
Returns the size of the type defined in T.
____________________________________________________________________________________________________
ETL_SIZE_OF_OBJECT_TYPE(Object, Type)
Returns the size of Type defined in the declared type of Object.
C++11 and above
20.36.0
ETL_SIZE_OF_CLASS_TYPE(Class, Type)
Returns the size of Type defined in Class.
20.36.0
____________________________________________________________________________________________________
nontype_t
20.43.0
Wraps a non-type template parameter as a type.
Defines a value associated with the template type.
If ETL_FORCE_CPP11_NONTYPE is defined then the C++14 and below variant is used.
C++14 and below
template <typename T, T Value>
struct nontype_t;
using FortyTwo = etl::nontype_t<int, 42>;
C++17 and above
template <auto Value>
struct nontype_t;
using FortyTwo = etl::nontype_t<42>

View File

@ -1,29 +0,0 @@
---
title: "Versions"
---
As set of macros that allow the version of the ETL to be determined.
## Definitions
```cpp
ETL_VERSION
ETL_VERSION_W
ETL_VERSION_U16
ETL_VERSION_U32
ETL_VERSION_MAJOR
ETL_VERSION_MINOR
ETL_VERSION_PATCH
ETL_VERSION_VALUE
```
## Example values
```cpp
#define ETL_VERSION "10.21.2"
#define ETL_VERSION_W L"10.21.2"
#define ETL_VERSION_U16 u"10.21.2"
#define ETL_VERSION_U32 U"10.21.2"
#define ETL_VERSION_MAJOR 10
#define ETL_VERSION_MINOR 21
#define ETL_VERSION_PATCH 2
#define ETL_VERSION_VALUE 102102
```

View File

@ -1,31 +0,0 @@
instance_count
Inherit from this class to count instances of a class.
<20.25.0
etl::instance_count<typename T>
This class is not thread safe.
20.25.0
etl::instance_count<typename T, typename TCounter = uint32_t>
This class is not thread safe unless TCounter is an atomic type.
____________________________________________________________________________________________________
Types
type The type being counted.
counter_type The type used for the counter.
____________________________________________________________________________________________________
Member functions
static const counter_type& get_instance_count()
Returns a const reference to the current count.
____________________________________________________________________________________________________
static void reset_instance_count()
Resets the count to zero.
____________________________________________________________________________________________________
Example
Instances of My_Class will be counted and can be accessed by the inherited member function get_instance_count().
class My_Class : public etl::instance_count<My_Class, std::atomic_uint8_t>
{
};

View File

@ -1,5 +0,0 @@
limits
An emulation of <limits> under the etl namespace
See https://en.cppreference.com/w/cpp/types/numeric_limits

View File

@ -1,209 +0,0 @@
multi_range
Allows the creation of simulated nested ranges at runtime.
Each range is defined as an etl::multi_range which may be linked to create nested multiple ranges.
template <typename T>
class multi_range
All multi_range<T> classes derive from imulti_range
By default, each call to next() will invoke either the forward_step or reverse_step types.
If the type is an arithmetic or pointer type then the default stepper will be automatically selected, dependent on the first and last parameters. If not, the default will be forward_step.
If a custom stepper for the type is required, then it may be defined in the constructor.
By default, each call to completed() will invoke not_equal_compare against the terminating range value. If a custom incrementor for the type is required, then it may be defined in the constructor.
____________________________________________________________________________________________________
Types
value_type
The type of the range.
const_reference
The const reference type of the range.
____________________________________________________________________________________________________
step_type
Pure abstract base.
Inherit from this to define custom step functionality.
forward_step
A pre-defined step type that calls the type's operator++().
This is the default step type if the type is arithmetic or random access iterator and the range is ascending, or the type is
not an arithmetic or pointer.
forward_step_by
A pre-defined step type that calls the type's operator+=().
The constructor requires the step value to add.
reverse_step
A pre-defined step type that calls the type's operator--().
This is the default step type if the type is arithmetic or random access iterator and the range is descending.
reverse_step_by
A pre-defined step type that calls the type's operator-=().
The constructor requires the step value to subtract.
____________________________________________________________________________________________________
compare_type
Pure abstract base.
Inherit from this to define custom compare functionality.
not_equal_compare
A pre-defined step type that calls etl::not_equal_to.
This is the default compare type.
less_than_compare
A pre-defined step type that calls etl::less.
greater_than_compare
A pre-defined step type that calls etl::greater.
____________________________________________________________________________________________________
Constructor
multi_range(value_type start,
value_type last)
Initialises the loop where start is the initial value and last is the terminate value.
____________________________________________________________________________________________________
multi_range(value_type first,
value_type last,
step_type& stepper)
Initialises the loop where start is the initial value and last is the terminate value.
stepper will be called to increment the current range value.
____________________________________________________________________________________________________
multi_range(value_type first,
value_type last,
compare_type& compare)
Initialises the loop where start is the initial value and last is the terminate value.
compare will be called to compare with the terminating value.
____________________________________________________________________________________________________
multi_range(value_type first,
value_type last,
step_type& stepper,
compare_type& compare)
Initialises the loop where start is the initial value and last is the terminate value.
stepper will be called to increment the current range value.
compare will be called to compare with the terminate value.
____________________________________________________________________________________________________
Modifiers
The nested ranges may be constructed in a variety of ways.
imulti_range& append(imulti_range& inner_ranges)
Appends inner loop(s) to the current range(s).
If the current range, A, is linked to ranges B & C in the order A -> B -> C and the new linked ranges are D -> E,
A.append(D) will result in A -> B -> C -> D -> E
____________________________________________________________________________________________________
imulti_range& insert(imulti_range& inner_ranges)
Inserts inner range(s) after the current range.
If the current range, A, is linked to ranges B & C in the order A -> B -> C and the new linked ranges are D -> E,
A.insert(D) will result in A -> D -> E -> B -> C
____________________________________________________________________________________________________
void detach()
Unlinks this range from its inner ranges.
____________________________________________________________________________________________________
void detach_all()
Unlinks this range and all its inner ranges from each other.
____________________________________________________________________________________________________
Access
const_reference value() const;
Gets a const reference to the current value
____________________________________________________________________________________________________
const_reference begin() const;
Gets a const reference to the first value
____________________________________________________________________________________________________
const_reference end() const;
Gets a const reference to the terminate value
____________________________________________________________________________________________________
bool completed() const
Returns true if the range, and all of its inner ranges, have completed.
____________________________________________________________________________________________________
size_t number_of_ranges() const
Returns the number of linked ranges, starting from this.
For linked ranges A -> B -> C -> D -> E,
B.number_of_ranges() returns 4.
____________________________________________________________________________________________________
size_t number_of_iterations()
Returns the total number of iterations for all linked ranges, starting from this.
For linked ranges A -> B -> C -> D -> E, and a range size of 5 for each one,
B.number_of_iterations() returns 625 (5 * 5 * 5 * 5).
This function is not const as it must simulate the running of all of the nested ranges.
____________________________________________________________________________________________________
Operations
void start()
Resets the range, and all its linked inner ranges to the starting conditions, with each range reset to its begin value.
____________________________________________________________________________________________________
void next()
Moves to the next iteration of the nested range.
____________________________________________________________________________________________________
Example
using Iterator = std::forward_list<std::string>::const_iterator;
// Less Than compare type
using LessThanCompare = etl::multi_range<const short*>::less_than_compare;
// Decrementing step type
using DecrementPtr = etl::multi_range<const short*>::reverse_step;
using Outer = etl::multi_range<int>; // Incrementing int
using Middle = etl::multi_range<const short*>; // Decrementing const short*
using Inner = etl::multi_range<Iterator>; // Incrementing const_iterator
const short data[4] = { 0, 1, 2, 3 };
std::forward_list<std::string> strings =
{
"zero", "one", "two", "three"
};
LessThanCompare lessThan;
DecrementPtr decrementPtr;
// Setup the loops.
Outer outer(0, 4, lessThan);
Middle middle(data + 3, data - 1, decrementPtr);
Inner inner(strings.begin(), strings.end());
outer.append(middle).append(inner);
size_t n_outer_loops = outer.number_of_loops(); // == 3
size_t n_middle_loops = middle.number_of_loops(); // == 2
size_t n_inner_loops = inner.number_of_loops(); // == 1
size_t n_outer_iterations = outer.number_of_iterations(); // == 64
size_t n_middle_iterations = middle.number_of_iterations(); // == 16
size_t n_inner_iterations = inner.number_of_iterations(); // == 4
// Create const references to the loop values.
const int& value_outer = outer.value();
const short*& value_middle = middle.value();
const Iterator& value_inner = inner.value();
// Iterate through the nested loops.
int i = 0;
for (outer.start(); !outer.completed(); outer.next())
{
std::cout << "Iteration " << i++ << " : "
<< "Outer = " << value_outer << " : "
<< "Middle = " << *value_middle << " : "
<< "Inner = " << *value_inner
<< "\n";
}
// Just iterate through the two nested loops.
i = 0;
for (middle.start(); !middle.completed(); middle.next())
{
std::cout << "Iteration " << i++ << " : "
<< "Middle = " << *value_middle << " : "
<< "Inner = " << *value_inner
<< "\n";
}

View File

@ -1,372 +0,0 @@
type_traits
Reverse engineered types traits classes from C++11 plus several ETL extensions.
This file is generated from type_traits_generator.h. See Generators
Not all traits have been defined as some rely on compiler intrinsics that are not available on all compiler platforms.
See type_traits for more information
integral_constant
remove_reference
add_reference
remove_pointer
add_pointer
is_const
remove_const
add_const
is_volatile
remove_volatile
add_volatile
remove_cv
add_cv
add_volatile
remove_cvref 20.17.0
is_integral
is_signed
is_unsigned
is_floating_point
is_same
is_void
is_arithmetic
is_fundamental
is_compound
is_array
is_pointer
is_reference
is_base_of
make_signed
make_unsigned
enable_if
conditional
extent
remove_extent
remove_all_extents
rank
decay
alignment_of
conjunction 20.14.0
disjunction 20.14.0
negation
is_lvalue_assignable
void_t 20.28.0
declvar 20.28.0
common_type
is_enum 20.30.0 C++11
underlying_type 20.42.0
Unless the ETL is set to use builtins, the user must specialise the templte for their enumerations.
The definitions will wrap those defined in C++11's <type_traits> if available.
____________________________________________________________________________________________________
The following will be defined according to the C++ standard and user defined macros.
is_assignable
is_constructible
is_copy_constructible
is_move_constructible
is_trivially_constructible
is_trivially_copy_constructible
is_trivially_destructible
is_trivially_copy_assignable
is_trivially_copyable
____________________________________________________________________________________________________
Scenario: Using C++11 or above and the STL.
If ETL_CPP11_SUPPORTED and ETL_USING_STL == 1 and !defined(ETL_USE_TYPE_TRAITS_BUILTINS)
and !defined(ETL_USER_DEFINED_TYPE_TRAITS) and ((!defined(ARDUINO) && ETL_NOT_USING_STLPORT) or defined(ETL_GCC_V5_TYPE_TRAITS_SUPPORTED))
The ETL's definitions wrap the STL definitions, except in the following case.
if ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED is not defined then they will be defined as in the ETL_USER_DEFINED_TYPE_TRAITS option.
____________________________________________________________________________________________________
Scenario: Not using the STL but the compiler has type trait built-ins.
If the user has defined ETL_USE_TYPE_TRAITS_BUILTINS then the ETL will use the generally available compiler built-ins.
This option is useful for when you are not using the STL, but are using a compatible compiler.
____________________________________________________________________________________________________
Scenario: Not using the STL and have the compiler has no type trait built-ins.
If the user has defined ETL_USER_DEFINED_TYPE_TRAITS then the ETL will define these type traits for arithmetic and pointer types only. For all other types the traits will be undefined, unless the user explicitly specialises them.
struct Copyable
{
Copyable() {}
Copyable(const Copyable& other) {}
Copyable& operator =(const Copyable& rhs) { return *this; }
Copyable(Copyable&& other) = delete;
Copyable& operator =(Copyable& rhs) = delete;
};
using etl::is_assignable;
using etl::is_constructible;
using etl::is_copy_constructible;
using etl::is_move_constructible;
template <>
struct etl::is_assignable<Copyable, Copyable> : public etl::true_type
{
};
template <>
struct etl::is_constructible<Copyable> : public etl::true_type
{
};
template <>
struct etl::is_copy_constructible<Copyable> : public etl::true_type
{
};
template <>
struct etl::is_move_constructible<Copyable> : public etl::false_type
{
};
____________________________________________________________________________________________________
Scenario: Not using the STL, the compiler has no type trait built-ins, and no user define specialisations are defined.
The ETL will define these type traits as true for arithmetic and pointer types only. For all other types the traits will have a value of false.
____________________________________________________________________________________________________
is_one_of
ETL extension
C++03
template <typename T,
typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
struct is_one_of
By default the ETL allows up the 16 types. This may be changed by running the type traits generator.
See Generators
____________________________________________________________________________________________________
C++11 or above
template <typename T, typename... TTypelist>
struct is_one_of
____________________________________________________________________________________________________
Members
value
Set to true if the first template type is one of the subsequent types, otherwise false.
If C++17 is supported then this definition available
template <typename T>
constexpr bool is_one_of_v = etl::is_one_of<T, TRest...>::value;
____________________________________________________________________________________________________
Example
bool isOK;
isOK = etl::is_one_of<int, char, short, int, long>::value; // Sets 'isOK' to true.
isOK = etl::is_one_of<double, char, short, int, long>::value; // Sets 'isOK' to false.
____________________________________________________________________________________________________
are_all_same
ETL extension
C++11 or above
template <typename T, typename... TTypelist>
struct are_all_same
____________________________________________________________________________________________________
Members
value
Set to true if all of the template types are the same, otherwise false.
If C++17 is supported then this definition available
template <typename T>
constexpr bool are_all_same_v = etl::is_one_of<T, TRest...>::value;
____________________________________________________________________________________________________
Example
bool isOK;
isOK = etl::are_all_same<int, int, int, int>::value; // Sets 'isOK' to true.
isOK = etl::is_one_of<int, int, char, int>::value; // Sets 'isOK' to false.
____________________________________________________________________________________________________
conditional_integral_constant
ETL extension
Members
value
Set to the constant determined by the condition.
____________________________________________________________________________________________________
Example
int value;
value = etl::conditional_integral_constant<true, 1, 2>::value; // Sets value to 1
value = etl::conditional_integral_constant<false, 1, 2>::value; // Sets value to 2
____________________________________________________________________________________________________
types
ETL extension
Extracts the basic types from a template type.
____________________________________________________________________________________________________
type
The underlying type.
____________________________________________________________________________________________________
reference
A reference to the underlying type.
____________________________________________________________________________________________________
const_reference
A const reference to the underlying type.
____________________________________________________________________________________________________
pointer
A pointer to the underlying type.
____________________________________________________________________________________________________
const_pointer
A const pointer to the underlying type.
____________________________________________________________________________________________________
Example
typedef const int* const MyType;
etl::types<MyType>::type int
etl::types<MyType>::reference int&
etl::types<MyType>::const_reference const int&
etl::types<MyType>::pointer int*
etl::types<MyType>::const_pointer const int*
etl::types<MyType>::const_pointer_const const int* const
____________________________________________________________________________________________________
unsigned_type
ETL extension
20.29.0
template <typename T>
struct unsigned_type
Defines one of five unsigned types that has the same size as T.
Defines one of unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long.
____________________________________________________________________________________________________
template <typename T>
using unsigned_type_t = typename unsigned_type<T>::type;
C++11
____________________________________________________________________________________________________
signed_type
ETL extension
20.29.0
template <typename T>
struct signed_type
Defines one of five signed types that has the same size as T.
Defines one of char, short, int, long, long long.
____________________________________________________________________________________________________
template <typename T>
using signed_type_t = typename signed_type<T>::type;
C++11
____________________________________________________________________________________________________
has_duplicates
ETL extension
20.39.1
C++11 or above
template <typename... TTypes>
struct has_duplicates
____________________________________________________________________________________________________
Members
value
Set to true if the typelist TTypes contains any duplicate types, otherwise false.
____________________________________________________________________________________________________
If C++17 is supported then this definition is available
template <typname... TTypes>
constexpr bool has_duplicates_v = etl::has_duplicates<TTypes...>::value;
____________________________________________________________________________________________________
has_duplicates_of
ETL extension
20.39.1
C++11 or above
template <typename T, typename... TTypes>
struct has_duplicates_of
____________________________________________________________________________________________________
Members
value
Set to true if the typelist TTypes contains duplicates of types T, otherwise false.
____________________________________________________________________________________________________
If C++17 is supported then this definition is available
template <typename T, typname... TTypes>
constexpr bool has_duplicates_of_v = etl::has_duplicates_of<T, TTypes...>::value;
____________________________________________________________________________________________________
count_of
ETL extension
20.39.1
C++11 or above
template <typename T, typename... TTypes>
struct count_of
____________________________________________________________________________________________________
Members
value
The count of the occurences of type T in the typelist TTypes.
____________________________________________________________________________________________________
If C++17 is supported then this definition is available
template <typename T, typname... TTypes>
constexpr bool count_of_v = etl::count_of<T, TTypes...>::value;
____________________________________________________________________________________________________
conjunction
20.40.1
template <typename... Types>
struct conjunction;
Forms the logical conjunction (AND) of Types...
The result is found in the member value.
template <typename... Types>
inline constexpr bool conjunction_v;
Forms the logical conjunction (AND) of Types...
C++17
____________________________________________________________________________________________________
disjunction
20.40.1
template <typename... Types>
struct disjunction;
Forms the logical disjunction (OR) of Types...
The result is found in the member value.
template <typename... Types>
inline constexpr bool disjunction_v;
Forms the logical disjunction (OR) of Types...
C++17
____________________________________________________________________________________________________
exclusive_disjunction
20.40.1
template <typename... Types>
struct exclusive_disjunction;
Forms the logical exclusive disjunction (XOR) of Types...
The result is found in the member value.
template <typename... Types>
inline constexpr bool exclusive_disjunction_v;
Forms the logical exclusive disjunction (XOR) of Types...
C++17
____________________________________________________________________________________________________
unwrap_reference
unwrap_ref_decay
20.40.1
template <class T>
struct unwrap_reference;
Unwraps any etl::reference_wrapper, changing etl::reference_wrapper<U> to U&.
If T is a specialisation of etl::reference_wrapper, unwraps it, otherwise T remains the same.
template <typename T>
using unwrap_reference_t;
C++11
____________________________________________________________________________________________________
template <typename T>
struct unwrap_ref_decay;
Unwraps any etl::reference_wrapper, changing etl::reference_wrapper<U> to U&.
If decayed T is a specialisation of etl::reference_wrapper, unwraps it, otherwise T is decayed.
template <typename T>
using unwrap_ref_decay_t;
C++11
____________________________________________________________________________________________________
is_specialization
20.41.0
template <typename T, template <typename...> class Template>
struct is_specialization
Checks if T is a specialization of template type Template.
The result is found in the member value.
C++11
template <typename T, template <typename...> class Template>
inline constexpr bool is_specialization_v = etl::is_specialization<T, Template>::value;
C++17

View File

@ -1,163 +1,250 @@
tuple
---
title: "tuple"
---
{{< callout type="info">}}
Header: `tuple.h`
Since: `20.41.0`
Similar to: `std::tuple`
{{< /callout >}}
A fixed-size collection of heterogeneous values.
20.41.0
A fixed-size collection of heterogeneous values.
STL equivalent: std::tuple
Adds additional functionality to std::tuple.
```cpp
etl::tuple<typename... Types>
____________________________________________________________________________________________________
Template deduction guides
C++17 and above
```
Template deduction guide from variadic arguments.
## Template deduction guides
C++17 and above.
**Template deduction guide from variadic arguments.**
```cpp
template <typename... TArgs>
tuple(TArgs... args) -> tuple<TArgs...>;
```
Template deduction guide from pair.
**Template deduction guide from pair.**
```cpp
template <typename T1, typename T2>
tuple(ETL_OR_STD::pair<T1, T2>) -> tuple<T1, T2>;
```
Example
**Example**
```cpp
etl::tuple tp(1, 2.2, 3, std::string("4"));
```
Equivalent to:
Equivalent to:
```cpp
etl::tuple<int, double, int, std::string> t(1, 2.2, 3, std::string("4"));
____________________________________________________________________________________________________
Make tuple
```
## Make tuple
```cpp
template <typename... Types>
ETL_NODISCARD
ETL_CONSTEXPR14
etl::tuple<etl::unwrap_ref_decay_t<Types>...> make_tuple(Types&&... args)
```
Example
**Example**
```cpp
auto t = etl::make_tuple(1, 2.2, 3, std::string("4"));
```
Equivalent to:
Equivalent to:
```cpp
etl::tuple<int, double, int, std::string> t(1, 2.2, 3, std::string("4"));
____________________________________________________________________________________________________
Member types
```
value_type The first type contained by this tuple.
this_type The type of this tuple.
base_type The type of the base tuple to this tuple. This is a tuple of all types except for the first.
index_sequence_type The index_sequence type for this tuple.
____________________________________________________________________________________________________
Constructor
---
Default or copy constructs each element.
Can be initialised like a C array.
## Member types
`value_type`
&emsp; The first type contained by this tuple.
`this_type`
&emsp; The type of this tuple.
`base_type`
&emsp; The type of the base tuple to this tuple. This is a tuple of all types except for the first.
`index_sequence_type`
&emsp; The index_sequence type for this tuple.
## Constructor
Default or copy constructs each element.
Can be initialised like a C array.
```cpp
etl::array<int, 10> data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
____________________________________________________________________________________________________
Access
---
### Access
```cpp
template <size_t Index, typename Tuple>
etl::tuple_element;
____________________________________________________________________________________________________
Capacity
```
## Capacity
```cpp
template <typename Tuple>
struct tuple_size;
____________________________________________________________________________________________________
ETL Extensions
```
## ETL Extensions
```cpp
template <typename T>
struct is_tuple
If T is a tuple etl::is_tuple is defined as etl::true_type, otherwise etl::false_type.
____________________________________________________________________________________________________
Specialisations of STL to allow the use of C++ structured bindings.
```
If `T` is a `tuple` then `etl::is_tuple` is defined as `etl::true_type`, otherwise `etl::false_type`.
### Specialisations of STL to allow the use of C++ structured bindings.
```cpp
template <typename... Types>
struct tuple_size<etl::tuple<Types...>>
Specialisation of tuple_size to allow the use of C++ structured bindings.
Declared in namespace std.
```
Specialisation of tuple_size to allow the use of C++ structured bindings.
Declared in namespace `std`.
```cpp
template <size_t Index, typename... Types>
struct tuple_element<Index, etl::tuple<Types...>>
Specialisation of tuple_element to allow the use of C++ structured bindings.
Declared in namespace std.
____________________________________________________________________________________________________
Convert an etl::tuple to a std::tuple
```
Specialisation of `tuple_element` to allow the use of C++ structured bindings.
Declared in namespace `std`.
### Convert an `etl::tuple` to a `std::tuple`
```cpp
template <typename... Types>
ETL_NODISCARD
ETL_CONSTEXPR14
auto to_std(const etl::tuple<Types...>& etl_tuple)
Converts an etl::tuple to a std::tuple.
```
Converts an `etl::tuple` to a `std::tuple`.
Enabled when STL is available.
---
```cpp
template <typename... Types>
ETL_NODISCARD
ETL_CONSTEXPR14
auto to_std(etl::tuple<Types...>&& etl_tuple)
Converts an etl::tuple to a std::tuple.
```
Converts an `etl::tuple` to a `std::tuple`.
Enabled when STL is available.
____________________________________________________________________________________________________
Convert an std::tuple to a etl::tuple
### Convert an std::tuple to a etl::tuple
```cpp
template <typename... Types>
ETL_NODISCARD
ETL_CONSTEXPR14
auto to_etl(const std::tuple<Types...>& std_tuple)
Converts a std::tuple to an etl::tuple.
```
Converts a `std::tuple` to an `etl::tuple`.
Enabled when STL is available.
---
```cpp
template <typename... Types>
ETL_NODISCARD
ETL_CONSTEXPR14
auto to_etl(std::tuple<Types...>&& std_tuple)
Converts a std::tuple to an etl::tuple.
```
Converts a `std::tuple` to an `etl::tuple`.
Enabled when STL is available.
____________________________________________________________________________________________________
Create a tuple from selected elements of another
### Create a tuple from selected elements of another
```cpp
template <typename Tuple, size_t... Indices>
ETL_NODISCARD
ETL_CONSTEXPR14
auto select_from_tuple(Tuple&& tuple, etl::index_sequence<Indices...>)
Creates a new tuple by selecting elements from another, given a run time index sequence.
```
Creates a new tuple by selecting elements from another, given a run time index sequence.
Static asserts if the number of indices does not match the tuple size.
---
```cpp
template <size_t... Indices, typename Tuple>
ETL_NODISCARD
ETL_CONSTEXPR14
auto select_from_tuple(Tuple&& tuple)
Creates a new tuple by selecting elements from another, given a template parameter index sequence.
```
Creates a new tuple by selecting elements from another, given a template parameter index sequence.
Static asserts if the number of indices does not match the tuple size.
____________________________________________________________________________________________________
Non-member functions
## Non-member functions
```cpp
template <size_t Index, typename... Types>
ETL_CONSTEXPR14
etl::tuple_element_t<Index, etl::tuple<Types...>>& get(tuple<Types...>&);
```
---
```cpp
template <size_t Index, typename... Types>
ETL_CONSTEXPR14
etl::tuple_element_t<Index, etl::tuple<Types...>>&& get(tuple<Types...>&&);
```
---
```cpp
template <size_t Index, typename... Types>
ETL_CONSTEXPR14
const etl::tuple_element_t<Index, etl::tuple<Types...>>& get(const tuple<Types...>&);
```
---
```cpp
template <size_t Index, typename... Types>
ETL_CONSTEXPR14
const etl::tuple_element_t<Index, etl::tuple<Types...>>&& get(const tuple<Types...>&&);
```
---
```cpp
template <typename T, typename... Types>
ETL_CONSTEXPR14
T& get(tuple<Types...>&);
```
---
```cpp
template <typename T, typename... Types>
ETL_CONSTEXPR14
T&& get(tuple<Types...>&&);
```
---
```cpp
template <typename T, typename... Types>
ETL_CONSTEXPR14
const T& get(const tuple<Types...>&);
```
---
```cpp
template <typename T, typename... Types>
ETL_CONSTEXPR14
const T&& get(const tuple<Types...>&&);
```

117
docs/types/type-list.md Normal file
View File

@ -0,0 +1,117 @@
---
title: "type_list"
---
{{< callout type="info">}}
Header: `type_list.h`
Since: `20.39.5`
{{< /callout >}}
Defines a tuple of types, but unlike a tuple, does not contain any values.
This is an empty class.
Valid for C++11 and above.
## type_list
```cpp
etl::type_select<typename... TTypes>
```
Creates a tuple of types from a set of template type parameters.
### Member types
index_sequence_type
The index_sequence type for this type_list.
### Type list creation
**Using global types**
```cpp
template <typename TTypeList, size_t... Indices>
type_list_select
```
Defines a new type_list by selecting types from a given type_list, according to an index sequence.
---
```cpp
template <typename... TTypeLists>
type_list_cat
```
Defines a new type list by concatenating a list of `etl::type_list` objects.
`std::tuple` style access.
## Type list properties
### Using member types
```cpp
static constexpr size_t size();
```
Returns the number of types in the type list.
### Using global types
```cpp
template <typename TTypelist>
type_list_size
```
Defines value as the size of the type list.
tuple style access.
```cpp
template <typename TTypelist>
type_list_size_v
```
C++17 and above.
---
```cpp
etl::nth_type<size_t N, typename TTypeList>
```
Defines the nth type in the type list.
---
```cpp
template <typename TFromList, typename TToList>
type_lists_are_convertible
```
Checks that types in a type_list are convertible to the type in another.
Defines value as `true` or `false`.
Since: `20.43.0`
---
```cpp
template <typename TFromList, typename TToList>
type_lists_are_convertible_v
```
C++17 and above.
Since: `20.43.0`
## Examples
```cpp
using TypeList1 = etl::type_list<char, short, int, long>
using TypeList2 = etl::type_list<float, double>
using TypeList3 = etl::type_list<unsigned char, unsigned short>
```
### Using member types
```cpp
// Get the size of TypeList1
constexpr size_t typeList1Size = TypeList1::size();
```
### Using tuple style global types
```cpp
// Get the size of TypeList1
constexpr size_t typeList1Size = etl::type_list_size_v<TypeList1>;
// Define the type list
// etl::type_list<char, short, int, long, float, double, unsigned char, unsigned short>
using Concatenated = etl::type_list_cat<TypeList1, TypeList2, TypeList3>
```

View File

@ -1,98 +1,139 @@
Type Lookup
Compile time mapping of id to type, type to id and type to type.
This file is generated from type_lookup_generator.h and can be created by running generate_type_lookup.bat.
---
title: "type-lookup"
---
For a less complex solution for simple id to type lookup, see etl::type_select.
____________________________________________________________________________________________________
type_id_pair
Support structure for type_id_lookup.
{{< callout type="info">}}
Header: `type_lookup.h`
{{< /callout >}}
Compile time mapping of id to type, type to id and type to type.
This file is generated from `type_lookup_generator.h` and can be created by running `generate_type_lookup.bat`.
For a less complex solution for simple id to type lookup, see `etl::type_select`.
## type_id_pair
Support structure for `type_id_lookup`.
```cpp
etl::type_id_pair<typename T, size_t ID>
Defines:
type The type.
ID The id associated with the type.
____________________________________________________________________________________________________
type_type_pair
Support structure for type_type_lookup.
```
**Defines**
`type` The type.
`ID` The id associated with the type.
## type_type_pair
Support structure for `type_type_lookup`.
```cpp
etl::type_type_pair<typename T1, typename T2>
```
Defines:
type1 The indexing type.
type2 The associated type.
____________________________________________________________________________________________________
type_id_lookup
Creates a class for compile time id to type and type to id mappings.
**Defines**
`type1` The indexing type.
`type2` The associated type.
## type_id_lookup
Creates a class for compile time id to type and type to id mappings.
```cpp
etl::type_id_lookup<typename T1, ...>
The number of types that can be handled is determined by the generator.
Each template parameter is a type_id_pair.
```
The number of types that can be handled is determined by the generator.
Each template parameter is a `type_id_pair`.
The class contains two nested templates
____________________________________________________________________________________________________
type_from_id
---
The class contains two nested templates.
### type_from_id
Gets the type from the id.
```cpp
type_from_id<size_t ID>
```
Defines:
type The associated type.
**Defines**
`type` The associated type.
C++14 and above
**C++14 and above**
```cpp
template <int ID>
using type_from_id_t = typename type_from_id<ID>::type;
____________________________________________________________________________________________________
id_from_type
Gets the id from the type.
id_from_type<typename T>
```
Defines:
### id_from_type
```cpp
id_from_type<typename T>
```
Gets the id from the type.
**Defines**
ID The associated id.
C++ 17 and above
**C++ 17 and above**
```cpp
template <typename T>
constexpr size_t id_from_type_v = id_from_type<T>::value;
____________________________________________________________________________________________________
Static functions
Gets the id from the type.
```
## Static functions
```cpp
template <typename T>
static unsigned int get_id_from_type(const T&)
```
Gets the id from the type.
```cpp
template <typename T>
static unsigned int get_id_from_type()
____________________________________________________________________________________________________
type_type_lookup
Creates a class for compile time type to type mapping.
```
Gets the id from the type.
## type_type_lookup
Creates a class for compile time type to type mapping.
```cpp
etl::type_id_lookup<typename T1, ...>
The number of types that can be handled is determined by the generator.
Each template parameter is a type_id_pair.
```
The number of types that can be handled is determined by the generator.
Each template parameter is a `type_id_pair`.
---
The class contains one nested template.
____________________________________________________________________________________________________
type_from_type
### type_from_type
```cpp
type_from_type<typename T>
```
Defines:
type The associated type.
**Defines**
`type` The associated type.
C++14 and above
**C++14 and above**
```cpp
template <typename T>
using type_from_type_t = typename type_from_type<T>::type;
____________________________________________________________________________________________________
nth_type
Gets the nth type in a variadic type list.
```
## nth_type
Gets the nth type in a variadic type list.
```cpp
template <size_t N, typename... TTypes>
struct nth_type
```
Defines member type as the nth type in the variadic type list.
```cpp
template <size_t N, typename... TTypes>
using nth_type_t = typename nth_type<N, TTypes...>::type;
```
Type alias defined as the nth type in the variadic type list.
____________________________________________________________________________________________________
Examples
____________________________________________________________________________________________________
type_id_lookup
## Examples
```cpp
enum
{
INT32 = 32,
@ -131,7 +172,7 @@ TypeIdLookup::id_from_type_v<std::string>
// Compile error
TypeIdLookup::id_from_type_v<double>
____________________________________________________________________________________________________
---
type_type_lookup
// Get the next larger type.
typedef etl::type_type_pair<int16_t, int32_t> TypeInt16;
@ -152,4 +193,4 @@ typename TypeTypeLookup::type_from_type_t<float>
// Compile error
typename TypeTypeLookup::type_from_type_t<int32_t>
```

View File

@ -1,30 +1,40 @@
Type Select
Compile time mapping of id to type. When etl::type_lookup is OTT.
Type ids must be sequential from zero.
---
title: "type_select"
---
This file is generated from type_select_generator.h and can be created by running generate_type_select.bat.
____________________________________________________________________________________________________
type_select
Compile time mapping of id to type. When etl::type_lookup is OTT.
Type ids must be sequential from zero.
Creates a class for compile time id to type.
This file is generated from `type_select_generator.h` and can be created by running `generate_type_select.bat`.
## type_select
Creates a class for compile time id to type.
```cpp
etl::type_select<typename T1, ...>
```
The number of types that can be handled is determined by the generator.
The class contains a nested template.
The number of types that can be handled is determined by the generator.
The class contains a nested template.
select
Gets the type from the id.
### select
Gets the type from the id.
```cpp
select<const size_t ID>
```
Defines:
type The associated type.
**Defines**
`type` The associated type.
C++14 and above
**C++14 and above**
```cpp
template <size_t ID>
using select_t = typename select<ID>::type;
____________________________________________________________________________________________________
Examples
```
## Examples
```cpp
enum
{
INT32 = 0,
@ -47,4 +57,4 @@ typename Types::select_t<STRING>
// Compile error
typename Types::select_t<OTHER>
```

461
docs/types/type-traits.md Normal file
View File

@ -0,0 +1,461 @@
---
title: "type_traits"
---
Reverse engineered types traits classes from C++11 plus several ETL extensions.
This file is generated from type_traits_generator.h. See Generators
Not all traits have been defined as some rely on compiler intrinsics that are not available on all compiler platforms.
`integral_constant`
`remove_reference`
`add_reference`
`remove_pointer`
`add_pointer`
`is_const`
`remove_const`
`add_const`
`is_volatile`
`remove_volatile`
`add_volatile`
`remove_cv`
`add_cv`
`add_volatile`
`remove_cvref` `20.17.0`
`is_integral`
`is_signed`
`is_unsigned`
`is_floating_point`
`is_same`
`is_void`
`is_arithmetic`
`is_fundamental`
`is_compound`
`is_array`
`is_pointer`
`is_reference`
`is_base_of`
`make_signed`
`make_unsigned`
`enable_if`
`conditional`
`extent`
`remove_extent`
`remove_all_extents`
`rank`
`decay`
`alignment_of`
`conjunction` `20.14.0`
`disjunction` `20.14.0`
`negation`
`is_lvalue_assignable`
`void_t` `20.28.0`
`declvar` `20.28.0`
`common_type`
`is_enum` `20.30.0`
`underlying_type` `20.42.0`
&emsp;Unless the ETL is set to use builtins, the user must specialise the template for their enumerations.
The definitions will wrap those defined in C++11's `<type_traits>` if available.
---
The following will be defined according to the C++ standard and user defined macros.
`is_assignable`
`is_constructible`
`is_copy_constructible`
`is_move_constructible`
`is_trivially_constructible`
`is_trivially_copy_constructible`
`is_trivially_destructible`
`is_trivially_copy_assignable`
`is_trivially_copyable`
## Scenario 1
**Using C++11 or above and the STL.**
If `ETL_CPP11_SUPPORTED and ETL_USING_STL == 1` and `!defined(ETL_USE_TYPE_TRAITS_BUILTINS)`
and `!defined(ETL_USER_DEFINED_TYPE_TRAITS)` and `((!defined(ARDUINO) && ETL_NOT_USING_STLPORT)` or `defined(ETL_GCC_V5_TYPE_TRAITS_SUPPORTED))`
The ETL's definitions wrap the STL definitions, except in the following case.
if `ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED` is not defined then they will be defined as in the `ETL_USER_DEFINED_TYPE_TRAITS` option.
## Scenario 2
**Not using the STL but the compiler has type trait built-ins.**
If the user has defined `ETL_USE_TYPE_TRAITS_BUILTINS` then the ETL will use the generally available compiler built-ins.
This option is useful for when you are not using the STL, but are using a compatible compiler.
## Scenario 3
**Not using the STL and have the compiler has no type trait built-ins.**
If the user has defined `ETL_USER_DEFINED_TYPE_TRAITS` then the ETL will define these type traits for arithmetic and pointer types only. For all other types the traits will be undefined, unless the user explicitly specialises them.
```cpp
struct Copyable
{
Copyable() {}
Copyable(const Copyable& other) {}
Copyable& operator =(const Copyable& rhs) { return *this; }
Copyable(Copyable&& other) = delete;
Copyable& operator =(Copyable& rhs) = delete;
};
using etl::is_assignable;
using etl::is_constructible;
using etl::is_copy_constructible;
using etl::is_move_constructible;
template <>
struct etl::is_assignable<Copyable, Copyable> : public etl::true_type
{
};
template <>
struct etl::is_constructible<Copyable> : public etl::true_type
{
};
template <>
struct etl::is_copy_constructible<Copyable> : public etl::true_type
{
};
template <>
struct etl::is_move_constructible<Copyable> : public etl::false_type
{
};
```
## Scenario 4
**Not using the STL, the compiler has no type trait built-ins, and no user define specialisations are defined.**
The ETL will define these type traits as `true` for arithmetic and pointer types only. For all other types the traits will have a value of `false`.
## is_one_of
**ETL extension**
**C++03**
```cpp
template <typename T,
typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
struct is_one_of
```
By default the ETL allows up the 16 types. This may be changed by running the type traits generator.
**C++11 or above**
```cpp
template <typename T, typename... TTypelist>
struct is_one_of
```
### Members
`value`
Set to `true` if the first template type is one of the subsequent types, otherwise `false`.
If C++17 is supported then this definition available.
```cpp
template <typename T>
constexpr bool is_one_of_v = etl::is_one_of<T, TRest...>::value;
```
**Example**
```cpp
bool isOK;
isOK = etl::is_one_of<int, char, short, int, long>::value; // Sets 'isOK' to true.
isOK = etl::is_one_of<double, char, short, int, long>::value; // Sets 'isOK' to false.
```
## are_all_same
**ETL extension**
C++11 or above
```cpp
template <typename T, typename... TTypelist>
struct are_all_same
```
### Members
`value`
Set to `true` if all of the template types are the same, otherwise `false`.
If C++17 is supported then this definition available.
```cpp
template <typename T>
constexpr bool are_all_same_v = etl::is_one_of<T, TRest...>::value;
```
**Example**
```cpp
bool isOK;
isOK = etl::are_all_same<int, int, int, int>::value; // Sets 'isOK' to true.
isOK = etl::is_one_of<int, int, char, int>::value; // Sets 'isOK' to false.
```
## conditional_integral_constant
**ETL extension**
### Members
`value`
Set to the constant determined by the condition.
**Example**
int value;
value = etl::conditional_integral_constant<true, 1, 2>::value; // Sets value to 1
value = etl::conditional_integral_constant<false, 1, 2>::value; // Sets value to 2
## types
**ETL extension**
Extracts the basic types from a template type.
`type`
The underlying type.
---
`reference`
A reference to the underlying type.
---
`const_reference`
A const reference to the underlying type.
---
`pointer`
A pointer to the underlying type.
---
```cpp
const_pointer
```
A const pointer to the underlying type.
---
**Example**
```cpp
typedef const int* const MyType;
etl::types<MyType>::type int
etl::types<MyType>::reference int&
etl::types<MyType>::const_reference const int&
etl::types<MyType>::pointer int*
etl::types<MyType>::const_pointer const int*
etl::types<MyType>::const_pointer_const const int* const
```
## unsigned_type
**ETL extension**
Since: `20.29.0`
```cpp
template <typename T>
struct unsigned_type
```
Defines one of five unsigned types that has the same size as `T`.
Defines one of `unsigned char`, `unsigned short`, `unsigned int`, `unsigned long`, `unsigned long long`.
---
```cpp
template <typename T>
using unsigned_type_t = typename unsigned_type<T>::type;
```
C++11
## signed_type
**ETL extension**
Since: `20.29.0`
```cpp
template <typename T>
struct signed_type
```
Defines one of five signed types that has the same size as `T`.
Defines one of `char`, `short`, `int`, `long`, `long long`.
---
```cpp
template <typename T>
using signed_type_t = typename signed_type<T>::type;
```
C++11
---
## has_duplicates
**ETL extension**
```cpp
template <typename... TTypes>
struct has_duplicates
```
Since: `20.39.1`
C++11 or above
### Members
`value`
Set to `true` if the typelist `TTypes` contains any duplicate types, otherwise `false`.
---
If C++17 is supported then this definition is available
```cpp
template <typname... TTypes>
constexpr bool has_duplicates_v = etl::has_duplicates<TTypes...>::value;
```
## has_duplicates_of
**ETL extension**
```cpp
template <typename T, typename... TTypes>
struct has_duplicates_of
```
Since: `20.39.1`
C++11 or above
### Members
`value`
Set to `true` if the typelist `TTypes` contains duplicates of types `T`, otherwise `false`.
---
If C++17 is supported then this definition is available.
```cpp
template <typename T, typname... TTypes>
constexpr bool has_duplicates_of_v = etl::has_duplicates_of<T, TTypes...>::value;
```
## count_of
**ETL extension**
```cpp
template <typename T, typename... TTypes>
struct count_of
```
Since: `20.39.1`
C++11 or above
### Members
`value`
The count of the occurrences of type `T` in the typelist `TTypes`.
---
If C++17 is supported then this definition is available.
```cpp
template <typename T, typname... TTypes>
constexpr bool count_of_v = etl::count_of<T, TTypes...>::value;
```
## conjunction
Since: `20.40.1`
```cpp
template <typename... Types>
struct conjunction;
```
Forms the logical conjunction (AND) of `Types...`
The result is found in the member `value`.
```cpp
template <typename... Types>
inline constexpr bool conjunction_v;
```
Forms the logical conjunction (AND) of `Types...`
C++17
## disjunction
Since: `20.40.1`
```cpp
template <typename... Types>
struct disjunction;
```
Forms the logical disjunction (OR) of `Types...`
The result is found in the member `value`.
```cpp
template <typename... Types>
inline constexpr bool disjunction_v;
```
Forms the logical disjunction (OR) of `Types...`
C++17
## exclusive_disjunction
Since: `20.40.1`
```cpp
template <typename... Types>
struct exclusive_disjunction;
```
Forms the logical exclusive disjunction (XOR) of `Types...`
The result is found in the member `value`.
```cpp
template <typename... Types>
inline constexpr bool exclusive_disjunction_v;
```
Forms the logical exclusive disjunction (XOR) of `Types...`
C++17
## unwrap_reference, unwrap_ref_decay
Since: `20.40.1`
```cpp
template <class T>
struct unwrap_reference;
```
Unwraps any `etl::reference_wrapper`, changing `etl::reference_wrapper<U>` to `U&`.
If `T` is a specialisation of `etl::reference_wrapper`, unwraps it, otherwise `T` remains the same.
```cpp
template <typename T>
using unwrap_reference_t;
```
C++11
---
```cpp
template <typename T>
struct unwrap_ref_decay;
```
Unwraps any `etl::reference_wrapper`, changing `etl::reference_wrapper<U>` to `U&`.
If decayed `T` is a specialisation of `etl::reference_wrapper`, unwraps it, otherwise `T` is decayed.
```cpp
template <typename T>
using unwrap_ref_decay_t;
```
C++11
## is_specialization
Since: `20.41.0`
```cpp
template <typename T, template <typename...> class Template>
struct is_specialization
```
Checks if `T` is a specialization of template type `Template`.
The result is found in the member `value`.
C++11
```cpp
template <typename T, template <typename...> class Template>
inline constexpr bool is_specialization_v = etl::is_specialization<T, Template>::value;
```
C++17

View File

@ -1,14 +1,22 @@
type_def
Typesafe typedefs
---
title: "type_def"
---
A method of declaring types that are strongly typesafe.
Avoids the problem of inadvertently mixing different typedef'd types.
{{< callout type="info">}}
Header: `type_def.h`
{{< /callout >}}
etl::type_def is noexcept from 20.42.0
________________________________________________________________________________________________
The problem
Typdefs do not give you a lot of type safety, allowing the following runtime errors to occur.
Typesafe typedefs.
A method of declaring types that are strongly type safe.
Avoids the problem of inadvertently mixing different typedef'd types.
`etl::type_def` is `noexcept` since 20.42.0
## The problem
Standard typdefs do not give you a lot of type safety, allowing the following runtime errors to occur.
```cpp
typedef int event_t;
typedef int action_t;
@ -28,10 +36,12 @@ event_t event = 1;
action_t action = 2;
DoEvent(action, event); // Oops! Runtime error. :-(
________________________________________________________________________________________________
The solution
```
## The solution
ETL typedefs are strongly typed and will not allow the errors above to be compiled.
```cpp
#include "type_def.h"
ETL_TYPEDEF(int, event_t);
@ -53,13 +63,14 @@ event_t event = 1; // Implicit construction from underlying type.
action_t action = 2; // Implicit construction from underlying type.
DoEvent(action, event); // Compile time error. :-)
```
The class defines two class types; value_type which represents the underlying type and id_type that represents the typedef unique type id.
The class defines two class types; `value_type` which represents the underlying type and `id_type` that represents the typedef unique type id.
The class defines all of the operators that the underlying type may be expected to support.
Also the class defines two get() member functions that return a const or non-const reference to the internal value, for data binding purposes.
Also the class defines two `get()` member functions that return a const or non-const reference to the internal value, for data binding purposes.
```cpp
T& get()
```
```cpp
const T& get() const
```

View File

@ -1,28 +1,47 @@
unaligned_type
20.23.0
A wrapper for fundamental types around unaligned internal storage.
Allows big and little endian storage.
---
title: "unaligned_type"
---
20.40.0
Marked as 'packed' for MSVC, GCC amd Clang.
{{< callout type="info">}}
Header: `unaligned_type.h`
Since: `20.23.0`
{{< /callout >}}
A wrapper for fundamental types around unaligned internal storage.
Allows big and little endian storage.
Marked as `packed` for MSVC, GCC amd Clang.
```cpp
template <typename T, int Endian>
class unaligned_type
```
Where Endian is etl::endian::big or etl::endian::little.
____________________________________________________________________________________________________
For C++11 or above
Where `Endian` is `etl::endian::big` or `etl::endian::little`.
---
**For C++11 or above**
```cpp
template <typename T, int Endian>
using unaligned_type_t = typename etl::unaligned_type<T, Endian>::type;
____________________________________________________________________________________________________
For C++17 or above
```
---
**For C++17 or above**
```cpp
template <typename T, int Endian>
constexpr size_t unaligned_type_v = etl::unaligned_type<T, Endian>::Size;
____________________________________________________________________________________________________
The following types are predefined.
Host order
Only defined if ETL_ENDIANNESS_IS_CONSTEXPR
```
---
The following types are predefined.
## Host order
Only defined if `ETL_ENDIANNESS_IS_CONSTEXPR`.
```cpp
host_char_t
host_schar_t
host_uchar_t
@ -45,9 +64,9 @@ host_uint64_t ETL_USING_64BIT_TYPES
host_float_t
host_double_t
host_long_double_t
____________________________________________________________________________________________________
Little Endian
```
## Little Endian
```cpp
le_char_t
le_schar_t
le_uchar_t
@ -70,9 +89,9 @@ le_uint64_t ETL_USING_64BIT_TYPES
le_float_t
le_double_t
le_long_double_t
____________________________________________________________________________________________________
Big Endian
```
## Big Endian
```cpp
be_char_t
be_schar_t
be_uchar_t
@ -95,10 +114,10 @@ be_uint64_t ETL_USING_64BIT_TYPES
be_float_t
be_double_t
be_long_double_t
____________________________________________________________________________________________________
Network Order
```
## Network Order
Synonym for Big Endian
```cpp
using net_char_t = be_char_t
using net_schar_t = be_schar_t
using net_uchar_t = be_uchar_t
@ -121,120 +140,268 @@ using net_uint64_t = be_uint64_t ETL_USING_64BIT_TYPES
using net_float_t = be_float_t
using net_double_t = be_double_t
using net_long_double_t = be_long_double_t
____________________________________________________________________________________________________
Constants
int Endian The endianness of the type.
size_t Size The size, in char, of the type.
____________________________________________________________________________________________________
Constructors
```
## Constants
`int Endian`
&emsp;The endianness of the type.
`size_t Size`
&emsp;The size, in `char`, of the type.
## Constructors
```cpp
ETL_CONSTEXPR unaligned_type()
Constructs an uninitialised unaligned_type.
____________________________________________________________________________________________________
```
**Description**
Constructs an uninitialised `unaligned_type`.
---
```cpp
unaligned_type(T value)
```
**Description**
Constructs with the supplied value.
____________________________________________________________________________________________________
---
```cpp
template <int Endian_Other>
unaligned_type(const unaligned_type<T, Endian_Other>& other)
```
**Description**
Constructs from another unaligned_type.
The endianness is converted, if necessary.
____________________________________________________________________________________________________
Member types
## Member types
```cpp
using pointer = char*;
using const_pointer = const char*;
using iterator = char*;
using const_iterator = const char*;
using reverse_iterator = etl::reverse_iterator<iterator>;
using const_reverse_iterator = etl::reverse_iterator<const_iterator>;
____________________________________________________________________________________________________
Member functions
```
## Member functions
```cpp
pointer data()
```
**Description**
Pointer to the beginning of the storage.
---
```cpp
ETL_CONSTEXPR14 const_pointer data() const
```
**Description**
Const pointer to the beginning of the storage.
____________________________________________________________________________________________________
---
```cpp
ETL_CONSTEXPR14 size_t size() const
```
**Description**
Size of the storage.
____________________________________________________________________________________________________
---
```cpp
iterator begin()
```
**Description**
Iterator to the beginning of the storage.
---
```cpp
ETL_CONSTEXPR14 const_iterator begin() const
```
**Description**
Const iterator to the beginning of the storage.
---
```cpp
ETL_CONSTEXPR14 const_iterator cbegin() const
```
**Description**
Const iterator to the beginning of the storage.
____________________________________________________________________________________________________
---
```cpp
reverse_iterator rbegin()
```
**Description**
Reverse iterator to the beginning of the storage.
---
```cpp
ETL_CONSTEXPR14 const_reverse_iterator rbegin() const
```
**Description**
Const reverse iterator to the beginning of the storage.
---
```cpp
ETL_CONSTEXPR14 const_reverse_iterator crbegin() const
```
**Description**
Const reverse iterator to the beginning of the storage.
____________________________________________________________________________________________________
---
```cpp
iterator end()
```
**Description**
Iterator to the end of the storage.
---
```cpp
ETL_CONSTEXPR14 const_iterator end() const
```
**Description**
Const iterator to the end of the storage.
---
```cpp
ETL_CONSTEXPR14 const_iterator cend() const
```
**Description**
Const iterator to the end of the storage.
____________________________________________________________________________________________________
---
```cpp
reverse_iterator rend()
```
**Description**
Reverse iterator to the end of the storage.
---
```cpp
ETL_CONSTEXPR14 const_reverse_iterator rend() const
```
**Description**
Const reverse iterator to the end of the storage.
---
```cpp
ETL_CONSTEXPR14 const_reverse_iterator crend() const
```
**Description**
Const reverse iterator to the end of the storage.
____________________________________________________________________________________________________
---
```cpp
char& operator[](int i)
```
**Description**
Index operator.
---
```cpp
ETL_CONSTEXPR14 const char& operator[](int i) const
```
**Description**
Const index operator.
____________________________________________________________________________________________________
---
```cpp
ETL_CONSTEXPR14 unaligned_type& operator =(T value)
```
**Description**
Assignment operator.
____________________________________________________________________________________________________
---
```cpp
ETL_CONSTEXPR14 operator T() const
```
**Description**
Conversion operator.
____________________________________________________________________________________________________
---
```cpp
ETL_CONSTEXPR14 T value() const
```
**Description**
Gets the value.
____________________________________________________________________________________________________
---
```cpp
template <int Endian_Other>
ETL_CONSTEXPR14 unaligned_type& operator =(const unaligned_type<T, Endian_Other>& other)
```
**Description**
Assignment operator from other endianness.
____________________________________________________________________________________________________
---
```cpp
ETL_CONSTEXPR14 bool operator ==(const unaligned_type& lhs, const unaligned_type& rhs)
Equality operator.
Removed 20.39.3
```
**Description**
Equality operator.
Removed: `20.39.3`
---
```cpp
ETL_CONSTEXPR14 bool operator ==(const unaligned_type& lhs, T rhs)
Equality operator.
Removed 20.39.3
```
**Description**
Equality operator.
Removed: `20.39.3`
---
```cpp
ETL_CONSTEXPR14 bool operator ==(T lhs, const unaligned_type& rhs)
Equality operator.
Removed 20.39.3
____________________________________________________________________________________________________
```
**Description**
Equality operator.
Removed: `20.39.3`
---
```cpp
ETL_CONSTEXPR14 bool operator !=(const unaligned_type& lhs, T rhs)
Inequality operator.
Removed 20.39.3
```
**Description**
Inequality operator.
Removed: `20.39.3`
---
```cpp
ETL_CONSTEXPR14 bool operator !=(const unaligned_type& lhs, const unaligned_type& rhs)
Inequality operator.
Removed 20.39.3
```
**Description**
Inequality operator.
Removed: `20.39.3`
---
```cpp
ETL_CONSTEXPR14 bool operator !=(T lhs, const unaligned_type& rhs)
Inequality operator.
Removed 20.39.3
```
**Description**
Inequality operator.
Removed: `20.39.3`

View File

@ -1,10 +1,14 @@
user_type
A strong typedef with constants.
---
title: "user_type"
---
A method of declaring a strong typedef, like type_def, but with a set of constants, like enum_type.
Unlike enum types, a user type may be set to arbitrary values.
A strong typedef with constants.
Example
A method of declaring a strong `typedef`, like `etl::type_def`, but with a set of constants, like `enum_type`.
Unlike enum types, a user type may be set to arbitrary values.
**Example**
```cpp
ETL_DECLARE_USER_TYPE(CompassDirection, int)
ETL_USER_TYPE(North, 0)
ETL_USER_TYPE(South, 180)
@ -21,4 +25,4 @@ direction = CompassDirection(3); // Explicit conversion from an arbitrary va
++direction; // Modify.
direction += CompassDirection::THIRTY_DEGREES;
direction = value; // **** Compilation error ****
```

View File

@ -1,5 +1,5 @@
---
title: "Endian"
title: "endian"
---
{{< callout type="info">}}
@ -23,8 +23,8 @@ If `ETL_ENDIAN_NATIVE` is not defined by the user, then the ETL selects an appro
&emsp;&emsp;`etl::endian::big = std::endian::big`
&emsp;&emsp;`etl::endian::native = std::endian::native`
else, if `__BYTE_ORDER__` is defined then
&emsp;If `__ORDER_LITTLE_ENDIAN__` is defined then
else if `__BYTE_ORDER__` is defined then
&emsp;If `__ORDER_LITTLE_ENDIAN__` is defined then
&emsp;&emsp;`etl::endian::little = __ORDER_LITTLE_ENDIAN__`
&emsp;&emsp;`etl::endian::big = __ORDER_BIG_ENDIAN__`
&emsp;&emsp;`etl::endian::native = __BYTE_ORDER__`

View File

@ -0,0 +1,262 @@
---
title: "error_handler"
---
{{< callout type="info">}}
Header: `error_handler.h`
{{< /callout >}}
Finding errors within an embedded system can be difficult due to the performance and space restrictions imposed upon the platform. The library allows a variety of methods to catch errors, allowing the performance and space overheads to be chosen according to the situation and requirements.
The library allows the method to be chosen at compile time.
You have a choice of:-
- Exceptions
- Asserts
- Error log
- No error checking
The type of error handler used is dependant on the compile time macro defined.
Note: This are usually set as a project wide definition.
| Macro | Actions |
| ----------------------- | ---------------------------------------------------------------------------------------------------- |
| ETL_NO_CHECKS | No checks are mode at all, not even in debug mode. |
| ETL_THROW_EXCEPTIONS | Exceptions are thrown for an error. |
| ETL_USE_ASSERT_FUNCTION | Errors are sent to a user defined assert handler. |
| ETL_LOG_ERRORS | Errors are sent to a user defined error handler. This can be used in conjunction with other options. |
If none of the above macros are defined then the library will use assert. These are only active is `NDEBUG` is not defined.
Errors are checked for by calling one of the following:-
```cpp
ETL_ASSERT(condition, ETL_ERROR(error_exception_class))
```
Raises the error if the condition is `false`.
---
```cpp
ETL_ASSERT_AND_RETURN(condition, ETL_ERROR(error_exception_class))
```
Raises the error if the condition is `false` and calls `return`.
---
```cpp
ETL_ASSERT_AND_RETURN_VALUE(condition, ETL_ERROR(error_exception_class), value)
```
Raises the error if the condition is `false` and calls `return value`.
---
```cpp
ETL_ALWAYS_ASSERT(ETL_ERROR(error_exception_class))
```
Raises the error.
---
```cpp
ETL_ALWAYS_ASSERT_AND_RETURN(ETL_ERROR(error_exception_class))
```
Raises the error and calls `return`.
---
```cpp
ETL_ALWAYS_ASSERT_AND_RETURN_VALUE(ETL_ERROR(error_exception_class), value)
```
Raises the error and calls `return value`.
---
Note: Not all error methods will call the return, such as when using C++ exceptions.
The macro will call return for the following combinations:-
- ETL_LOG_ERRORS only.
- ETL_DEBUG not defined.
---
If `ETL_VERBOSE_ERRORS` is defined then the filename is included as part of the error, otherwise it will be omitted, so reducing storage requirements.
Error messages by be declared using the `ETL_ERROR_TEXT` macro.
```cpp
ETL_ERROR_TEXT("Verbose text", "terse text")
```
If `ETL_VERBOSE_ERRORS` is defined then `ETL_TEXT` uses the verbose text. By default the terse text is used.
The terse text used in the library follows a `<numeric><alpha>` pattern. For example, errors in `etl::vector` start with `"17"` and the alpha code for 'vector full' is `"A"`. The return from the `what()` member function in this case will be `"17A"`.
When ETL_LOG_ERRORS is defined, error exceptions are passed to etl::error_handler::error() before throwing the exception or calling the assert. This will do nothing until a user defined handler function is set. The user function may either be a free function or a member function.
There is an additional switch that enables checks to be made on pushes and pops to containers, ETL_CHECK_PUSH_POP.
This is not enabled by default as empty/full checks will usually be made by the calling code.
---
There are versions of the assert macros that are only enabled when `ETL_IS_DEBUG_BUILD` is true:-
```cpp
ETL_DEBUG_ASSERT(condition, ETL_ERROR(error_exception_class))
```
Raises the error if the condition is `false`.
---
```cpp
ETL_DEBUG_ASSERT_AND_RETURN(condition, ETL_ERROR(error_exception_class))
```
Raises the error if the condition is `false` and calls `return`.
---
```cpp
ETL_DEBUG_ASSERT_AND_RETURN_VALUE(condition, ETL_ERROR(error_exception_class), value)
```
Raises the error if the condition is `false` and calls `return value`.
---
```cpp
ETL_DEBUG_ALWAYS_ASSERT(ETL_ERROR(error_exception_class))
```
Raises the error.
---
```cpp
ETL_DEBUG_ALWAYS_ASSERT_AND_RETURN(ETL_ERROR(error_exception_class))
```
Raises the error and calls `return`.
---
```cpp
ETL_DEBUG_ALWAYS_ASSERT_AND_RETURN_VALUE(ETL_ERROR(error_exception_class), value)
```
Raises the error and calls return(value).
## Example macro combinations
*No error macros defined*
&emsp;Asserts are generated when a check fails.
---
`ETL_LOG_ERRORS`
&emsp;The error handler is called.
---
`ETL_NO_CHECKS`
&emsp;No checks are made. No asserts or exceptions are generated.
&emsp;No calls to the error handler are made, even if `ETL_LOG_ERRORS` is defined.
---
`ETL_THROW_EXCEPTIONS`
&emsp;An exception is thrown when a check fails.
---
`ETL_USE_ASSERT_FUNCTION`
&emsp;Calls a user defined assert function. Set with `etl::set_assert_function()`
&emsp;The assert function must have the signature `void(const etl::exception&)`
&emsp;If an assert handler is not specified then `assert(false)` is called.
---
`ETL_LOG_ERRORS`
`ETL_THROW_EXCEPTIONS`
&emsp;When a check fails the error handler is called, then an exception is thrown.
---
`ETL_LOG_ERRORS`
`ETL_CHECK_PUSH_POP`
&emsp;Asserts are generated when a check fails and the error handler is called and additional checks for pushes and pops are made.
## Example error handlers
```cpp
void free_function(const etl::exception& e)
{
std::cout << "The error was " << e.what() << " in " << e.file_name() << " at "
<< e.line_number() << "\n";
}
struct error_log
{
void member_function(const etl::exception& e)
{
std::cout << "The error was " << e.what() << " in " << e.file_name() << " at "
<< e.line_number() << "\n";
}
};
```
---
**Setting a free function as the recipient**
```cpp
int main()
{
etl::error_handler::set_callback<free_function>();
}
```
---
**Setting a member function as the recipient**
```cpp
error_log log;
// Run-time
int main()
{
etl::error_handler::set_callback<error_log, &error_log::member_function>(log);
}
// Compile-time. 'log' must have static linkage.
int main()
{
etl::error_handler::set_callback<error_log, log, &error_log::member_function>();
}
```
---
**Setting an `etl::ifunction` as the recipient**
*This is not recommended for new applications.*
*Use one of the methods above instead.*
```cpp
// Free function
etl::function<void, const etl::exception&> error_callback(free_function);
// Member function
etl::function<TObject, const etl::exception&> error_callback(log, &error_log::member_function);
// Free function using the nested struct (Deprecated)
etl::error_handler::free_function error_callback(free_function);
// Member function using the nested struct (Deprecated)
etl::error_handler::member_function error_callback(log, error_log::member_function);
Use one of the above
int main()
{
// Tell the error handler about it.
etl::error_handler::set_callback(error_callback);
}
```
---
**Deprecated**
The nested structures `free_function` and `member_function` may still be used, but are deprecated.

View File

@ -4,10 +4,9 @@ title: "instance_count"
{{< callout type="info">}}
Header: `instance_count.h`
Since: `TBC`
{{< /callout >}}
Inherit from this class to count instances of a class.
Inherit from this class to count instances of a class.
Before: `20.25.0`
```cpp
@ -15,21 +14,26 @@ etl::instance_count<typename T>
```
This class is not thread safe.
From: `20.25.0`
Since: `20.25.0`
```cpp
etl::instance_count<typename T, typename TCounter = uint32_t>
```
This class is not thread safe unless `TCounter` is an atomic type.
This class is thread safe if `TCounter` is an *atomic* type.
## Types
`type` The type being counted.
`counter_type` The type used for the counter.
`type`
The type being counted.
`counter_type`
The type used for the counter.
## Member functions
```cpp
static const counter_type& get_instance_count()
```
**Description**
Returns a const reference to the current count.
---
@ -37,6 +41,7 @@ Returns a const reference to the current count.
```cpp
static void reset_instance_count()
```
**Description**
Resets the count to zero.
## Example

7
docs/utilities/limits.md Normal file
View File

@ -0,0 +1,7 @@
---
title: "limits"
---
An emulation of <limits> under the `etl` namespace.
See https://en.cppreference.com/w/cpp/types/numeric_limits

View File

@ -1,88 +1,162 @@
Reference Counted Objects
---
title: "Reference Counted Objects"
---
Reference counted objects types
Reference counted objects types.
Defines the following classes.
```cpp
etl::ireference_counter
The interface of all reference counters.
```
The interface of all reference counters.
---
```cpp
etl::reference_counter<TCounter>
A reference counter using TCounter as the counter.
```
A reference counter using TCounter as the counter.
---
```cpp
etl::reference_counter<void>
A null reference counter. The reference count always reports as 1.
```
A null reference counter. The reference count always reports as 1.
---
```cpp
etl::ireference_counted_object
The interface of all reference counted object types.
```
The interface of all reference counted object types.
---
```cpp
etl::reference_counted_object<typename TObject, typename TCounter>
Derived from etl::ireference_counted_object
```
Derived from `etl::ireference_counted_object`
---
```cpp
etl::atomic_counted_object<typename TObject>
A template alias of etl::reference_counted_object<typename TObject, etl::atomic_int32_t>
____________________________________________________________________________________________________
ireference_counter
```
A template alias of `etl::reference_counted_object<typename TObject, etl::atomic_int32_t>`
## ireference_counter
```cpp
etl::ireference_counter
```
The interface of all reference counters.
```cpp
virtual ~ireference_counter() {};
virtual void set_reference_count(int32_t value) = 0;
virtual void increment_reference_count() = 0;
ETL_NODISCARD virtual int32_t decrement_reference_count() = 0;
ETL_NODISCARD virtual int32_t get_reference_count() const = 0;
____________________________________________________________________________________________________
reference_counter
```
## reference_counter
```cpp
etl::reference_counter<TCounter>
```
A reference counter that uses type TCounter to count.
---
```cpp
etl::reference_counter<void>
A dummy reference counter that always returns a count of 1.
```
A dummy reference counter that always returns a count of 1.
Used for persistent objects.
____________________________________________________________________________________________________
ireference_counted_object
## ireference_counted_object
```cpp
etl::ireference_counted_object<typename TObject, typename TCounter>
```
The interface of all reference counted object types.
____________________________________________________________________________________________________
---
```cpp
virtual ~ireference_counted_object()
____________________________________________________________________________________________________
```
---
```cpp
ETL_NODISCARD virtual etl::ireference_counter& get_reference_counter() = 0;
```
Get a reference to the reference counter.
____________________________________________________________________________________________________
---
```cpp
ETL_NODISCARD virtual const etl::ireference_counter& get_reference_counter() const = 0;
```
Get a const reference to the reference counter.
____________________________________________________________________________________________________
reference_counted_object
etl::reference_counted_object<typename TObject, typename TCounter>
## reference_counted_object
```cpp
etl::reference_counted_object<typename TObject, typename TCounter>
```
The implementation of a reference counted object.
____________________________________________________________________________________________________
reference_counted_object(const TObject& object)
Constructs from an .
The object is copied.
____________________________________________________________________________________________________
reference_counted_object()
Constructs from an .
The object is default constructed.
____________________________________________________________________________________________________
ETL_NODISCARD TObject& get_object() ETL_OVERRIDE
Get a reference to the object.
____________________________________________________________________________________________________
ETL_NODISCARD const TObject& get_object() const ETL_OVERRIDE
Get a const reference to the object.
____________________________________________________________________________________________________
ETL_NODISCARD etl::ireference_counter& get_reference_counter() ETL_OVERRIDE
Get a reference to the reference counter.
____________________________________________________________________________________________________
ETL_NODISCARD const etl::ireference_counter& get_reference_counter() const ETL_OVERRIDE
Get a const reference to the reference counter.
____________________________________________________________________________________________________
For C++11, with atomic support.
---
```cpp
reference_counted_object(const TObject& object)
```
Constructs from an object.
The object is copied.
---
```cpp
reference_counted_object()
```
Constructs from an onject.
The object is default constructed.
---
```cpp
ETL_NODISCARD TObject& get_object() ETL_OVERRIDE
```
Get a reference to the object.
---
```cpp
ETL_NODISCARD const TObject& get_object() const ETL_OVERRIDE
```
Get a const reference to the object.
---
```cpp
ETL_NODISCARD etl::ireference_counter& get_reference_counter() ETL_OVERRIDE
```
Get a reference to the reference counter.
---
```cpp
ETL_NODISCARD const etl::ireference_counter& get_reference_counter() const ETL_OVERRIDE
```
Get a const reference to the reference counter.
## For C++11, with atomic support.
```cpp
template <typename TObject>
using atomic_counted_object = etl::reference_counted_object<TObject, etl::atomic_int32_t>;
```
**Description**
Defines an alias to a reference counted object that uses an atomic.

531
docs/utilities/utility.md Normal file
View File

@ -0,0 +1,531 @@
---
title: "Utility"
---
{{< callout type="info">}}
Header: `utility.h`
{{< /callout >}}
Useful utility functions and classes.
## pair
```cpp
template <typename T1, typename T2>
struct pair
```
**Description**
A clone of std::pair
**C++03**
```cpp
template <typename T1, typename T2>
pair<T1, T2> make_pair(T1 a, T2 b)
```
**C++11 and above**
```cpp
template <typename T1, typename T2>
pair<T1, T2> make_pair(T1&& a, T2&& b)
```
**Description**
Returns a pair.
---
```cpp
template <size_t Index, typename T1, typename T2>
struct tuple_element<Index, ETL_OR_STD::pair<T1, T2>>
```
**Description**
Specialisation for pair.
Gets the type in the pair at `Index`.
Static asserts if `Index` is not `0` or `1`.
Since: `20.40.1`
---
```cpp
template <typename T1, typename T2>
struct tuple_size<ETL_OR_STD::pair<T1, T2>>
```
**Description**
Specialisation for pair.
Gets the size of the pair, which is always `2`.
Since:`20.40.1`
## Template deduction guides
**C++17 and above**
```cpp
template <typename T1, typename T2>
pair(T1, T2) ->pair<T1, T2>;
```
## exchange
```cpp
template <typename T, typename U = T>
T exchange(T& object, const U& new_value)
```
**Description**
Copies the new value to object and returns the old value.
Note: This is not an atomic operation.
## add_const
```cpp
template <typename T>
typename etl::add_const<T>::type& as_const(T& t)
```
**Description**
Returns a value of type `T` as a `const T`.
## coordinate_2d
```cpp
template <typename T>
struct coordinate_2d
```
**Member types**
`T x;`
`T y;`
## in_place disambiguation tags.
```cpp
struct in_place_t
```
```cpp
inline constexpr in_place_t in_place{}; // C++17
```
---
```cpp
template <typename T> struct in_place_type_t
```
```cpp
template <typename T>
inline constexpr in_place_type_t<T> in_place_type{}; // C++17
```
---
```cpp
template <size_t I> struct in_place_index_t
```
```cpp
template <size_t I>
inline constexpr in_place_index_t<I> in_place_index{}; // C++17
```
## declval
```cpp
template <typename T>
typename etl::add_rvalue_reference<T>::type declval() ETL_NOEXCEPT;
```
C++11
## functor
For C++11 and above.
Since: `20.27.0`
```cpp
template <typename TReturn, typename... TParams>
class functor
```
**Description**
Wraps a free/global function in a functor.
---
```cpp
constexpr functor(TReturn(*ptr_)(TParams...))
```
Constructs a functor from a function pointer.
---
```cpp
constexpr TReturn operator()(TParams... args) const
```
**Description**
Function operator.
Calls the wrapped function with the forwarded parameters.
### Example
```cpp
void int Function(int i)
{
return i;
}
// Note that the functor deduces the template parameters.
constexpr etl::functor f(Function);
```
---
## member_function_wrapper
For C++11 and above.
Since: `20.27.0`
```cpp
template <typename TReturn, typename... TParams>
class member_function_wrapper<TReturn(TParams...)>
```
**Description**
Wraps a member function in a static member function.
---
```cpp
template <typename T, T& Instance, TReturn(T::* Method)(TParams...)>
static constexpr TReturn function(TParams... params)
```
**Description**
The static function that calls the member function.
### Example
```cpp
class MyClass
{
public:
int MemberFunction(int i)
{
return 2 * i;
}
};
MyClass test;
constexpr int(*pf)(int)
= &etl::member_function_wrapper<int(int)>::function<MyClass, test, &MyClass::MemberFunction>;
// Call
int result = pf(1);
```
## functor_wrapper
For C++11 and above.
Since: `20.27.0`
```cpp
template <typename TReturn, typename... TParams>
class functor_wrapper<TReturn(TParams...)>
```
**Description**
Wraps a functor in a static member function.
---
```cpp
template <typename TFunctor, TFunctor& Instance>
static constexpr TReturn function(TParams... params)
```
**Description**
The static function that calls the member function.
### Example
```cpp
class MyClass
{
public:
int operator()(int i)
{
return 2 * i;
}
};
MyClass test;
constexpr int(*pf)(int) = &etl::functor_wrapper<int(int)>::function<MyClass, test>;
// Call
int result = pf(1);
```
## functor_as_static
For C++17 and above.
20.40.0
Wraps a functor with a static free function at compile time.
Creates a static member `call` that calls the specified functor.
```cpp
template <auto& Instance>
struct functor_as_static
```
---
```cpp
template <typename... TArgs>
static constexpr auto call(TArgs&&... args)
```
**Description**
Member static function that calls the functor
### Example
```cpp
struct Test
{
int operator()(int i)
{
return 2 * i;
}
};
Test test;
using fas_t = etl::functor_as_static<test>;
fas_t::call(1));
```
## member_function_as_static
For C++17 and above.
Since: `20.40.0`
Wraps a member function with a static free function at compile time.
Creates a static member function that calls the specified member function.
```cpp
template <auto Method, auto& Instance>
struct member_function_as_static
```
---
```cpp
template <typename... TArgs>
static constexpr auto call(TArgs&&... args)
```
**Description**
Member static function that calls the member function.
### Example
```cpp
struct Test
{
int Function()(int i)
{
return 2 * i;
}
};
Test test;
using mfas_t = etl::functor_as_static<&Test::Function, test>;
mfas_t::call(1));
```
## member_function_as_functor
For C++17 and above.
Since: `20.40.0`
Wraps a member function with a functor at compile time.
Creates a functor that calls the specified member function.
```cpp
template <auto Method, auto& Instance>
class member_function_as_functor
```
---
```cpp
template <typename... TArgs>
constexpr auto operator()(TArgs&&... args) const
```
**Description**
Calls the functor.
### Example
```cpp
struct Test
{
int Function()(int i)
{
return 2 * i;
}
};
constexpr etl::member_function_as_functor<&Test::Function, test> mfaf;
mfaf(1);
```
## function_as_functor
For C++17 and above.
Since: `20.40.0`
Wraps a function with a functor at compile time.
Creates a functor that calls the specified free function.
```cpp
template <auto Function>
class function_as_functor
```
---
```cpp
constexpr auto operator()(TArgs&&... args) const
```
**Description**
Calls the functor.
### Example
```cpp
int Function()(int i)
{
return 2 * i;
}
constexpr etl::function_as_functor<Function> faf;
faf(1);
```
## function_ptr_as_functor
For C++11 and above.
Since: `20.40.0`
Wraps a function pointer with a functor at run time.
Creates a functor that calls the specified free function.
```cpp
template <typename TReturn, typename... TArgs>
class function_ptr_as_functor
```
---
```cpp
constexpr function_ptr_as_functor(TReturn(*ptr_)(TArgs...))
```
**Description**
Construct from a function pointer.
---
```cpp
constexpr TReturn operator()(TArgs... args) const
```
**Description**
Function operator.
### Example
```cpp
int Function()(int i)
{
return 2 * i;
}
using function_type = decltype(Function);
constexpr function_type* fptr = Function;
constexpr etl::function_ptr_as_functor<function_type> fpaf(fptr)
```
## integer_sequence
Since: `20.14.0`
```cpp
template <typename T, T... Integers>
class integer_sequence
```
## index_sequence
Since: `20.14.0`
```cpp
template <size_t... Indices>
using index_sequence = etl::integer_sequence<size_t, Indices...>;
```
```cpp
template <size_t N>
make_index_sequence
```
## select1st & select2nd
`select1st`
A functor object that takes a single argument, a pair, and returns the `pair::first element`.
---
`select2nd`
A functor object that takes a single argument, a pair, and returns the `pair::second element`.
## size_of_type
Since: `20.36.0`
```cpp
template <typename T>
ETL_CONSTEXPR size_t size_of_type()
```
**Description**
Returns the size of the type defined in `T`.
---
```cpp
template <typename T>
ETL_CONSTEXPR size_t size_of_type(const T&)
```
**Description**
Returns the size of the type defined in `T`.
---
```cpp
ETL_SIZE_OF_OBJECT_TYPE(Object, Type)
```
**Description**
Returns the size of `Type` defined in the declared type of `Object`.
C++11 and above.
Since: `20.36.0`
```cpp
ETL_SIZE_OF_CLASS_TYPE(Class, Type)
```
**Description**
Returns the size of `Type` defined in `Class`.
Since: `20.36.0`
---
## nontype_t
Since `20.43.0`
Wraps a non-type template parameter as a type.
Defines a value associated with the template type.
If `ETL_FORCE_CPP11_NONTYPE` is defined then the C++14 and below variant is used.
**C++14 and below**
```cpp
template <typename T, T Value>
struct nontype_t;
```
```cpp
using FortyTwo = etl::nontype_t<int, 42>;
```
**C++17 and above**
```cpp
template <auto Value>
struct nontype_t;
```
```cpp
using FortyTwo = etl::nontype_t<42>
```

View File

@ -48,7 +48,7 @@ html:not(.dark) pre code {
}
html:not(.dark) hr {
background-color: darkgrey !important;
background-color: #eeeeee !important;
}
html:not(.dark) .hx\:font-extrabold {