]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Forward declares `boost::hana::at_key`. | |
4 | ||
5 | @copyright Louis Dionne 2013-2016 | |
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) | |
8 | */ | |
9 | ||
10 | #ifndef BOOST_HANA_FWD_AT_KEY_HPP | |
11 | #define BOOST_HANA_FWD_AT_KEY_HPP | |
12 | ||
13 | #include <boost/hana/config.hpp> | |
14 | #include <boost/hana/core/when.hpp> | |
15 | ||
16 | ||
17 | BOOST_HANA_NAMESPACE_BEGIN | |
18 | //! Returns the value associated to the given key in a structure, or fail. | |
19 | //! @ingroup group-Searchable | |
20 | //! | |
21 | //! Given a `key` and a `Searchable` structure, `at_key` returns the first | |
22 | //! value whose key is equal to the given `key`, and fails at compile-time | |
23 | //! if no such key exists. This requires the `key` to be compile-time | |
24 | //! `Comparable`, exactly like for `find`. `at_key` satisfies the following: | |
25 | //! @code | |
26 | //! at_key(xs, key) == find(xs, key).value() | |
27 | //! @endcode | |
28 | //! | |
29 | //! If the `Searchable` actually stores the elements it contains, `at_key` | |
30 | //! is required to return a lvalue reference, a lvalue reference to const | |
31 | //! or a rvalue reference to the found value, where the type of reference | |
32 | //! must match that of the structure passed to `at_key`. If the `Searchable` | |
33 | //! does not store the elements it contains (i.e. it generates them on | |
34 | //! demand), this requirement is dropped. | |
35 | //! | |
36 | //! | |
37 | //! @param xs | |
38 | //! The structure to be searched. | |
39 | //! | |
40 | //! @param key | |
41 | //! A key to be searched for in the structure. The key has to be | |
42 | //! `Comparable` with the other keys of the structure. In the current | |
43 | //! version of the library, the comparison of `key` with any other key | |
44 | //! of the structure must return a compile-time `Logical`. | |
45 | //! | |
46 | //! | |
47 | //! Example | |
48 | //! ------- | |
49 | //! @include example/at_key.cpp | |
50 | #ifdef BOOST_HANA_DOXYGEN_INVOKED | |
51 | constexpr auto at_key = [](auto&& xs, auto const& key) -> decltype(auto) { | |
52 | return tag-dispatched; | |
53 | }; | |
54 | #else | |
55 | template <typename S, typename = void> | |
56 | struct at_key_impl : at_key_impl<S, when<true>> { }; | |
57 | ||
58 | struct at_key_t { | |
59 | template <typename Xs, typename Key> | |
60 | constexpr decltype(auto) operator()(Xs&& xs, Key const& key) const; | |
61 | }; | |
62 | ||
63 | constexpr at_key_t at_key{}; | |
64 | #endif | |
65 | BOOST_HANA_NAMESPACE_END | |
66 | ||
67 | #endif // !BOOST_HANA_FWD_AT_KEY_HPP |