etl/docs/iterators/Iterator.md
John Wellbelove 4a88884b39
Issue/add hugo support for documentation (#1449)
* Add ranges

* Initial Hugo setup

* Work in progress

* Added selection for local or remote site

* Updated to 'light' theme

* Changed to using Hextra Hugo theme

* Changed to using Hextra Hugo theme

* Changed to Hextra Hugo theme

* Change to Hextra Hugo theme

* Updated Hugo setup.

* Updated Hugo setup.

# Conflicts:
#	docs/releases/_index.md

* Work in progress

* Added new fonts

Added new documentation

* Latest documentation updates

* Latest documentation updates

# Conflicts:
#	docs/containers/array.md
#	docs/containers/array_view.md
#	docs/containers/array_wrapper.md
#	docs/containers/bip_buffer_spsc_atomic.md
#	docs/containers/bitset.md
#	docs/containers/indirect_vector.md
#	docs/containers/vector.md
#	docs/getting-started/compilers.md

* Added bloom_filter markdown doc

* Added more documentation

Updated CSS for light and dark modes

* Fixed some menus

Added mode documentation files

* Updated CSS rules

Added badges to home page
Added uniqur_ptr + pool tutorial

* Fixed formatting on the home page markdown

Modified light amd dark code formatting

* Updated unique_ptr-with-pool

* Added container and shared message tutorials

* Updates to documentation

* Added const_multimap

* Updated source-formatting.md

* Added initial raw text files form Web site editor

* Innore coverage build directory

* Exported raw text documentation files from the web site editor

* Hugo updates

* Added Hugo intalation and markdown descriptions

* More addition to the documentation

* Added closure.md and updates to delegate.md

* Added format.md

* Added documentation for etl::delegate_observable, etl::function, Base64 codec

* Added io_port documentation

* Added basic_format_spec

* Added documentation for string_stream and string utilities.

* Added more documentation

Updated the documentation CSS

* Added documentation for clocks, day, duration

* Added more documentation for chrono classes

Updated callouts

* More chrono documentation

* Completed chrono documentation

* Maths functions documentation

* Completed maths documentation

* Completed maths documentation

* Completed maths documentation

* Completed maths documentation

* Added multiple documentation files

* Added iterator.md

* Added debug_count.md and versions.md

* Added debug_count.md and versions.md

* Added more documentation

* More documentation

* Added some design pattern documentation

Modified some of the layout files
Modified the About documentation

* Converted more documentation pages

Modified the site CSS

* Added more documentation

Moced some documentation files to new directories

* Added more documentation

Tweaks to CSS

* Added callback_timer_deferred_locked documentation

* Added callback_timer_locked documentation

* More documentation updates

* More documentation updates

* More documentation updates

* New documentation files.

Harmonised file name format

* New documentation files.

* Multiple document updates

* Multiple document updates

* Final conversion of web pages

* Updates before PR

* Updates before PR

* Updates before PR

# Conflicts:
#	docs/blog/_index.md

* Final pre PR updates

* Updates to message framework documentation

* Renamed directory

* Fix spelling

* Added author and date to blog files

Moved documentation files merged from development

* Fixed 'Description' typo

* Fix typos

# Conflicts:
#	docs/IO/io_port.md
#	docs/containers/sets/const-multiset.md
#	docs/containers/sets/const-set.md
#	docs/maths/correlation.md
#	docs/maths/gamma.md

* Renamed two files to lower case

* Minor renaming

* Added author and date

* Updated callout on bresenham_line.md

Added support for showing the ETL version on the documentation first page, by copying the version.txt file as a hugo asset.
Updated the Python 'update_release.py' to copy 'version.txt'

* Replace space in filename with hyphen.

Added more information to hugo-commands.md

* Replace space in filename with hyphen.

Added more information to hugo-commands.md

# Conflicts:
#	docs/getting-started/view-the-docs-locally/hugo-commands.md

* Added a link to pseudo_moving_average.md

* Updated title pages for groups

* Fixed missing 404 for non-existent pages

* Fixed coordinate variable names in the 'Calculating the intersection' example

---------

Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com>
Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.co.uk>
2026-06-06 13:12:44 +01:00

470 lines
10 KiB
Markdown

---
title: iterator
---
{{< callout type="info">}}
Header: `iterator.h`
Since: `TBC`
{{< /callout >}}
A set of templates to more easily determine the properties of iterator types.
## Input iterators
```cpp
is_input_iterator<T>::value
```
**Description**
Is `T` an input iterator?
---
```cpp
is_input_iterator_concept<T>::value
```
**Description**
Can `T` be used as an input iterator?
## Output iterators
```cpp
is_output_iterator<T>::value
```
**Description**
Is `T` an output iterator?
---
```cpp
is_output_iterator_concept<T>::value
```
**Description**
Can `T` be used as an output iterator?
## Forward iterators
```cpp
is_forward_iterator<T>::value
```
**Description**
Is `T` a forward iterator?
---
```cpp
is_forward_iterator_concept<T>::value
```
**Description**
Can `T` be used as an forward iterator?
## Bidirectional iterators
```cpp
is_bidirectional_iterator<T>::value
```
**Description**
Is `T` a bidirectional iterator?
---
```cpp
is_bidirectional_iterator_concept<T>::value
```
**Description**
Can `T` be used as a bidirectional iterator?
## Random iterators
```cpp
is_random_iterator<T>::value
```
**Description**
Is `T` a random iterator?
```cpp
is_random_iterator_concept<T>::value
```
**Description**
Can `T` be used as a random iterator?
## Iterator tags
```cpp
struct input_iterator_tag
struct output_iterator_tag
struct forward_iterator_tag
struct bidirectional_iterator_tag
struct random_access_iterator_tag
```
## Iterator traits
```cpp
template <typename TIterator>
struct iterator_traits
```
**Defined types**
```cpp
iterator_category
value_type
difference_type
pointer
reference
```
## advance
```cpp
template <typename TIterator, typename TDistance>
ETL_CONSTEXPR17 void advance(TIterator& itr, TDistance n)
```
## prev
```cpp
template<typename TIterator>
ETL_CONSTEXPR17 TIterator prev(TIterator itr,
typename etl::iterator_traits<TIterator>::difference_type n = 1)
```
## next
```cpp
template<typename TIterator>
ETL_CONSTEXPR17 TIterator next(TIterator itr,
typename etl::iterator_traits<TIterator>::difference_type n = 1)
```
## distance
```cpp
template<typename TIterator>
ETL_CONSTEXPR17 typename std::iterator_traits<TIterator>::difference_type
distance(TIterator first, TIterator last)
```
## iterator
A base class provided to simplify definitions of the required types for iterators.
https://en.cppreference.com/w/cpp/iterator/iterator
```cpp
template <typename TCategory,
typename T,
typename TDistance = ptrdiff_t,
typename TPointer = T* ,
typename TReference = T&>
struct iterator
```
**Defined types**
```cpp
value_type
difference_type
pointer
reference
iterator_category
```
## reverse_iterator
An iterator adaptor that reverses the direction of a given iterator
```cpp
template <typename TIterator>
class reverse_iterator
```
**Defined types**
```cpp
iterator_category
value_type
iterator_type
difference_type
pointer
reference
```
## move_iterator
An iterator adaptor that converts the value returned by the underlying iterator into an rvalue.
C++11 or above.
```cpp
template <typename TIterator>
class move_iterator
```
**Defined types**
```cpp
iterator_category
value_type
iterator_type
difference_type
pointer
reference
```
## back_insert_iterator
Inserts using `push_back`.
```cpp
template <typename TContainer>
class back_insert_iterator
```
---
```cpp
template <typename TContainer>
ETL_NODISCARD
ETL_CONSTEXPR14
etl::back_insert_iterator<TContainer> back_inserter(TContainer& container)
```
## front_insert_iterator
Inserts using `push_front`.
```cpp
template <typename TContainer>
class front_insert_iterator
```
---
```cpp
template <typename TContainer>
ETL_NODISCARD
ETL_CONSTEXPR14
etl::front_insert_iterator<TContainer> front_inserter(TContainer& container)
```
## push_insert_iterator
Inserts using `push`.
```cpp
template <typename TContainer>
class push_insert_iterator
```
---
```cpp
template <typename TContainer>
ETL_NODISCARD
ETL_CONSTEXPR14
etl::push_insert_iterator<TContainer> push_inserter(TContainer& container)
```
## begin
```cpp
template <typename TContainer>
ETL_CONSTEXPR typename TContainer::iterator begin(TContainer& container)
Get the 'begin' iterator of `container`.
```
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP11_NOT_SUPPORTED`.
---
```cpp
template <typename TContainer>
ETL_CONSTEXPR typename TContainer::const_iterator begin(const TContainer& container)
```
Get the `begin` `const_iterator` of `container`.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP11_NOT_SUPPORTED`.
---
```cpp
template <typename TContainer>
ETL_CONSTEXPR typename TContainer::const_iterator cbegin(const TContainer& container)
```
Get the `begin` `const_iterator` of `container`.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP11_NOT_SUPPORTED`.
---
```cpp
template <typename TValue, size_t Array_Size>
ETL_CONSTEXPR TValue* begin(TValue(&data)[Array_Size])
```
Get the `begin` `pointer` for an array.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP11_NOT_SUPPORTED`.
---
```cpp
template <typename TValue, size_t Array_Size>
ETL_CONSTEXPR const TValue* begin(const TValue(&data)[Array_Size])
```
Get the `begin` `const pointer` for an array.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP11_NOT_SUPPORTED`.
---
```cpp
template <typename TValue, size_t Array_Size>
ETL_CONSTEXPR const TValue* cbegin(const TValue(&data)[Array_Size])
```
Get the `begin` `const pointer` for an array.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP11_NOT_SUPPORTED`.
---
```cpp
template <typename TContainer>
ETL_CONSTEXPR typename TContainer::reverse_iterator rbegin(TContainer& container)
```
Get the `begin` `reverse_iterator` of `container`.
Enabled if ETL_NOT_USING_STL or ETL_CPP14_NOT_SUPPORTED.
---
```cpp
template <typename TContainer>
ETL_CONSTEXPR typename TContainer::const_reverse_iterator rbegin(const TContainer& container)
```
Get the `begin` `const_reverse_iterator` of `container`.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP14_NOT_SUPPORTED`.
---
```cpp
template <typename TContainer>
ETL_CONSTEXPR typename TContainer::const_reverse_iterator crbegin(const TContainer& container)
```
Get the `begin`' `const_reverse_iterator` of `container`.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP14_NOT_SUPPORTED`.
---
```cpp
template <typename TValue, size_t Array_Size>
ETL_OR_STD::reverse_iterator<TValue*> rbegin(TValue(&data)[Array_Size])
```
Get the `begin` `reverse_iterator` for an array.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP14_NOT_SUPPORTED`.
---
```cpp
template <typename TValue, size_t Array_Size>
ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<const TValue*> crbegin(const TValue(&data)[Array_Size])
```
Get the `begin` `const_reverse_iterator` for an array.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP14_NOT_SUPPORTED`.
## end
```cpp
template <typename TContainer>
ETL_CONSTEXPR typename TContainer::iterator end(TContainer& container)
```
Get the `end` iterator of `container`.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP11_NOT_SUPPORTED`.
---
```cpp
template <typename TContainer>
ETL_CONSTEXPR typename TContainer::const_iterator end(const TContainer& container)
```
Get the `end` `const_iterator` of `container`.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP11_NOT_SUPPORTED`.
---
```cpp
template <typename TContainer>
ETL_CONSTEXPR typename TContainer::const_iterator cend(const TContainer& container)
```
Get the `end` `const_iterator` of `container`.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP11_NOT_SUPPORTED`.
---
```cpp
template <typename TValue, size_t Array_Size>
ETL_CONSTEXPR TValue* end(TValue(&data)[Array_Size])
```
Get the `end` `pointer` for an array.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP11_NOT_SUPPORTED`.
---
```cpp
template <typename TValue, size_t Array_Size>
ETL_CONSTEXPR const TValue* end(const TValue(&data)[Array_Size])
```
Get the `end` `const pointer` of an array.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP11_NOT_SUPPORTED`.
---
```cpp
template <typename TValue, size_t Array_Size>
ETL_CONSTEXPR const TValue* cend(const TValue(&data)[Array_Size])
```
Get the `end` `const pointer` of an array.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP11_NOT_SUPPORTED`.
---
```cpp
template <typename TContainer>
ETL_CONSTEXPR typename TContainer::reverse_iterator rend(TContainer& container)
```
Get the `end` `reverse_iterator` of `container`.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP14_NOT_SUPPORTED`.
---
```cpp
template <typename TContainer>
ETL_CONSTEXPR typename TContainer::const_reverse_iterator rend(TContainer& container)
```
Get the `end` `const_reverse_iterator` of `container`.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP14_NOT_SUPPORTED`.
---
```cpp
template <typename TContainer>
ETL_CONSTEXPR typename TContainer::const_reverse_iterator crend(const TContainer& container)
```
Get the `end` `const_reverse_iterator` of `container`.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP14_NOT_SUPPORTED`.
---
```cpp
template <typename TValue, size_t Array_Size>
ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<TValue*> rend(TValue(&data)[Array_Size])
```
Get the `end` `reverse_iterator` for an array.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP14_NOT_SUPPORTED`.
---
```cpp
template <typename TValue, size_t Array_Size>
ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<const TValue*> crend(const TValue(&data)[Array_Size])
```
Get the `end` `const_reverse_iterator` for an array.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP14_NOT_SUPPORTED`.
## size
```cpp
template <typename TContainer>
ETL_CONSTEXPR typename TContainer::size_type size(const TContainer& container)
```
Get the size of a container.
Expects the container to have defined `size_type`.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP17_NOT_SUPPORTED`.
---
```cpp
template <typename TValue, size_t Array_Size>
ETL_CONSTEXPR size_t size(TValue(&)[Array_Size])
```
Get the size of an array in elements at run time, or compile time if C++11 or above.
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP17_NOT_SUPPORTED`.
---
```cpp
template <typename T, size_t Array_Size>
char(&array_size(T(&array)[Array_Size]))[Array_Size];
```
Get the size of an array in elements at compile time for C++03
Usage:- `sizeof(array_size(array))`
Enabled if `ETL_NOT_USING_STL` or `ETL_CPP17_NOT_SUPPORTED`.
---
`ETL_ARRAY_SIZE(a)` calls `sizeof(etl::array_size(a))`