First of all, thanks for implementing this, great job!
I noticed that variant<> would not compile when I used a type with overloaded operator& as an alternative. access::get_if gave the following error:
'auto' in return type deduced as 'thing' here but deduced as 'wrapper' in earlier return statement.
wrapper<thing>::operator&, in my case, is returning thing *.
Changing get_if like this makes that part work:
constexpr auto *get_if(Variant *v) {
using V = decay_t<Variant>;
static_assert(I < experimental::tuple_size<V>::value, "");
using T = experimental::tuple_element_t<I, V>;
assert(v);
if (!holds_alternative<I>(*v)) {
using R = add_pointer_t<lib::qualify_as_t<T, Variant>>;
return static_cast<R>(nullptr);
} // if
- return &unsafe::get<I>(*v);
+ return std::addressof(unsafe::get<I>(*v));
}
I also had to change the UNION_IMPL macro like this to avoid some nasty crashes:
Hi Erik! Sorry for the delayed response. I just finished implementing the latest specification of std::variant, and I've introduced cpp17::addressof which tries to be constexpr as possible.
Hi!
First of all, thanks for implementing this, great job!
I noticed that
variant<>
would not compile when I used a type with overloadedoperator&
as an alternative.access::get_if
gave the following error:wrapper<thing>::operator&
, in my case, is returningthing *
.Changing
get_if
like this makes that part work:I also had to change the
UNION_IMPL
macro like this to avoid some nasty crashes:I am not sure about the changes above, but it seems to be what the standard wants: http://en.cppreference.com/w/cpp/utility/variant/get_if
It seems like
std::addressof()
does not becomeconstexpr
until C++17 though...Cheers, Erik