Boost logo

Boost Users :

Subject: [Boost-users] [variant] how to in-place construct a variant
From: Stefan Strasser (strasser_at_[hidden])
Date: 2009-09-07 17:30:26


I can't figure out how to in-place construct the contents of a boost::variant.
the error message using GCC is merely 516 kb in size.

from the boost.variant tutoral:

> By default, a variant default-constructs its first bounded type, so v
initially contains int(0). If this is not desired, or if the first bounded
type is not default-constructible, a variant can be constructed directly from
any value convertible to one of its bounded types.

from the synopsis:
> template<typename T> variant(const T &);
> template<typename T> variant & operator=(const T &);

so why does the following fail:

struct A : noncopyable{
        A(int);
        A &operator=(int);
};
struct B{};

int main(){
        A a(5); //ok
        a=5; //ok
        variant<A,B> var(5); //error
        var=5; //error
}

both error messages complain about noncopyable being - noncopyable.

compiler is gcc 4.3.2

thank you


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