https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101263
TC <rs2740 at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rs2740 at gmail dot com
--- Comment #7 from TC <rs2740 at gmail dot com> ---
(In reply to Barry Revzin from comment #6)
> The "real" answer is allowing constexpr placement new, but that obviously
> doesn't help you right now.
>
> But I think the helpful answer is that you can add a constructor to your
> storage like storage(init_from_invoke_t, Args&&... args) that initializes
> the underlying value from invoke((Args&&)args...), and then
> construct_at(&storage, init_from_invoke, [&]() -> decltype(auto) { return
> *i; }).
>
> Something like that?
Yes. Something at that level of generality will be needed for the new
optional::transform, so it seems the better approach.
In my proof-of-concept implementation (which didn't have that concern), I used
something tailored to this specific case, along the lines of
struct __deref_tag {};
template<class _Tp>
struct __cache_wrapper {
template<class _Iter>
constexpr __cache_wrapper(__deref_tag, const _Iter& __i)
: __t(*__i) {}
_Tp __t;
};
and then stored a __non_propagating_cache<__cache_wrapper<range_value_t<...>>>
__cache, so that emplace-deref(i) is __cache.emplace(__deref_tag{}, i);