| 1 | /*! |
| 2 | @file |
| 3 | Forward declares `boost::hana::detail::nested_by`. |
| 4 | |
| 5 | Copyright Louis Dionne 2013-2022 |
| 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_DETAIL_NESTED_BY_FWD_HPP |
| 11 | #define BOOST_HANA_DETAIL_NESTED_BY_FWD_HPP |
| 12 | |
| 13 | #include <boost/hana/config.hpp> |
| 14 | |
| 15 | |
| 16 | namespace boost { namespace hana { namespace detail { |
| 17 | template <typename Algorithm> |
| 18 | struct nested_by_t { |
| 19 | template <typename Predicate, typename Object> |
| 20 | constexpr decltype(auto) |
| 21 | operator()(Predicate&& predicate, Object&& object) const; |
| 22 | |
| 23 | template <typename Predicate> |
| 24 | constexpr decltype(auto) operator()(Predicate&& predicate) const; |
| 25 | }; |
| 26 | |
| 27 | //! @ingroup group-details |
| 28 | //! Provides a `.by` static constexpr function object. |
| 29 | //! |
| 30 | //! When creating a binary function object of type `Algorithm` whose |
| 31 | //! signature is `Object x Predicate -> Return`, `nested_by<Algorithm>` |
| 32 | //! can be used as a base class to `Algorithm`. Doing so will provide a |
| 33 | //! static constexpr member called `by`, which has the two following |
| 34 | //! signatures: |
| 35 | //! @code |
| 36 | //! Predicate x Object -> Return |
| 37 | //! Predicate -> (Object -> Return) |
| 38 | //! @endcode |
| 39 | //! |
| 40 | //! In other words, `nested_by` is a `curry`ed and `flip`ped version of |
| 41 | //! `Algorithm`. Note that the function object `Algorithm` must be |
| 42 | //! default-constructible, since the algorithm will be called as |
| 43 | //! `Algorithm{}(arguments...)`. |
| 44 | //! |
| 45 | //! @note |
| 46 | //! This function object is especially useful because it takes care of |
| 47 | //! avoiding ODR violations caused by the nested static constexpr member. |
| 48 | template <typename Algorithm> |
| 49 | struct nested_by { static constexpr nested_by_t<Algorithm> by{}; }; |
| 50 | |
| 51 | template <typename Algorithm> |
| 52 | constexpr nested_by_t<Algorithm> nested_by<Algorithm>::by; |
| 53 | } }} // end namespace boost::hana |
| 54 | |
| 55 | #endif // !BOOST_HANA_DETAIL_NESTED_BY_FWD_HPP |
| 56 | |