if.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*!
  2. @file
  3. Forward declares `boost::hana::if_`.
  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_FWD_IF_HPP
  9. #define BOOST_HANA_FWD_IF_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Conditionally return one of two values based on a condition.
  14. //! @ingroup group-Logical
  15. //!
  16. //! Specifically, `then` is returned iff `cond` is true-valued, and
  17. //! `else_` is returned otherwise. Note that some `Logical` models may
  18. //! allow `then` and `else_` to have different types, while others may
  19. //! require both values to have the same type.
  20. //!
  21. //!
  22. //! @param cond
  23. //! The condition determining which of the two values is returned.
  24. //!
  25. //! @param then
  26. //! The value returned when `cond` is true-valued.
  27. //!
  28. //! @param else_
  29. //! The value returned when `cond` is false-valued.
  30. //!
  31. //!
  32. //! Example
  33. //! -------
  34. //! @include example/if.cpp
  35. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  36. constexpr auto if_ = [](auto&& cond, auto&& then, auto&& else_) -> decltype(auto) {
  37. return tag-dispatched;
  38. };
  39. #else
  40. template <typename L, typename = void>
  41. struct if_impl : if_impl<L, when<true>> { };
  42. struct if_t {
  43. template <typename Cond, typename Then, typename Else>
  44. constexpr decltype(auto) operator()(Cond&& cond, Then&& then, Else&& else_) const;
  45. };
  46. constexpr if_t if_{};
  47. #endif
  48. BOOST_HANA_NAMESPACE_END
  49. #endif // !BOOST_HANA_FWD_IF_HPP