|
Boost Users : |
From: Bjorn.Karlsson_at_[hidden]
Date: 2005-07-12 04:07:19
> From: Felipe Magno de Almeida [mailto:felipe.m.almeida_at_[hidden]]
>
> What I wanted is a vector of variant<object1, object2> and I dont want
> object1 and object2 to be copied because it is expensive. But Im not
> figuring out how to do this... tried boost::ref either with no
> success... :/
Boost.Smart_ptr (http://www.boost.org/libs/smart_ptr/smart_ptr.htm) can
help: use boost::shared_ptr, which is a reference-counted smart pointer.
typedef boost::variant<object1,object2> variant_type;
std::vector<boost::shared_ptr<variant_type> > vec;
boost::shared_ptr<variant_type> v(new variant_type(object1()));
vec.push_back(v); // No copying of the variant
Bjorn Karlsson
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net