tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
index.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_CONTAINER_INDEX_HPP
4#define TETL_CONTAINER_INDEX_HPP
5
10#include <etl/_iterator/end.hpp>
12
13namespace etl::detail {
14
17template <typename Range, typename Index>
18 requires(RandomAccessRange<Range>)
19constexpr auto index(Range&& rng, Index&& i) noexcept -> decltype(auto)
20{
21 using etl::begin;
22 using etl::end;
23
24 TETL_PRECONDITION(static_cast<etl::ptrdiff_t>(i) < (end(rng) - begin(rng)));
26}
27} // namespace etl::detail
28
29#endif // TETL_CONTAINER_INDEX_HPP
#define TETL_PRECONDITION(...)
Definition check.hpp:16
constexpr auto end(C &c) -> decltype(c.end())
Returns an iterator to the end (i.e. the element after the last element) of the given container c or ...
Definition end.hpp:14
constexpr auto begin(C &c) -> decltype(c.begin())
Returns an iterator to the beginning of the given container c or array array. These templates rely on...
Definition begin.hpp:20
TETL_BUILTIN_PTRDIFF ptrdiff_t
etl::ptrdiff_t is the signed integer type of the result of subtracting two pointers.
Definition ptrdiff_t.hpp:14
constexpr auto forward(remove_reference_t< T > &param) noexcept -> T &&
Forwards lvalues as either lvalues or as rvalues, depending on T. When t is a forwarding reference (a...
Definition forward.hpp:18