Boost logo

Boost :

Subject: [boost] [boos][switch] What do you think?
From: Kasra Nassiri\(Math & ComSci\) (kasra_n500_at_[hidden])
Date: 2008-09-26 08:36:10


Hi all,

I have been writing a BOOST_SWITCH(...) statement, which tries to emulate the C++ switch() for C++ objects.

string variable = "some string";
string string0 = "0", string1 = "1", string2 = "2";

   BOOST_SWITCH( variable ,
      BOOST_CASE( string0,
         std::cout << "error" << std::endl;
         BOOST_BREAK;
      );
      BOOST_CASE( string1,
         std::cout << "error" << std::endl;
         BOOST_BREAK;
      );
      BOOST_DEFAULT(
         BOOST_SWITCH( string2,
            BOOST_DEFAULT(
               std::cout << "embedded switch statments work" << std::endl;
            );
         ); std::cout << "end of secound switch statment" << std::endl;

         std::cout << "reached default" << std::endl;
      );
   );

The above code would work correctly (msvc). However, for "const char *", the compiler could not deduce template. I have written an specialized "const char *" template however, still could not deduce template. Any suggestions?

template<class T> switch_;
template<> switch_<const char *>;

With best regards

Kasra Nassiri

      


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk