always — Boost.HigherOrderFunctions 0.6 documentation

# always

## Header

    #include <boost/hof/always.hpp>

## Description

The `always` function returns a function object that will always return the value given to it, no matter what parameters are passed to the function object. The nullary version(i.e. `always(void)`) will return `void`. On compilers, that don’t support constexpr functions returning `void`, a private empty type is returned instead. This return type is specified as `BOOST_HOF_ALWAYS_VOID_RETURN`.

## Synopsis

    template<class T>
    constexpr auto always(T value);

    template<class T>
    constexpr auto always(void);

## Semantics

    assert(always(x)(xs...) == x);

## Requirements

T must be:

- CopyConstructible

## Example

    #include <boost/hof.hpp>
    #include <algorithm>
    #include <cassert>
    using namespace boost::hof;

    int main() {
        int ten = 10;
        assert( always(ten)(1,2,3,4,5) == 10 );
    }

    // Count all
    template<class Iterator, class T>
    auto count(Iterator first, Iterator last)
    {
        return std::count_if(first, last, always(true));
    }