Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:52:53

0001 /*!
0002 @file
0003 Forward declares `boost::hana::at` and `boost::hana::at_c`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_FWD_AT_HPP
0011 #define BOOST_HANA_FWD_AT_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/core/when.hpp>
0015 
0016 #include <cstddef>
0017 
0018 
0019 namespace boost { namespace hana {
0020     //! Returns the `n`th element of an iterable.
0021     //! @ingroup group-Iterable
0022     //!
0023     //! Given an `Iterable` and an `IntegralConstant` index, `at` returns the
0024     //! element located at the index in the linearization of the iterable.
0025     //! Specifically, given an iterable `xs` with a linearization of
0026     //! `[x1, ..., xN]`, `at(xs, k)` is equivalent to `xk`.
0027     //!
0028     //! If the `Iterable` actually stores the elements it contains, `at` is
0029     //! required to return a lvalue reference, a lvalue reference to const
0030     //! or a rvalue reference to the matching element, where the type of
0031     //! reference must match that of the iterable passed to `at`. If the
0032     //! `Iterable` does not store the elements it contains (i.e. it generates
0033     //! them on demand), this requirement is dropped.
0034     //!
0035     //!
0036     //! @param xs
0037     //! The iterable in which an element is retrieved. The iterable must
0038     //! contain at least `n + 1` elements.
0039     //!
0040     //! @param n
0041     //! A non-negative `IntegralConstant` representing the 0-based index of
0042     //! the element to return. It is an error to call `at` with an index that
0043     //! out of bounds of the iterable.
0044     //!
0045     //!
0046     //! Example
0047     //! -------
0048     //! @include example/at.cpp
0049 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0050     constexpr auto at = [](auto&& xs, auto const& n) -> decltype(auto) {
0051         return tag-dispatched;
0052     };
0053 #else
0054     template <typename It, typename = void>
0055     struct at_impl : at_impl<It, when<true>> { };
0056 
0057     struct at_t {
0058         template <typename Xs, typename N>
0059         constexpr decltype(auto) operator()(Xs&& xs, N const& n) const;
0060     };
0061 
0062     BOOST_HANA_INLINE_VARIABLE constexpr at_t at{};
0063 #endif
0064 
0065     //! Equivalent to `at`; provided for convenience.
0066     //! @ingroup group-Iterable
0067     //!
0068     //!
0069     //! @note
0070     //! `hana::at_c<n>` is an overloaded function, not a function object.
0071     //! Hence, it can't be passed to higher-order algorithms. This is done
0072     //! for compile-time performance reasons.
0073     //!
0074     //!
0075     //! Example
0076     //! -------
0077     //! @include example/at_c.cpp
0078 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0079     template <std::size_t n>
0080     constexpr auto at_c = [](auto&& xs) {
0081         return hana::at(forwarded(xs), hana::size_c<n>);
0082     };
0083 #else
0084     template <std::size_t n, typename Xs>
0085     constexpr decltype(auto) at_c(Xs&& xs);
0086 #endif
0087 }} // end namespace boost::hana
0088 
0089 #endif // !BOOST_HANA_FWD_AT_HPP