Boost logo

Boost :

Subject: Re: [boost] An extension to boost::variant
From: Catalytic (iitk.cs_at_[hidden])
Date: 2009-02-08 10:09:34


Chris Hamilton-3 wrote:
>
> While boost::variant is very capable at what it does, there is one thing
> it doesn't do ..
>
> ..My question is this: why can't boost::variant be clever about reference
> data types..
>
> The reason I want this, is to have a nice String variant, that
> encapsulates the various forms a string can take in a current project:
> std::strings, char*'s, and std::string* and
> boost::shared_ptr<std::string>. I want functions to be able to handle
> all of these types transparently by using variants as the argument
> types. Allowing "const std::string&" as a variant type allows this to
> be done while not requiring a wasteful string copy.
> ..
> (I have a small custom variant class implementing this, and it appears
> to work well. It's not as 'full fledged' as the boost::variant class,
> but the approach I've taken could surely be grafted on to boost::variant.)
>
>

An example will be better than a lengthy explanation,
please have a look at the test-cases in the boost distribution:
libs/variant/test/:
specially variant_reference_test.cpp

IMHO, it will answer all your queries.

-Cat

-- 
View this message in context: http://www.nabble.com/An-extension-to-boost%3A%3Avariant-tp21881442p21896688.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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