| Home | Libraries | People | FAQ | More

## Function template condition_if_c

boost::contract::condition_if_c — Select compilation and execution of a boolean functor template condition using a static boolean predicate (not needed on C++17 compilers, use `if constexpr` instead).

## Synopsis

    // In header: <boost/contract/call_if.hpp>

    template<bool Pred, typename Then>
      bool condition_if_c(Then f, bool else_ = true);

## Description

Compile and execute the nullary boolean functor template call `f()` if and only if the specified static boolean predicate `Pred` is `true`, otherwise trivially return `else_` (`true` by default) at run-time.

A call to `boost::contract::condition_if_c<Pred>(f, else_)` is logically equivalent to `boost::contract::call_if_c<Pred>(f, [] { return else_; })` (but its internal implementation is optimized and it does not actually use `call_if_c`).

See Also: Assertion Requirements

Parameters:

`f` | Nullary boolean functor template. The functor template call `f()` is compiled and executed if and only if `Pred` is `true`.
`else_` | Boolean value to return when `Pred` is `false` (instead of compiling and executing the functor template call `f()`).

Template Parameters:

`Pred` | Static boolean predicate selecting when the functor template call `f()` should be compiled and executed.

Returns: | Boolean value returned by `f()` if the static predicate `Pred` is `true`. Otherwise, trivially return `else_`.