Date: Fri, 31 May 2024 10:24:44 +0100
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>>;
This elider interops with any other elider (F) that also declares both
operators, transparently. It's only move-callable to ensure that
there's a visual marker of "consuming" the state at the point of use.
We've been very successful with its use in our codebase.
On Fri, May 31, 2024 at 10:10 AM Matthew Taylor via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> > Did anyone like my previous idea of having a way of telling the compiler that we want template instantiation to fail?
>
> At the risk of stating the obvious, the difficulty there is that such an idea is a sledgehammer which could be a major change to template programming; and such an idea needs serious, strong motivation which goes far beyond being a workaround to make a different proposed feature's edge cases work. Particularly as at least a few of the potential use-cases for it can already be achieved in the language as it is now.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
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>>;
This elider interops with any other elider (F) that also declares both
operators, transparently. It's only move-callable to ensure that
there's a visual marker of "consuming" the state at the point of use.
We've been very successful with its use in our codebase.
On Fri, May 31, 2024 at 10:10 AM Matthew Taylor via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> > Did anyone like my previous idea of having a way of telling the compiler that we want template instantiation to fail?
>
> At the risk of stating the obvious, the difficulty there is that such an idea is a sledgehammer which could be a major change to template programming; and such an idea needs serious, strong motivation which goes far beyond being a workaround to make a different proposed feature's edge cases work. Particularly as at least a few of the potential use-cases for it can already be achieved in the language as it is now.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2024-05-31 09:25:00