Boost logo

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 ( 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, kalb at, bjorn.karlsson at, gregod at, wekempf at