This is superceded by P3312 [1].


Instead of std::construct<T>(...), write (&T::T)(...).

[1] https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p3312r1.pdf

On Sun, 2024-12-01 at 17:57 +0200, Avi Kivity wrote:
Functions and member functions are invocable, but constructors are not.

I propose to add

template <typename T, typename... Args>
T std::construct(Args&&... args) {
    return T(std::forward<decltype(Args)>(args)...);
}

With this, we can pass a constructor where other functions can be
passed.

    // build a callback that creates and returns a Type1 thing
    std::function<Type1 (Arg3)> make_somthing =
std::bind_front(std::construct<Type1>, arg1, std::ref(arg2));

    // transform a vector of ints to a vector of some other type
    auto foo = some_container |
std::views::transform(std::construct<AnotherType>) |
std::ranges::to<std::vector>();