tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
begin.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_ITERATOR_BEGIN_HPP
5#define TETL_ITERATOR_BEGIN_HPP
6
7#include <etl/_cstddef/size_t.hpp>
8
9namespace etl {
10
11/// \brief Returns an iterator to the beginning of the given container c or
12/// array array. These templates rely on `C::begin()` having a reasonable
13/// implementation. Returns exactly c.begin(), which is typically an iterator to
14/// the beginning of the sequence represented by c. If C is a standard
15/// Container, this returns `C::iterator` when c is not const-qualified, and
16/// `C::const_iterator` otherwise. Custom overloads of begin may be provided for
17/// classes that do not expose a suitable begin() member function, yet can be
18/// iterated.
19/// \ingroup iterator
20template <typename C>
21constexpr auto begin(C& c) -> decltype(c.begin())
22{
23 return c.begin();
24}
25
26/// \ingroup iterator
27template <typename C>
28constexpr auto begin(C const& c) -> decltype(c.begin())
29{
30 return c.begin();
31}
32
33/// \ingroup iterator
34template <typename T, etl::size_t N>
35constexpr auto begin(T (&array)[N]) noexcept -> T*
36{
37 return &array[0];
38}
39
40/// \ingroup iterator
41template <typename C>
42constexpr auto cbegin(C const& c) noexcept(noexcept(begin(c))) -> decltype(begin(c))
43{
44 return begin(c);
45}
46
47} // namespace etl
48
49#endif // TETL_ITERATOR_BEGIN_HPP
constexpr auto cbegin(C const &c) noexcept(noexcept(begin(c))) -> decltype(begin(c))
Definition begin.hpp:42
constexpr auto begin(C const &c) -> decltype(c.begin())
Definition begin.hpp:28
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:21
constexpr auto begin(T(&array)[N]) noexcept -> T *
Definition begin.hpp:35
Definition adjacent_find.hpp:9