Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:53:03

0001 /*!
0002 @file
0003 Forward declares `boost::hana::at_key`.
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_KEY_HPP
0011 #define BOOST_HANA_FWD_AT_KEY_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/core/when.hpp>
0015 
0016 
0017 namespace boost { namespace hana {
0018     //! Returns the value associated to the given key in a structure, or fail.
0019     //! @ingroup group-Searchable
0020     //!
0021     //! Given a `key` and a `Searchable` structure, `at_key` returns the first
0022     //! value whose key is equal to the given `key`, and fails at compile-time
0023     //! if no such key exists. This requires the `key` to be compile-time
0024     //! `Comparable`, exactly like for `find`. `at_key` satisfies the following:
0025     //! @code
0026     //!     at_key(xs, key) == find(xs, key).value()
0027     //! @endcode
0028     //!
0029     //! If the `Searchable` actually stores the elements it contains, `at_key`
0030     //! is required to return a lvalue reference, a lvalue reference to const
0031     //! or a rvalue reference to the found value, where the type of reference
0032     //! must match that of the structure passed to `at_key`. If the `Searchable`
0033     //! does not store the elements it contains (i.e. it generates them on
0034     //! demand), this requirement is dropped.
0035     //!
0036     //!
0037     //! @param xs
0038     //! The structure to be searched.
0039     //!
0040     //! @param key
0041     //! A key to be searched for in the structure. The key has to be
0042     //! `Comparable` with the other keys of the structure. In the current
0043     //! version of the library, the comparison of `key` with any other key
0044     //! of the structure must return a compile-time `Logical`.
0045     //!
0046     //!
0047     //! Example
0048     //! -------
0049     //! @include example/at_key.cpp
0050 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0051     constexpr auto at_key = [](auto&& xs, auto const& key) -> decltype(auto) {
0052         return tag-dispatched;
0053     };
0054 #else
0055     template <typename S, typename = void>
0056     struct at_key_impl : at_key_impl<S, when<true>> { };
0057 
0058     struct at_key_t {
0059         template <typename Xs, typename Key>
0060         constexpr decltype(auto) operator()(Xs&& xs, Key const& key) const;
0061     };
0062 
0063     BOOST_HANA_INLINE_VARIABLE constexpr at_key_t at_key{};
0064 #endif
0065 }} // end namespace boost::hana
0066 
0067 #endif // !BOOST_HANA_FWD_AT_KEY_HPP