$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Yuval Ronen (ronen_yuval_at_[hidden])
Date: 2006-07-01 14:56:01
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<boost/variant.hpp>
>  
> 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::get<std::string&>(v)); // NOw this does NOT  throw
>          bool &Bref(boost::get<bool&>(v));                  // but this does 
>          return 0;
> }
Looks quite reasonable. I guess that making a derived class would also 
be my solution in this case.