nested_than_fwd.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*!
  2. @file
  3. Forward declares `boost::hana::detail::nested_than`.
  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_THAN_FWD_HPP
  9. #define BOOST_HANA_DETAIL_NESTED_THAN_FWD_HPP
  10. #include <boost/hana/config.hpp>
  11. BOOST_HANA_NAMESPACE_BEGIN namespace detail {
  12. template <typename Algorithm>
  13. struct nested_than_t {
  14. template <typename X>
  15. constexpr decltype(auto) operator()(X&& x) const;
  16. };
  17. //! @ingroup group-details
  18. //! Provides a `.than` static constexpr function object.
  19. //!
  20. //! When creating a binary function object of type `Algo` whose signature
  21. //! is `A x B -> Return`, `nested_than<Algo>` can be used as a base class
  22. //! of `Algo`. Doing so will provide a static constexpr member called
  23. //! `than`, which has the following signature:
  24. //! @code
  25. //! B -> A -> Return
  26. //! @endcode
  27. //!
  28. //! Note that the function object `Algo` must be default-constructible,
  29. //! since it will be called as `Algo{}(arguments...)`.
  30. //!
  31. //! @note
  32. //! This function object is especially useful because it takes care of
  33. //! avoiding ODR violations caused by the nested static constexpr member.
  34. template <typename Algorithm>
  35. struct nested_than { static constexpr nested_than_t<Algorithm> than{}; };
  36. template <typename Algorithm>
  37. constexpr nested_than_t<Algorithm> nested_than<Algorithm>::than;
  38. } BOOST_HANA_NAMESPACE_END
  39. #endif // !BOOST_HANA_DETAIL_NESTED_THAN_FWD_HPP