C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::elide

From: Bjorn Reese <breese_at_[hidden]>
Date: Fri, 31 May 2024 14:34:45 +0200
On 5/31/24 11:24, Gašper Ažman via Std-Proposals wrote:
> My "elide", as exists in my codebase:
>
> template <typename F>
> struct init_t {
> F f;
> using result_t = decltype(std::move(std::declval<F>())());
> static constexpr bool is_noexcept = noexcept(std::move(std::declval<F>())());
> constexpr operator result_t () &&
> noexcept(is_noexcept) {
> return std::move(f)();
> }
> constexpr result_t operator()() &&
> noexcept(is_noexcept) {
> return std::move(f)();
> }
> };
> template <typename F>
> init_t(F&&) -> init_t<std::remove_cvref_t<F>>;

So

   elide(fn, args...)

would be equivalent to

   init_t(bind_front(fn, args...))

Which raises the question: if we want a facility that contextually
converts to the return type, should we add the conversion operator to
bind_front (and bind and bind_back) instead of introducing a new type?

Received on 2024-05-31 12:34:48