Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2003-02-21 11:25:38


Eric Friedman wrote:
> Peter Dimov wrote:
>> 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.
>
> OK, I believe I see what you're saying.
>
> Problem is that I was trying to design a general boost::extract<>
> facility, one that needs not be specialized for each type. (Indeed,
> with my design, visitable types need not be cognizant of the facility
> at all.)

I missed that part. ;-)

Still, I consider the function template interface better, even for a general
extract facility. Users that only extract from variants need not pay extra
for a generic interface that they don't need.

You can make a generic function template interface by using metaprogramming,
but I don't know how well the compilers will handle it.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk