Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
begin.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_BEGIN_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_BEGIN_HPP_
7
8// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
9// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
10
11// IWYU pragma: private, include <iterator>
12// IWYU pragma: friend "stdlib_detail/.*"
13
14#include "stdlib/include/stdlib_detail/cstddef.hpp"
15#include "stdlib/include/stdlib_detail/declval.hpp"
16
17namespace std {
18
19// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
20// parasoft-begin-suppress AUTOSAR-A5_0_3-a "False positive: there is only 1 level of pointer indirection"
21/// @brief Obtain a pointer to the first element of the array.
22/// @tparam Element The element type of the array
23/// @tparam Size The size of the array
24/// @param array The array
25/// @return A pointer to the first element of @c array
26template <typename Element, size_t Size>
27// NOLINTNEXTLINE(hicpp-avoid-c-arrays)
28constexpr auto begin(Element (&array)[Size]) noexcept -> Element* {
29 return array;
30}
31// parasoft-end-suppress AUTOSAR-A5_0_3-a
32// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
33
34// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
35/// @brief Obtain the result of calling @c cont.begin() on a container
36/// @tparam Container The type of the container
37/// @param cont The container object
38/// @return The result of @c cont.begin()
39template <typename Container>
40constexpr auto begin(Container& cont) noexcept(noexcept(std::declval<Container&>().begin())) -> decltype(cont.begin()) {
41 return cont.begin();
42}
43// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
44
45// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
46/// @brief Obtain the result of calling @c cont.begin() on a @c const container
47/// @tparam Container The type of the container
48/// @param cont The container object
49/// @return The result of @c cont.begin()
50template <typename Container>
51constexpr auto begin(Container const& cont) noexcept(noexcept(std::declval<Container const&>().begin()))
52 -> decltype(cont.begin()) {
53 return cont.begin();
54}
55// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
56
57// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
58/// @brief Equivalent to invoking @c begin(cont) on a @c const container
59/// @tparam Container The type of the container
60/// @param cont The container object
61/// @return The result of @c cont.begin()
62// parasoft-begin-suppress AUTOSAR-A5_0_3 "False positive: No pointer indirection here"
63template <typename Container>
64constexpr auto cbegin(Container const& cont) noexcept(noexcept(::std::begin(std::declval<Container const&>())))
65 -> decltype(::std::begin(cont)) {
66 return ::std::begin(cont);
67}
68// parasoft-end-suppress AUTOSAR-A5_0_3
69// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
70
71} // namespace std
72
73#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_BEGIN_HPP_
constexpr auto begin(Container const &cont) noexcept(noexcept(std::declval< Container const & >().begin())) ->
Obtain the result of calling cont.begin() on a const container.
Definition begin.hpp:51
constexpr auto begin(Element(&array)[Size]) noexcept -> Element *
Obtain a pointer to the first element of the array.
Definition begin.hpp:28
constexpr auto cbegin(Container const &cont) noexcept(noexcept(::std::begin(std::declval< Container const & >()))) ->
Equivalent to invoking begin(cont) on a const container.
Definition begin.hpp:64
constexpr auto begin(Container &cont) noexcept(noexcept(std::declval< Container & >().begin())) ->
Obtain the result of calling cont.begin() on a container.
Definition begin.hpp:40
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition result.hpp:1827