Re: [Boost-users] Boost.Variant: char[], a bool or std::string ?
This has the desired effects BUT ... I am not a software engineer .. so I would like to know is it would the proffessionals would consider ugly code ?
#include<string>
#include
Nindi Singh wrote:
This has the desired effects BUT ... I am not a software engineer .. so I would like to know is it would the proffessionals would consider ugly code ?
#include<string> #include
typedef boost::variant< bool,std::string> BoostVariant;
struct MyVariant:public BoostVariant {
template<typename type> MyVariant(const type &theType):BoostVariant(theType){}
MyVariant(const char *theCString):BoostVariant(std::string(theCString)){} };
int main () { MyVariant v("A String"); std::string &Sref(boost::getstd::string&(v)); // NOw this does NOT throw bool &Bref(boost::get
(v)); // but this does return 0; }
Looks quite reasonable. I guess that making a derived class would also be my solution in this case.
participants (2)
-
Nindi Singh
-
Yuval Ronen