
I hardly see how this could work for a O(1) lookup (the point of the switch statement).
I have found a compile time solution! However, we need C++0x :( A hash functions with output type of <int> so we could embed the statement in a normal switch statement on C++0x. #define BOOST_SWITCH( object ) switch ( const_hash_function(object) ) #define BOOST_CASE( case_object ) case const_hash_function(case_object) #define BOOST_DEFAULT default So we could write code like: BOOST_SWITCH( "Hello World" ) { BOOST_CASE("wrong value"): BOOST_CASE("another wrong value"): cout << "Reached wrong statements" << endl; BOOST_BREAK; BOOST_DEFAULT: cout << "Hello World" << endl; }; What I like to add is a reference to the value of the BOOST_SWITCH(...), in this example "Hello World".