|
Boost : |
Subject: Re: [boost] An extension to boost::variant
From: Chris Hamilton (chamilton_at_[hidden])
Date: 2009-02-09 14:47:58
> Chris Hamilton wrote:
>
>> 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.
>
> Why can't you simply use std::pair<const char*, size_t>?
> That seems to cover all possibilities already... (assuming std::string
> is contiguous, which is true in the real world).
The String example is only example. I'm considering using
boost::variant as a way to add relatively simple runtime polymorphism
for parameters passed to a function. It may be desirable to do this
using references for certain large data types that you'd rather not pass
by value. (I realize you could do this with pointers, but why not be
able to handle references as well?)
Chris
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk