Date: Sun, 01 Dec 2024 19:05:42 +0200
Thanks. I believe that the ability to only construct an object, without
modifying it, is useful in itself. I think there's room for three
variants of std::factory, not just two.
The motivations are different, for my proposal, T need not be some
heavyweight object; the goal is to streamline type conversion where a
transforming function is expected. For example, pass
std::construct<int> as a transforming function to convert a stream of
floats to ints.
On Sun, 2024-12-01 at 17:16 +0100, Sebastian Wittmeier via Std-
Proposals wrote:
>
> Hi Avi,
> what you are describing is a factory function.
> A few months back we were discussing Thomas' and my suggestion of a
> std::factory or std::construct_modify in the context of NRVO together
> with a version for free functions.
>
> The only difference was the added possibility to also modify or
> inspect the returned value freely without copy or move.
>
> P3357
> https://github.com/cplusplus/papers/issues/2013
>
> The construct template function would be half of it.
>
> > -----Ursprüngliche Nachricht-----
> > Von: Avi Kivity via Std-Proposals <std-proposals_at_[hidden]>
> > Gesendet: So 01.12.2024 16:57
> > Betreff: [std-proposals] std::construct<T>
> > An: std-proposals <std-proposals_at_[hidden]>;
> > CC: Avi Kivity <avi_at_[hidden]>;
> > 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>();
> > --
> > Std-Proposals mailing list
> > Std-Proposals_at_[hidden]
> > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
modifying it, is useful in itself. I think there's room for three
variants of std::factory, not just two.
The motivations are different, for my proposal, T need not be some
heavyweight object; the goal is to streamline type conversion where a
transforming function is expected. For example, pass
std::construct<int> as a transforming function to convert a stream of
floats to ints.
On Sun, 2024-12-01 at 17:16 +0100, Sebastian Wittmeier via Std-
Proposals wrote:
>
> Hi Avi,
> what you are describing is a factory function.
> A few months back we were discussing Thomas' and my suggestion of a
> std::factory or std::construct_modify in the context of NRVO together
> with a version for free functions.
>
> The only difference was the added possibility to also modify or
> inspect the returned value freely without copy or move.
>
> P3357
> https://github.com/cplusplus/papers/issues/2013
>
> The construct template function would be half of it.
>
> > -----Ursprüngliche Nachricht-----
> > Von: Avi Kivity via Std-Proposals <std-proposals_at_[hidden]>
> > Gesendet: So 01.12.2024 16:57
> > Betreff: [std-proposals] std::construct<T>
> > An: std-proposals <std-proposals_at_[hidden]>;
> > CC: Avi Kivity <avi_at_[hidden]>;
> > 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>();
> > --
> > Std-Proposals mailing list
> > Std-Proposals_at_[hidden]
> > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2024-12-01 17:05:47