if¶
Header¶
#include <fit/if.hpp>
Description¶
The if_
function decorator makes the function callable if the boolean
condition is true. The if_c
version can be used to give a boolean
condition directly(instead of relying on an integral constant).
Synopsis¶
template<class IntegralConstant>
constexpr auto if_(IntegralConstant);
template<bool B, class F>
constexpr auto if_c(F);
Example¶
#include <fit.hpp>
#include <cassert>
struct sum_f
{
template<class T>
int operator()(T x, T y) const
{
return fit::conditional(
fit::if_(std::is_integral<T>())(fit::_ + fit::_),
fit::always(0)
)(x, y);
}
};
int main() {
assert(sum_f()(1, 2) == 3);
assert(sum_f()("", "") == 0);
}