Eric Friedman wrote: > Peter Dimov wrote: [...] >> template <class T, ...> T & extract(variant<...> & operand); >> template <class T, ...> T const & extract(variant<...> const & >> operand); template <class T, ...> T * extract(variant<...> * >> operand); >> template <class T, ...> T const * extract(variant<...> const * >> operand); >> >> it's no longer ambiguous. > > I believe it is. The following (admittedly silly) example fails to > compile under Comeau: > > // -- BEGIN CODE EXAMPLE -- > template <class T, class Extractable> T & extract(Extractable & > operand); template <class T, class Extractable> T const & > extract(Extractable const & operand); > > template <class T, class Extractable> T * extract(Extractable * > operand); template <class T, class Extractable> T const * > extract(Extractable const * operand);
This is not what I wrote above. >> The other option is to support a dynamic_cast-style extract: >> >> T * p = extract<T*>(&var); >> T & r = extract<T&>(var); >> >> but it would likely require partial ordering/specialization. > > I've thought about this, but I think it would introduce significant > confusion among users. > > For instance: > > variant<char, char*> v; > char& c = extract<char&>(v); // ok... check for and either throw or > extract char > char* c = extract<char*>(v); // check for and either return null or > extract: char? or char*? Compile-time error, pointer syntax needs a pointer to the variant, consistent with dynamic_cast and any_cast: char* c = extract<char*>(&v); > Even though the statement is well-defined (extract char) under your > proposed syntax, I imagine many nonetheless would read the second > line as extraction of char* from v. (While in fact it would extract > char from v.) Yes, it's possible to misread it. _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost