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