Fix code examples in documentation (#1471)

This commit is contained in:
Roland Reichwein 2026-06-23 19:11:17 +02:00 committed by GitHub
parent 4e11bc9d54
commit d598337107
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
36 changed files with 484 additions and 365 deletions

View File

@ -404,8 +404,8 @@ port.control ^= 0x0080;
uint16_t status = port.status;
// Copy data from a buffer to the Tx data port.
std::copy(txBuffer.begin(), txBuffer.end(), serial_port.txdata.iter());
std::copy(txBuffer.begin(), txBuffer.end(), port.txdata.iter());
// Copy data from the Rx data port to a buffer.
std::copy_n(serial_port.rxdata, serial_port.status, std::back_inserter(rxBuffer));
std::copy_n(port.rxdata.iter(), status, std::back_inserter(rxBuffer));
```

View File

@ -130,7 +130,7 @@ Less-than-equal operator.
```cpp
ETL_CONSTEXPR14
bool operator <(const etl::chrono::month_day& lhs,
bool operator >(const etl::chrono::month_day& lhs,
const etl::chrono::month_day& rhs)
ETL_NOEXCEPT
```
@ -141,7 +141,7 @@ Greater-than operator.
```cpp
ETL_CONSTEXPR14
bool operator <=(const etl::chrono::month_day& lhs,
bool operator >=(const etl::chrono::month_day& lhs,
const etl::chrono::month_day& rhs)
ETL_NOEXCEPT
```

View File

@ -146,7 +146,7 @@ Rounds up a duration to the nearest higher precision.
---
```cp
```cpp
template <typename TToDuration, typename TClock, typename TDuration>
ETL_NODISCARD
ETL_CONSTEXPR14

View File

@ -46,10 +46,12 @@ Copy constructor.
## Tests
```cpp
ETL_NODISCARD
ETL_CONSTEXPR14
bool ok() const
ETL_NOEXCEPT
```
**Return**
`true` if the weekday_indexed is valid

View File

@ -5,309 +5,460 @@ title: "Base64"
{{< callout type="info">}}
Headers:
`base64.h` Common definitions
`base64_encoder.h` Encoder class
`base64_decoder.h` Decoder class
From: `20.38.4`
`base64_encoder.h` Encoder classes
`base64_decoder.h` Decoder classes
From: `20.38.17`
{{< /callout >}}
Encodes and decodes data to and from Base64 format.
## Encode
The codecs are stream based. Data is fed in one element, or block of elements, at a time and the encoded or decoded result is written to the codec's internal output buffer. The result can be obtained in one of two ways:
- If the internal buffer is large enough to hold the entire result, it can be read directly from the codec via `begin()`/`end()` or `span()`.
- Otherwise a callback may be supplied that is called with a span of the output data each time the internal buffer becomes full, and once more with an empty span to signal that the final block has been processed.
**Input -> pointer/length : Output -> pointer/length**
A separate codec class is supplied for each supported Base64 variant.
## Encoder
The encoder classes are declared in `base64_encoder.h`. They all derive from `etl::ibase64_encoder`, which provides the interface described below.
| Class | Variant | Padding |
| :--- | :--- | :--- |
| `etl::base64_rfc2152_encoder<Buffer_Size>` | RFC-2152 | No |
| `etl::base64_rfc3501_encoder<Buffer_Size>` | RFC-3501 | No |
| `etl::base64_rfc4648_encoder<Buffer_Size>` | RFC-4648 | No |
| `etl::base64_rfc4648_padding_encoder<Buffer_Size>` | RFC-4648 | Yes |
| `etl::base64_rfc4648_url_encoder<Buffer_Size>` | RFC-4648-URL | No |
| `etl::base64_rfc4648_url_padding_encoder<Buffer_Size>` | RFC-4648-URL | Yes |
### Template parameters
`Buffer_Size` The size of the internal output buffer, in characters.
Defaults to `etl::base64::Min_Encode_Buffer_Size` (4).
Must be a non-zero multiple of `etl::base64::Min_Encode_Buffer_Size`.
### Member types
```cpp
typedef etl::span<const char> span_type;
typedef etl::delegate<void(const span_type&)> callback_type;
```
### Constructors
```cpp
base64_rfcXXXX_encoder()
```
**Description**
Constructs an encoder with no callback. The encoded result is read from the internal output buffer.
---
```cpp
base64_rfcXXXX_encoder(callback_type callback)
```
**Description**
Constructs an encoder with a callback. The callback is called with a span of the encoded data each time the internal buffer becomes full, and with an empty span once the final block has been flushed.
### Encoding
```cpp
template <typename T>
ETL_CONSTEXPR14
static
size_t encode(const T* input, size_t input_length,
char* output, size_t output_length)
bool encode(T value)
```
**Description**
Transforms the input data described by input and input_length to Base64 format to be stored in output output_length.
Encodes a single 8 bit value.
Enabled if `etl::is_integral<T>` is `true` and `etl::integral_limits<T>::bits == 8`.
**Return**
The length of the encoded data.
**Error**
If output_length is not large enough to hold the encoded data then an `etl::base64_overflow` is raised.
`false` if the output buffer overflowed, otherwise `true`.
---
**Input -> pointer/length : Output -> string**
```cpp
template <typename TInputIterator>
bool encode(TInputIterator input_begin, size_t input_length)
```
**Description**
Encodes `input_length` 8 bit values starting at `input_begin`.
**Return**
`false` if the output buffer overflowed, otherwise `true`.
---
```cpp
template <typename TInputIterator>
bool encode(TInputIterator input_begin, TInputIterator input_end)
```
**Description**
Encodes the 8 bit values in the range `input_begin` to `input_end`.
**Return**
`false` if the output buffer overflowed, otherwise `true`.
---
```cpp
template <typename TInputIterator>
bool encode_final(TInputIterator input_begin, size_t input_length)
```
**Description**
Encodes `input_length` 8 bit values starting at `input_begin`, then flushes the final block. Equivalent to `encode()` followed by `flush()`.
**Return**
`false` if the output buffer overflowed, otherwise `true`.
---
```cpp
template <typename TInputIterator>
bool encode_final(TInputIterator input_begin, TInputIterator input_end)
```
**Description**
Encodes the 8 bit values in the range `input_begin` to `input_end`, then flushes the final block. Equivalent to `encode()` followed by `flush()`.
**Return**
`false` if the output buffer overflowed, otherwise `true`.
---
```cpp
bool flush()
```
**Description**
Encodes any remaining buffered input, including any required padding, and marks the end of the data. If a callback has been set it is called with any remaining data and then with an empty span.
Must be called once all of the input has been passed to `encode()`. Not required when `encode_final()` is used.
**Return**
`false` if the output buffer overflowed, otherwise `true`.
---
```cpp
void restart()
```
**Description**
Resets the encoder so that it can be reused to encode a new set of data.
### Reading the result
These functions return a useful value only when no callback has been set. The internal buffer must be large enough to hold the entire encoded result.
```cpp
const char* begin() const
const char* cbegin() const
```
**Return**
A pointer to the beginning of the encoded data in the internal buffer.
---
```cpp
const char* end() const
const char* cend() const
```
**Return**
A pointer to the end of the encoded data in the internal buffer.
---
```cpp
size_t size() const
```
**Return**
The number of encoded characters currently held in the internal buffer.
---
```cpp
size_t max_size() const
```
**Return**
The maximum size of the internal output buffer (`Buffer_Size`).
---
```cpp
span_type span() const
```
**Return**
A span over the encoded data in the internal buffer.
### Status
```cpp
bool overflow() const
```
**Return**
`true` if the output buffer has overflowed.
---
```cpp
bool error() const
```
**Return**
`true` if an error has been detected. For the encoder this is equivalent to `overflow()`.
### Static functions
```cpp
static size_t safe_output_buffer_size(size_t input_length)
```
**Return**
The internal buffer size required to encode `input_length` bytes in a single pass. Use this as the `Buffer_Size` template argument when the whole result is to be read from the internal buffer.
## Decoder
The decoder classes are declared in `base64_decoder.h`. They all derive from `etl::ibase64_decoder`, which provides the interface described below.
| Class | Variant | Padding |
| :--- | :--- | :--- |
| `etl::base64_rfc2152_decoder<Buffer_Size>` | RFC-2152 | No |
| `etl::base64_rfc3501_decoder<Buffer_Size>` | RFC-3501 | No |
| `etl::base64_rfc4648_decoder<Buffer_Size>` | RFC-4648 | No |
| `etl::base64_rfc4648_padding_decoder<Buffer_Size>` | RFC-4648 | Yes |
| `etl::base64_rfc4648_url_decoder<Buffer_Size>` | RFC-4648-URL | No |
| `etl::base64_rfc4648_url_padding_decoder<Buffer_Size>` | RFC-4648-URL | Yes |
### Template parameters
`Buffer_Size` The size of the internal output buffer, in bytes.
Defaults to `etl::base64::Min_Decode_Buffer_Size` (3).
Must be greater than or equal to `etl::base64::Min_Decode_Buffer_Size`.
### Member types
```cpp
typedef etl::span<const unsigned char> span_type;
typedef etl::delegate<void(const span_type&)> callback_type;
```
### Constructors
```cpp
base64_rfcXXXX_decoder()
```
**Description**
Constructs a decoder with no callback. The decoded result is read from the internal output buffer.
---
```cpp
base64_rfcXXXX_decoder(callback_type callback)
```
**Description**
Constructs a decoder with a callback. The callback is called with a span of the decoded data each time the internal buffer becomes full, and with an empty span once the final block has been flushed.
### Decoding
```cpp
template <typename T>
ETL_CONSTEXPR14
static
size_t encode(const T* input, size_t input_length,
etl::istring& output)
bool decode(T value)
```
**Description**
Transforms the input data described by input and input_length to Base64 format to be stored in output.
Enabled if `etl::is_integral<T>` is `true` and `etl::integral_limits<T>::bits == 8`.
The output string must have capacity of at least `etl::base64::encode_size(input)`.
**Return**
The length of the encoded data.
**Error**
If output_length is not large enough to hold the encoded data then an `etl::base64_overflow` is raised.
---
**Input -> pointer/pointer : Output -> pointer/pointer**
```cpp
template <typename T>
ETL_CONSTEXPR14
static
size_t encode(const T* input_begin, const T* input_end,
char* output_begin, char* output_end)
```
**Description**
Transforms the input data described by input_begin and input_end to Base64 format to be stored in output_begin to output_end.
Decodes a single Base64 character.
Enabled if `etl::is_integral<T>` is `true` and `etl::integral_limits<T>::bits == 8`.
**Return**
The length of the encoded data.
**Error**
If the output buffer is not large enough to hold the encoded data then an `etl::base64_overflow` is raised.
`false` if an error was detected, otherwise `true`.
---
**Input -> pointer/pointer : Output -> string**
```cpp
template <typename T>
ETL_CONSTEXPR14
static
size_t encode(const T* input_begin, const T* input_end,
etl::istring& output)
template <typename TInputIterator>
bool decode(TInputIterator input_begin, TInputIterator input_end)
```
**Description**
Transforms the input data described by input_begin and input_end to Base64 format to be stored in output.
Enabled if `etl::is_integral<T>` is `true` and `etl::integral_limits<T>::bits == 8`.
The output string must have capacity of at least `etl::base64::encode_size(input)`.
Decodes the Base64 characters in the range `input_begin` to `input_end`.
**Return**
The length of the encoded data.
**Error**
If the output buffer is not large enough to hold the encoded data then an `etl::base64_overflow` is raised.
`false` if an error was detected, otherwise `true`.
---
**Input -> span : Output -> span**
```cpp
template <typename T, size_t Length1, size_t Length2>
ETL_CONSTEXPR14
static
size_t encode(const etl::span<const T, Length1>& input_span,
const etl::span<char, Length2>& output_span)
template <typename TInputIterator>
bool decode(TInputIterator input_begin, size_t input_length)
```
**Description**
Transforms the input data described by input_span to Base64 format to be stored in output_span.
Enabled if etl::is_integral<T> is true and etl::integral_limits<T>::bits == 8.
Decodes `input_length` Base64 characters starting at `input_begin`.
**Return**
The length of the encoded data.
**Error**
If the output span is not large enough to hold the encoded data then an etl::base64_overflow is raised.
`false` if an error was detected, otherwise `true`.
---
**Input -> span : Output -> string**
```cpp
template <typename T, size_t Length>
ETL_CONSTEXPR14
static
size_t encode(const etl::span<const T, Length>& input_span,
etl::istring& output)
template <typename TInputIterator>
bool decode_final(TInputIterator input_begin, TInputIterator input_end)
```
**Description**
Transforms the input data described by input_span to Base64 format to be stored in output.
Enabled if etl::is_integral<T> is true and etl::integral_limits<T>::bits == 8
The output string must have capacity of at least etl::base64::encode_size(input).
Decodes the Base64 characters in the range `input_begin` to `input_end`, then flushes the final block. Equivalent to `decode()` followed by `flush()`.
**Return**
The length of the encoded data.
**Error**
If the output span is not large enough to hold the encoded data then an etl::base64_overflow is raised.
`false` if an error was detected, otherwise `true`.
---
```cpp
ETL_NODISCARD
ETL_CONSTEXPR14
static
size_t encode_size(size_t input_length)
```
**Return**
Returns the size of the output buffer required to encode the specified input data length.
## Decode
**Input -> pointer/length : Output -> pointer/length**
```cpp
template <typename T>
ETL_CONSTEXPR14
static
size_t decode(const char* input, size_t input_length,
T* output, size_t output_length)
template <typename TInputIterator>
bool decode_final(TInputIterator input_begin, size_t input_length)
```
**Description**
Transforms the Base64 format input data described by input and input_length to by output and output_length.
Enabled if `etl::is_integral<T>` is `true` and `etl::integral_limits<T>::bits == 8`.
Decodes `input_length` Base64 characters starting at `input_begin`, then flushes the final block. Equivalent to `decode()` followed by `flush()`.
**Return**
The length of the decoded data.
**Error**
If `output_length` is not large enough to hold the decoded data then an `etl::base64_overflow` is raised.
`false` if an error was detected, otherwise `true`.
---
**Input -> pointer/pointer: Output -> pointer/pointer**
```cpp
template <typename T>
ETL_CONSTEXPR14
static
size_t decode(const char* input_begin, const char* input_end,
T* output_begin, T* output_end)
```
**Description***
Transforms the Base64 format input data described by `input_begin` and `input_end` to `output_begin` and `output_end`.
Enabled if `etl::is_integral<T>` is `true` and `etl::integral_limits<T>::bits == 8`.
**Return**
The length of the decoded data.
**Error**
If the output buffer is not large enough to hold the decoded data then an `etl::base64_overflow` is raised.
---
**Input -> span: Output -> span**
```cpp
template <typename T, size_t Length1, size_t Length2>
ETL_CONSTEXPR14
static
size_t decode(const etl::span<const char, Length1>& input_span,
const etl::span<T, Length2>& output_span)
bool flush()
```
**Description**
Transforms the Base64 format input data described by input_span to output_span.
Enabled if `etl::is_integral<T>` is `true` and `etl::integral_limits<T>::bits == 8`.
Decodes any remaining buffered input and marks the end of the data. If a callback has been set it is called with any remaining data and then with an empty span.
Must be called once all of the input has been passed to `decode()`. Not required when `decode_final()` is used.
**Return**
The length of the decoded data.
**Error**
If the output span is not large enough to hold the decoded data then an `etl::base64_overflow` is raised.
`false` if an error was detected, otherwise `true`.
---
```cpp
ETL_NODISCARD
ETL_CONSTEXPR14
static
size_t decode_size(const char* input, size_t input_length)
void restart()
```
**Description**
Resets the decoder so that it can be reused to decode a new set of data.
### Reading the result
These functions return a useful value only when no callback has been set. The internal buffer must be large enough to hold the entire decoded result.
```cpp
const unsigned char* begin() const
const unsigned char* cbegin() const
```
**Return**
The size of the output buffer required to decode the specified input Base64 data length.
A pointer to the beginning of the decoded data in the internal buffer.
---
```cpp
ETL_NODISCARD
ETL_CONSTEXPR14
static
size_t decode_size(const char* input_begin, const char* input_end)
const unsigned char* end() const
const unsigned char* cend() const
```
**Return**
The size of the output buffer required to decode the specified input Base64 data length.
A pointer to the end of the decoded data in the internal buffer.
---
```cpp
ETL_NODISCARD
ETL_CONSTEXPR14
static
size_t decode_size(etl::span<const char> input)
size_t size() const
```
**Return**
The size of the output buffer required to decode the specified input Base64 data length.
The number of decoded bytes currently held in the internal buffer.
---
```cpp
size_t buffer_size() const
```
**Return**
The maximum size of the internal output buffer (`Buffer_Size`).
---
```cpp
span_type span() const
```
**Return**
A span over the decoded data in the internal buffer.
### Status
```cpp
bool overflow() const
```
**Return**
`true` if the output buffer has overflowed.
---
```cpp
bool invalid_data() const
```
**Return**
`true` if an invalid Base64 character was encountered.
---
```cpp
bool error() const
```
**Return**
`true` if an error has been detected. Equivalent to `overflow() || invalid_data()`.
### Static functions
```cpp
static size_t safe_output_buffer_size(size_t input_length)
```
**Return**
The internal buffer size required to decode `input_length` Base64 characters in a single pass. Use this as the `Buffer_Size` template argument when the whole result is to be read from the internal buffer.
## Examples
### Encode
### Encode - reading the result from the internal buffer
```cpp
const etl::array<int8_t, 12> input =
// The data to encode. "Hello World!"
constexpr size_t Input_Length = 12U;
const etl::array<char, Input_Length> input =
{
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20,
0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21 // "Hello World!"
0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21
};
etl::string<20> encoded;
// An encoder whose internal buffer is large enough to hold the entire result.
using encoder_type = etl::base64_rfc4648_encoder<etl::base64_rfc4648_encoder<>::safe_output_buffer_size(Input_Length)>;
size_t encoded_size = etl::base64::encode(input.data(), input.size(),
encoded.data(), encoded.size());
encoder_type encoder;
encoded.resize(encoded_size);
// encoded == "OycDQy37KCphrg=="
// Encode all of the input and flush the final block.
encoder.encode_final(input.begin(), input.end());
// Copy the result out of the encoder's internal buffer.
etl::string<16> encoded(encoder.begin(), encoder.end());
// encoded == "SGVsbG8gV29ybGQh"
```
---
*For C++14 or above*
### Encode - streaming the result through a callback
```cpp
const etl::array<int8_t, 12> input =
etl::string<16> encoded;
// Called with each chunk of encoded data as the internal buffer fills,
// and finally with an empty span to signal the end of the data.
auto append = [&encoded](const etl::span<const char>& chunk)
{
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20,
0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21 // "Hello World!"
encoded.append(chunk.begin(), chunk.end());
};
constexpr size_t length = etl::base64::encode_size(input.size());
etl::string<length> output;
output.uninitialized_resize(output.capacity());
etl::base64_rfc4648_encoder<>::callback_type callback = append;
etl::base64::encode(input.data(), input.size(), output.data(), output.size());
// output == "OycDQy37KCphrg=="
// A minimum size encoder that streams its output through the callback.
etl::base64_rfc4648_encoder<> encoder(callback);
encoder.encode_final(input.begin(), input.end());
// encoded == "SGVsbG8gV29ybGQh"
```
---
### Decode
### Decode - reading the result from the internal buffer
```cpp
const etl::string<16> encoded = "OycDQy37KCphrg==";
const etl::string<16> encoded = "SGVsbG8gV29ybGQh";
etl::vector<int8_t, 20> output;
// A decoder whose internal buffer is large enough to hold the entire result.
using decoder_type = etl::base64_rfc4648_decoder<etl::base64_rfc4648_decoder<>::safe_output_buffer_size(16U)>;
size_t decoded_size = etl::base64::decode(encoded.data(), encoded.size(),
output.data(), output.size());
decoder_type decoder;
output.resize(decoded_size);
// Decode all of the input and flush the final block.
decoder.decode_final(encoded.begin(), encoded.end());
// Copy the result out of the decoder's internal buffer.
etl::vector<unsigned char, 12> output(decoder.begin(), decoder.end());
// output == { 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20,
// 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21 };
```
---
*For C++14 or above*
```cpp
// "OycDQy37KCphrg=="
constexpr const etl::array<char, 16> input =
{
0x4F, 0x79, 0x63, 0x44, 0x51, 0x79, 0x33, 0x37,
0x4B, 0x43, 0x70, 0x68, 0x72, 0x67, 0x3D, 0x3D
};
constexpr size_t length = etl::base64::decode_size(input.data(), input.size());
etl::vector<int8_t, length> output;
etl::base64::decode(input.data(), input.size(), output.data(), output.size());
// output == { 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20,
// 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21 };
// 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21 }; // "Hello World!"
```

View File

@ -61,7 +61,7 @@ Equal to `100 * count() / width()`
---
```cpp
bool count() const
size_t count() const
```
**Description**
Returns the number of elements in use in the filter.
@ -69,7 +69,7 @@ Returns the number of elements in use in the filter.
---
```cpp
bool width() const
size_t width() const
```
**Description**
Returns the width of the filter.

View File

@ -84,8 +84,8 @@ reference value_type&
const_reference const value_type&
pointer value_type*
const_pointer const value_type*
iterator Bi-directional iterator
const_iterator Constant bi-directional iterator
iterator Forward iterator
const_iterator Constant forward iterator
```
## Constructors

View File

@ -96,26 +96,6 @@ const_iterator cend() const
**Description**
Returns an iterator to the end of the list.
---
```cpp
iterator rbegin()
const_iterator rbegin() const
const_iterator crbegin() const
```
**Description**
Returns a reverse iterator to the beginning of the list.
---
```cpp
iterator rend()
const_iterator rend() const
const_iterator crend() const
```
**Description**
Returns a reverse iterator to the end of the list.
## Capacity
```cpp

View File

@ -52,7 +52,7 @@ Creates the list from the range [`begin`, `end`) of node links.
```cpp
template <typename... TLinks>
intrusive_list(TLink& first, TLinks&... links))
intrusive_list(TLink& first, TLinks&... links)
```
**Description**
Creates the list from node link references.
@ -95,26 +95,6 @@ const_iterator cend() const
**Description**
Returns an iterator to the end of the list.
---
```cpp
iterator rbegin()
const_iterator rbegin() const
const_iterator crbegin() const
```
**Description**
Returns a reverse iterator to the beginning of the list.
---
```cpp
iterator rend()
const_iterator rend() const
const_iterator crend() const
```
**Description**
Returns a reverse iterator to the end of the list.
## Capacity
```cpp

View File

@ -43,7 +43,7 @@ constexpr auto make_flat_map(TValues&&... values)
### Example
```cpp
auto data = etl::make_map<int. int>(etl::pair{0, 1}, etl::pair{2, 3},
auto data = etl::make_map<int, int>(etl::pair{0, 1}, etl::pair{2, 3},
etl::pair{4, 5}, etl::pair{6, 7});
```

View File

@ -43,7 +43,7 @@ constexpr auto make_flat_map(TValues&&... values)
### Example
```cpp
auto data = etl::make_map<int. int>(etl::pair{0, 1}, etl::pair{2, 3},
auto data = etl::make_multimap<int, int>(etl::pair{0, 1}, etl::pair{2, 3},
etl::pair{4, 5}, etl::pair{6, 7});
```

View File

@ -47,7 +47,7 @@ constexpr auto make_reference_flat_map(TValues&&... values)
```
### Example
auto data = etl::make_reference_flat_map<int. int>(etl::pair{0, 1}, etl::pair{2, 3},
auto data = etl::make_reference_flat_map<int, int>(etl::pair{0, 1}, etl::pair{2, 3},
etl::pair{4, 5}, etl::pair{6, 7});
## Member types

View File

@ -47,7 +47,7 @@ constexpr auto make_reference_flat_map(TValues&&... values)
```
### Example
auto data = etl::make_reference_flat_map<int. int>(etl::pair{0, 1}, etl::pair{2, 3},
auto data = etl::make_reference_flat_multimap<int, int>(etl::pair{0, 1}, etl::pair{2, 3},
etl::pair{4, 5}, etl::pair{6, 7});
## Member types

View File

@ -109,8 +109,8 @@ Returns the maximum possible size of the queue.
```cpp
bool push(const T& value)
bool push(T&& value)
bool push_from_locked(const T& value)
bool push_from_locked(T&& value)
bool push_from_unlocked(const T& value)
bool push_from_unlocked(T&& value)
```
**Description**
Pushes a value to the back of the queue.

View File

@ -11,6 +11,7 @@ This is a C function that copies `count` characters , starting from `a`, to a bu
size_t CFunctionCopyToBuffer(char* start, size_t count)
{
size_t i = 0;
char* p = start;
while (i < count)
{
*p++ = 'a' + i;

View File

@ -233,17 +233,17 @@ ETL_CONSTEXPR14 bool operator !=(TIterator& lhs,
std::list<int> data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
// The start position to loop from.
std::list<int>::const_iterator> start = data.begin();
std::list<int>::const_iterator start = data.begin();
std::advance(start, 2);
// Create circular iterators.
etl::circular_iterator<std::list<int>::const_iterator>> cli(data.begin(), data.end(), start);
etl::circular_iterator<std::list<int>::const_reverse_iterator>> clri(data.rbegin(), data.rend);
etl::circular_iterator<std::list<int>::const_iterator> cli(data.begin(), data.end(), start);
etl::circular_iterator<std::list<int>::const_reverse_iterator> clri(data.rbegin(), data.rend());
// Loop 10 times, taking every third value, starting from the third element for the forward iterator and from the end for the reverse iterator.
for (int = 0; i < 10; ++i)
for (int i = 0; i < 10; ++i)
{
std::cout << "(" << *cli << "," << *clrl << ")";
std::cout << "(" << *cli << "," << *clri << ")";
std::advance(cli, 3);
std::advance(clri, 3);
}

View File

@ -75,7 +75,7 @@ etl::fixed_iterator<char*> uart_read(UART_READ);
etl::fixed_iterator<char*> uart_write(UART_WRITE);
// Read 20 characters from the port.
std::copy_n(uart_read, 20, std::back_inserter<char>(buffer));
std::copy_n(uart_read, 20, std::back_inserter(buffer));
// Write the buffer of characters to the port.
std::copy(buffer.begin(), buffer.end(), uart_write);

View File

@ -89,8 +89,8 @@ power_of_2_round_up<9> -> 16
C++17 and above
```cpp
template <size_t N, size_t POWER>
inline constexpr size_t power_of_2_round_up_v = power_of_2_round_up<N, POWER>::value;
template <size_t N>
inline constexpr size_t power_of_2_round_up_v = power_of_2_round_up<N>::value;
```
## power_of_2_round_down
@ -111,8 +111,8 @@ power_of_2_round_down<9> -> 8
C++17 and above
```cpp
template <size_t N, size_t POWER>
inline constexpr size_t power_of_2_round_down_v = power_of_2_round_down<N, POWER>::value;
template <size_t N>
inline constexpr size_t power_of_2_round_down_v = power_of_2_round_down<N>::value;
```
## is_power_of_2
@ -127,8 +127,8 @@ Defines the member value to true if N is a power of 2, otherwise false.
C++17 and above
```cpp
template <size_t N, size_t POWER>
inline constexpr size_t is_power_of_2_v = is_power_of_2<N, POWER>::value;
template <size_t N>
inline constexpr size_t is_power_of_2_v = is_power_of_2<N>::value;
```
## sqrt
@ -144,7 +144,7 @@ Defines the member value as the largest integer that, when squared, is at less t
C++17 and above
```cpp
template <size_t N, size_t I = 1>
inline constexpr size_t sqrt_v = sqrt<N, POWER>::value;
inline constexpr size_t sqrt_v = sqrt<N, I>::value;
```
## factorial

View File

@ -10,8 +10,8 @@ title: "limiter"
Limits an input range.
```cpp
template <typename TInput, typename TCompare = etl::less<TInput> >
class limit : public etl::unary_function<TInput, TInput>
template <typename TInput, typename TLimit = etl::private_limiter::limit<TInput> >
class limiter : public etl::unary_function<TInput, TInput>
```
`TInput` The input data type.

View File

@ -32,7 +32,7 @@ etl::ireference_counted_message* allocate(const TMessage& message)
---
```cpp
explicit shared_message(etl::ireference_coutnted_message& message)
explicit shared_message(etl::ireference_counted_message& message)
```
Construct from a reference counted message.

View File

@ -8,12 +8,14 @@ title: "singleton_base"
Allows creation of a singleton base class.
The class to apply to needs to derive from it. I.e. ``singleton_base`` is intrusive.
```cpp
etl::singleton_base<typename T>
```
`T` The type to use as a singleton.
The class derived derived from this must call the constructor with the instance of itself.
The class derived from this must call the constructor with the instance of itself.
Multiple calls to the constructor will result in an `etl::singleton_base_already_created` assertion.
Before the constructor Is called, the singleton is in the invalid state.
@ -40,12 +42,15 @@ Returns `true` if the instance is has been attached, otherwise `false`.
```cpp
class MyType : public etl::singleton_base<MyType>
{
MyType()
: etl::singleton_base<MyType>(*this)
public:
MyType()
: etl::singleton_base<MyType>(*this)
{
}
};
MyType my_instance; // Construct the singleton instance.
bool is_valid;
is_valid = MyType::is_valid(); // true

View File

@ -8,6 +8,8 @@ title: "singleton"
Allows creation of a singleton, with deterministic construction and destruction.
Non-intrusive to the class to apply to.
```cpp
etl::singleton<typename T>
```

View File

@ -197,7 +197,7 @@ Test test;
using callback_type = etl::icallback_timer_atomic<std::atomic_int32_t>::callback_type;
callback_type member_callback = callback_type::create<Test, test, &Test::callback> member_callback;
callback_type member_callback = callback_type::create<Test, test, &Test::callback>();
//***************************************************************************
// Free function callback via etl::function
@ -206,10 +206,10 @@ int free_ticks1 = 0;
void free_callback1()
{
++free_ticks;
++free_ticks1;
}
callback_type free_callback1 = callback_type::create<free_function_callback>();
callback_type free_function_callback = callback_type::create<free_callback1>();
//***************************************************************************
// Free function callback via function pointer

View File

@ -250,9 +250,9 @@ public:
int ticks;
};
using callback_type = etl::icallback_timer_atomic::callback_type;
using callback_type = etl::icallback_timer_locked::callback_type;
callback_type member_callback = callback_type::create<Test, test, &Test::callback> member_callback;
callback_type member_callback = callback_type::create<Test, test, &Test::callback>();
//***************************************************************************
// Free function callback via etl::function
@ -261,15 +261,15 @@ int free_ticks1 = 0;
void free_callback1()
{
++free_ticks;
++free_ticks1;
}
callback_type free_callback1 = callback_type::create<free_function_callback>();
callback_type free_function_callback = callback_type::create<free_callback1>();
//***************************************************************************
// Timer controller.
//***************************************************************************
etl::callback_timer<2> timer_controller;
etl::callback_timer_deferred_locked<2, 4> timer_controller;
//***************************************************************************
// The main loop.
@ -286,7 +286,6 @@ int main()
timer_controller.start(id1);
timer_controller.start(id2);
timer_controller.start(id3);
timer_controller.enable(true);

View File

@ -19,8 +19,8 @@ The framework relies on a supplied interrupt enable/disable guard type. With thi
**Defines the following classes**
```cpp
etl::icallback_timer_atomic<uint_least8_t MAX_TIMERS, typename TInterruptGuard>
etl::callback_timer_atomic<typename TInterruptGuard>
etl::icallback_timer_interrupt<uint_least8_t MAX_TIMERS, typename TInterruptGuard>
etl::callback_timer_interrupt<typename TInterruptGuard>
```
Uses definitions from `timer.h`.
@ -215,9 +215,9 @@ struct InterruptGuard
int state;
};
using callback_type = etl::icallback_timer_atomic<InterruptGuard>::callback_type;
using callback_type = etl::icallback_timer_interrupt<InterruptGuard>::callback_type;
callback_type member_callback = callback_type::create<Test, test, &Test::callback> member_callback;
callback_type member_callback = callback_type::create<Test, test, &Test::callback>();
//***************************************************************************
// Free function callback via etl::function
@ -226,10 +226,10 @@ int free_ticks1 = 0;
void free_callback1()
{
++free_ticks;
++free_ticks1;
}
callback_type free_callback1 = callback_type::create<free_function_callback>();
callback_type free_function_callback = callback_type::create<free_callback1>();
//***************************************************************************
// Free function callback via function pointer
@ -244,7 +244,7 @@ void free_callback2()
//***************************************************************************
// Timer controller.
//***************************************************************************
etl::callback_timer_atomic<2, InterruptGuard> timer_controller;
etl::callback_timer_interrupt<2, InterruptGuard> timer_controller;
//***************************************************************************
// The main loop.

View File

@ -228,9 +228,9 @@ public:
int ticks;
};
using callback_type = etl::icallback_timer_atomic::callback_type;
using callback_type = etl::icallback_timer_locked::callback_type;
callback_type member_callback = callback_type::create<Test, test, &Test::callback> member_callback;
callback_type member_callback = callback_type::create<Test, test, &Test::callback>();
//***************************************************************************
// Free function callback via etl::function
@ -239,15 +239,15 @@ int free_ticks1 = 0;
void free_callback1()
{
++free_ticks;
++free_ticks1;
}
callback_type free_callback1 = callback_type::create<free_function_callback>();
callback_type free_function_callback = callback_type::create<free_callback1>();
//***************************************************************************
// Timer controller.
//***************************************************************************
etl::callback_timer<2> timer_controller;
etl::callback_timer_locked<2> timer_controller;
//***************************************************************************
// The main loop.
@ -264,7 +264,6 @@ int main()
timer_controller.start(id1);
timer_controller.start(id2);
timer_controller.start(id3);
timer_controller.enable(true);

View File

@ -245,7 +245,7 @@ int free_ticks1 = 0;
void free_callback1()
{
++free_ticks;
++free_ticks1;
}
etl::function_fv<free_callback1> free_function_callback;

View File

@ -19,8 +19,8 @@ The framework relies on a supplied interrupt enable/disable guard type. With thi
**Defines the following classes**
```cpp
etl::imessage_timer_atomic<uint_least8_t MAX_TIMERS, typename TInterruptGuard>
etl::message_timer_atomic<typename TInterruptGuard>
etl::imessage_timer_interrupt<uint_least8_t MAX_TIMERS, typename TInterruptGuard>
etl::message_timer_interrupt<typename TInterruptGuard>
```
The `TInterruptGuard` type must disable and save the interrupt state on construction, and restore on destruction.
@ -257,7 +257,7 @@ class Bus1 : public etl::message_bus<1>
Router1 router1;
Bus1 bus1;
etl::message_timer_atomic<3, InterruptGuard> timer_controller;
etl::message_timer_interrupt<3, InterruptGuard> timer_controller;
//***************************************************************************
// The main loop.

View File

@ -263,7 +263,7 @@ class Bus1 : public etl::message_bus<1>
Router1 router1;
Bus1 bus1;
etl::message_timer_atomic<3> timer_controller;
etl::message_timer_locked<3> timer_controller;
//***************************************************************************
// The main loop.

View File

@ -35,8 +35,8 @@ enum VectorId
USART1_IRQ_HANDLER = 52,
USART2_IRQ_HANDLER = 53,
VECTOR_ID_END,
OFFSET = TIM1_CC_IRQ_HANDLER,
RANGE = VECTOR_ID_END - VECTOR_ID_OFFSET,
VECTOR_ID_OFFSET = TIM1_CC_IRQ_HANDLER,
VECTOR_ID_RANGE = VECTOR_ID_END - VECTOR_ID_OFFSET,
};
typedef etl::callback_service<VECTOR_ID_RANGE, VECTOR_ID_OFFSET> InterruptVectors;

View File

@ -302,8 +302,8 @@ Bus bus;
// to store reference counted messages in.
// The reference counted message parameters type for the messages we will use.
using message_parameters_small = MessagePool::pool_message_parameters<Message1
Message3>;
using message_parameters_small = MessagePool::pool_message_parameters<Message1,
Message3>;
using message_parameters_large = MessagePool::pool_message_parameters<Message2>;

View File

@ -28,7 +28,7 @@ class Triangle;
// Pure virtual 'visit' functions will be defined for the Square,
// Circle, and Triangle types.
//*****************************************************************
class Shape_Visitor : public etl:visitor<Square, Circle, Triangle>
class Shape_Visitor : public etl::visitor<Square, Circle, Triangle>
{
};
```

View File

@ -50,12 +50,12 @@ template <typename T1, typename T2, typename T3>
struct Test
{
// Defines smallest_t as the smallest type of T1, T2 and T3.
typedef typename etl::smallest_type<T1, T2, T3>::type largest_t;
typedef typename etl::smallest_type<T1, T2, T3>::type smallest_t;
enum
{
// Defines size as the size of the largest type.
size = etl::largest_type<T1, T2, T3>::size;
// Defines size as the size of the smallest type.
size = etl::smallest_type<T1, T2, T3>::size;
}
};
```

View File

@ -43,9 +43,9 @@ Swaps the elements pointed to by two iterators.
## swap_ranges
```cpp
template <typename T1terator1, typename TIterator2>
TIterator2 swap_ranges(T1terator1 first1,
T1terator1 last1,
template <typename TIterator1, typename TIterator2>
TIterator2 swap_ranges(TIterator1 first1,
TIterator1 last1,
TIterator2 first2)
```
**Description**
@ -116,10 +116,10 @@ A safer version that will stop copying when either `n` items have been copied o
```cpp
template <typename TInputIterator, typename TSize1, typename TOutputIterator, typename TSize2>
TOutputIterator copy_n_s(TIterator i_begin,
TOutputIterator copy_n_s(TInputIterator i_begin,
TSize1 n1,
TOutputIterator o_begin,
TSize1 n2,)
TSize2 n2)
```
**Description**
A safer version that will stop copying when either n1 or n2 items have been copied.

View File

@ -247,7 +247,7 @@ namespace etl
short s = stream.read_unchecked<short , 11U>();
int32_t i = stream.read_unchecked<int32_t, 25U>();
return CustomType { c.value(), s.value(), i.value() };
return CustomType { c, s, i };
}
}
@ -257,6 +257,6 @@ etl::bit_stream_reader bit_stream(storage.data(), storage.size());
// Read unchecked values from the stream.
char c = etl::read_unchecked<char>(bit_stream, 6U);
unsigned short s = etl::read_unchecked<unsigned short>(bit_stream, 13U);
CustomType custom = etl::read_unchecked<Custom>(bit_stream);
CustomType custom = etl::read_unchecked<CustomType>(bit_stream);
int32_t i = etl::read_unchecked<>(bit_stream, 23U);
```

View File

@ -161,7 +161,7 @@ Calls the wrapped function with the forwarded parameters.
### Example
```cpp
void int Function(int i)
int Function(int i)
{
return i;
}