Edit: /usr/include/boost/hana/eval_if.hpp (3381B)
/*!
@file
Defines `boost::hana::eval_if`.
@copyright Louis Dionne 2013-2017
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
#ifndef BOOST_HANA_EVAL_IF_HPP
#define BOOST_HANA_EVAL_IF_HPP
#include
#include
#include
#include
#include
#include
#include
#include
#include
BOOST_HANA_NAMESPACE_BEGIN
//! @cond
template
constexpr decltype(auto) eval_if_t::operator()(Cond&& cond, Then&& then_, Else&& else_) const {
using Bool = typename hana::tag_of::type;
using EvalIf = BOOST_HANA_DISPATCH_IF(eval_if_impl,
hana::Logical::value
);
#ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
static_assert(hana::Logical::value,
"hana::eval_if(cond, then, else) requires 'cond' to be a Logical");
#endif
return EvalIf::apply(static_cast(cond),
static_cast(then_),
static_cast(else_));
}
//! @endcond
template
struct eval_if_impl> : default_ {
template
static constexpr auto apply(Args&& ...) = delete;
};
//////////////////////////////////////////////////////////////////////////
// Model for arithmetic data types
//////////////////////////////////////////////////////////////////////////
template
struct eval_if_impl::value>> {
template
static constexpr auto apply(Cond const& cond, T&& t, E&& e) {
return cond ? hana::eval(static_cast(t))
: hana::eval(static_cast(e));
}
};
//////////////////////////////////////////////////////////////////////////
// Model for Constants over a Logical
//////////////////////////////////////////////////////////////////////////
template
struct eval_if_impl::value &&
Logical::value
>> {
template
static constexpr decltype(auto)
eval_if_helper(hana::true_, Then&& t, Else&&)
{ return hana::eval(static_cast(t)); }
template
static constexpr decltype(auto)
eval_if_helper(hana::false_, Then&&, Else&& e)
{ return hana::eval(static_cast(e)); }
template
static constexpr decltype(auto) apply(Cond const&, Then&& t, Else&& e) {
constexpr auto cond = hana::value();
constexpr bool truth_value = hana::if_(cond, true, false);
return eval_if_helper(hana::bool_{},
static_cast(t),
static_cast(e));
}
};
BOOST_HANA_NAMESPACE_END
#endif // !BOOST_HANA_EVAL_IF_HPP