result

Description

The result function adaptor sets the return type for the function, which can be useful when dealing with multiple overloads. Since the return type is no longer dependent on the parameters passed to the function, the result_adaptor provides a nested result_type that is the return type of the function.

Synopsis

template<class Result, class F>
constexpr result_adaptor<Result, F> result(F f);

Requirements

F must be:

Example

#include <boost/hof.hpp>
#include <cassert>

struct id
{
    template<class T>
    T operator()(T x) const
    {
        return x;
    }
};

int main() {
    auto int_result = boost::hof::result<int>(id());
    static_assert(std::is_same<decltype(int_result(true)), int>::value, "Not the same type");
}