construct

Description

The construct function returns a function object that will construct the object when the called. A template can also be given, which it will deduce the parameters to the template. The construct_meta can be used to construct the object from a metafunction.

Synopsis

// Construct by decaying each value
template<class T>
constexpr auto construct();

template<template<class...> class Template>
constexpr auto construct();

// Construct by deducing lvalues by reference and rvalue reference by reference
template<class T>
constexpr auto construct_forward();

template<template<class...> class Template>
constexpr auto construct_forward();

// Construct by deducing lvalues by reference and rvalues by value.
template<class T>
constexpr auto construct_basic();

template<template<class...> class Template>
constexpr auto construct_basic();

// Construct by deducing the object from a metafunction
template<class MetafunctionClass>
constexpr auto construct_meta();

template<template<class...> class MetafunctionTemplate>
constexpr auto construct_meta();

Semantics

assert(construct<T>()(xs...) == T(xs...));
assert(construct<Template>()(xs...) == Template<decltype(xs)...>(xs...));
assert(construct_meta<MetafunctionClass>()(xs...) == MetafunctionClass::apply<decltype(xs)...>(xs...));
assert(construct_meta<MetafunctionTemplate>()(xs...) == MetafunctionTemplate<decltype(xs)...>::type(xs...));

Requirements

MetafunctionClass must be a:

MetafunctionTemplate<Ts...> must be a:

T, Template<Ts..>, MetafunctionClass::apply<Ts...>, and MetafunctionTemplate<Ts...>::type must be:

  • MoveConstructible

Example

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

int main() {
    auto v = boost::hof::construct<std::vector<int>>()(5, 5);
    assert(v.size() == 5);
}