nested_by_fwd.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*!
  2. @file
  3. Forward declares `boost::hana::detail::nested_by`.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_DETAIL_NESTED_BY_FWD_HPP
  9. #define BOOST_HANA_DETAIL_NESTED_BY_FWD_HPP
  10. #include <boost/hana/config.hpp>
  11. BOOST_HANA_NAMESPACE_BEGIN namespace detail {
  12. template <typename Algorithm>
  13. struct nested_by_t {
  14. template <typename Predicate, typename Object>
  15. constexpr decltype(auto)
  16. operator()(Predicate&& predicate, Object&& object) const;
  17. template <typename Predicate>
  18. constexpr decltype(auto) operator()(Predicate&& predicate) const;
  19. };
  20. //! @ingroup group-details
  21. //! Provides a `.by` static constexpr function object.
  22. //!
  23. //! When creating a binary function object of type `Algorithm` whose
  24. //! signature is `Object x Predicate -> Return`, `nested_by<Algorithm>`
  25. //! can be used as a base class to `Algorithm`. Doing so will provide a
  26. //! static constexpr member called `by`, which has the two following
  27. //! signatures:
  28. //! @code
  29. //! Predicate x Object -> Return
  30. //! Predicate -> (Object -> Return)
  31. //! @endcode
  32. //!
  33. //! In other words, `nested_by` is a `curry`ed and `flip`ped version of
  34. //! `Algorithm`. Note that the function object `Algorithm` must be
  35. //! default-constructible, since the algorithm will be called as
  36. //! `Algorithm{}(arguments...)`.
  37. //!
  38. //! @note
  39. //! This function object is especially useful because it takes care of
  40. //! avoiding ODR violations caused by the nested static constexpr member.
  41. template <typename Algorithm>
  42. struct nested_by { static constexpr nested_by_t<Algorithm> by{}; };
  43. template <typename Algorithm>
  44. constexpr nested_by_t<Algorithm> nested_by<Algorithm>::by;
  45. } BOOST_HANA_NAMESPACE_END
  46. #endif // !BOOST_HANA_DETAIL_NESTED_BY_FWD_HPP