Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:43:36

0001 /*!
0002 @file
0003 Defines `boost::hana::if_`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_IF_HPP
0011 #define BOOST_HANA_IF_HPP
0012 
0013 #include <boost/hana/fwd/if.hpp>
0014 
0015 #include <boost/hana/concept/logical.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/dispatch.hpp>
0018 #include <boost/hana/eval_if.hpp>
0019 
0020 
0021 namespace boost { namespace hana {
0022     //! @cond
0023     template <typename Cond, typename Then, typename Else>
0024     constexpr decltype(auto) if_t::operator()(Cond&& cond, Then&& then_, Else&& else_) const {
0025         using Bool = typename hana::tag_of<Cond>::type;
0026         using If = BOOST_HANA_DISPATCH_IF(if_impl<Bool>,
0027             hana::Logical<Bool>::value
0028         );
0029 
0030     #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0031         static_assert(hana::Logical<Bool>::value,
0032         "hana::if_(cond, then, else) requires 'cond' to be a Logical");
0033     #endif
0034 
0035         return If::apply(static_cast<Cond&&>(cond),
0036                          static_cast<Then&&>(then_),
0037                          static_cast<Else&&>(else_));
0038     }
0039     //! @endcond
0040 
0041     namespace detail {
0042         template <typename T>
0043         struct hold {
0044             T value;
0045             constexpr T&& operator()() && { return static_cast<T&&>(value); }
0046         };
0047     }
0048 
0049     template <typename L, bool condition>
0050     struct if_impl<L, when<condition>> : default_ {
0051         template <typename C, typename T, typename E>
0052         static constexpr auto apply(C&& c, T&& t, E&& e) {
0053             return hana::eval_if(static_cast<C&&>(c),
0054                 detail::hold<T&&>{static_cast<T&&>(t)},
0055                 detail::hold<E&&>{static_cast<E&&>(e)}
0056             );
0057         }
0058     };
0059 }} // end namespace boost::hana
0060 
0061 #endif // !BOOST_HANA_IF_HPP