nested_to_fwd.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*!
  2. @file
  3. Forward declares `boost::hana::detail::nested_to`.
  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_TO_FWD_HPP
  9. #define BOOST_HANA_DETAIL_NESTED_TO_FWD_HPP
  10. #include <boost/hana/config.hpp>
  11. BOOST_HANA_NAMESPACE_BEGIN namespace detail {
  12. template <typename Algorithm>
  13. struct nested_to_t {
  14. template <typename X>
  15. constexpr decltype(auto) operator()(X&& x) const;
  16. };
  17. //! @ingroup group-details
  18. //! Provides a `.to` static constexpr function object.
  19. //!
  20. //! When creating a binary function object of type `Algo` whose signature
  21. //! is `Object x Object -> Return`, `nested_to<Algo>` can be used as a base
  22. //! class of `Algo`. Doing so will provide a static constexpr member called
  23. //! `to`, which has the following signature:
  24. //! @code
  25. //! Object -> Object -> Return
  26. //! @endcode
  27. //!
  28. //! Note that the function object `Algo` must be default-constructible,
  29. //! since the algorithm 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_to { static constexpr nested_to_t<Algorithm> to{}; };
  36. template <typename Algorithm>
  37. constexpr nested_to_t<Algorithm> nested_to<Algorithm>::to;
  38. } BOOST_HANA_NAMESPACE_END
  39. #endif // !BOOST_HANA_DETAIL_NESTED_TO_FWD_HPP