3 Forward declares `boost::hana::at` and `boost::hana::at_c`.
5 @copyright Louis Dionne 2013-2017
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_FWD_AT_HPP
11 #define BOOST_HANA_FWD_AT_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/core/when.hpp>
19 BOOST_HANA_NAMESPACE_BEGIN
20 //! Returns the `n`th element of an iterable.
21 //! @ingroup group-Iterable
23 //! Given an `Iterable` and an `IntegralConstant` index, `at` returns the
24 //! element located at the index in the linearization of the iterable.
25 //! Specifically, given an iterable `xs` with a linearization of
26 //! `[x1, ..., xN]`, `at(xs, k)` is equivalent to `xk`.
28 //! If the `Iterable` actually stores the elements it contains, `at` is
29 //! required to return a lvalue reference, a lvalue reference to const
30 //! or a rvalue reference to the matching element, where the type of
31 //! reference must match that of the iterable passed to `at`. If the
32 //! `Iterable` does not store the elements it contains (i.e. it generates
33 //! them on demand), this requirement is dropped.
37 //! The iterable in which an element is retrieved. The iterable must
38 //! contain at least `n + 1` elements.
41 //! A non-negative `IntegralConstant` representing the 0-based index of
42 //! the element to return. It is an error to call `at` with an index that
43 //! out of bounds of the iterable.
48 //! @include example/at.cpp
49 #ifdef BOOST_HANA_DOXYGEN_INVOKED
50 constexpr auto at = [](auto&& xs, auto const& n) -> decltype(auto) {
51 return tag-dispatched;
54 template <typename It, typename = void>
55 struct at_impl : at_impl<It, when<true>> { };
58 template <typename Xs, typename N>
59 constexpr decltype(auto) operator()(Xs&& xs, N const& n) const;
65 //! Equivalent to `at`; provided for convenience.
66 //! @ingroup group-Iterable
70 //! `hana::at_c<n>` is an overloaded function, not a function object.
71 //! Hence, it can't be passed to higher-order algorithms. This is done
72 //! for compile-time performance reasons.
77 //! @include example/at_c.cpp
78 #ifdef BOOST_HANA_DOXYGEN_INVOKED
79 template <std::size_t n>
80 constexpr auto at_c = [](auto&& xs) {
81 return hana::at(forwarded(xs), hana::size_c<n>);
84 template <std::size_t n, typename Xs>
85 constexpr decltype(auto) at_c(Xs&& xs);
87 BOOST_HANA_NAMESPACE_END
89 #endif // !BOOST_HANA_FWD_AT_HPP