boost::variant construction,assignment
hello, class parameters { public: parameters(); ~parameters(); const R& getR() const; void setR(const R& rhs); const V& getV() const; void setV(const V& rhs); private: const R* r_; const V* v_; }; R and V are typedefs of variant<>. I have chosen to make the private members r_ and v_ as pointers to allow for r_=0 and v_=0 (is this a "never do this" thing?). R setter is implemented like this: void parameters::setR(const R& rhs) { if (!r_) r_ = new R( rhs ); else *r_ = rhs; } then ~parameters() { if (r_) delete r_; } There is no operator= for variant<> it seems? regards,
I have chosen to make the private members r_ and v_ as pointers to allow for r_=0 and v_=0 (is this a "never do this" thing?).
You can also consider using boost::optionalboost::variant r_, v_; Then setR() would be just: r_ = rhs;
boost::variant has already the notion that it has not been set with any value. So there is no need to make it optional. -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Igor R Sent: Thursday, October 09, 2008 12:52 To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost::variant construction,assignment
I have chosen to make the private members r_ and v_ as pointers to allow for r_=0 and v_=0 (is this a "never do this" thing?).
You can also consider using boost::optionalboost::variant r_, v_; Then setR() would be just: r_ = rhs; _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
AMDG peter_foelsche@agilent.com wrote:
boost::variant has already the notion that it has not been set with any value. So there is no need to make it optional.
Not unless you use boost::blank. http://www.boost.org/doc/html/variant/design.html#variant.design.never-empty In Christ, Steven Watanabe
bool variant::empty() const; http://www.boost.org/doc/libs/1_36_0/doc/html/boost/variant.html -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: Thursday, October 09, 2008 13:36 To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost::variant construction,assignment AMDG peter_foelsche@agilent.com wrote:
boost::variant has already the notion that it has not been set with any value. So there is no need to make it optional.
Not unless you use boost::blank. http://www.boost.org/doc/html/variant/design.html#variant.design.never-empty In Christ, Steven Watanabe _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
AMDG peter_foelsche@agilent.com wrote:
bool variant::empty() const;
Returns: false: variant always contains exactly one of its bounded types. (See the section called “"Never-Empty" Guarantee” for more information.) Rationale: Facilitates generic compatibility with boost::any. Throws: Will not throw. In Christ, Steven Watanabe
participants (4)
-
Hicham Mouline
-
Igor R
-
peter_foelsche@agilent.com
-
Steven Watanabe