[switch] Is there any interest in library switch extention?

Hello to all; I came up with an idea of extending the current switch functionality using library extensions. The problem is mostly when we have char[] (or any other object) in the switch statement: void do_switch(const char *cstr) { switch( cstr ) { case "Sunday": case "Saturday": ... break; case "Monday": ... }; } Obviously we can't do this using C++ alone, so if we have something like BOOST_SWITCH() which would accomplish this would be great. I have a runtime solution (with need of some attention) for this, however, a compile time solution is desirable. The library should do something like: BOOST_SWITCH( "hello world" ) { BOOST_CASE( "hello" ): BOOST_CASE( "world" ): ... break; BOOST_DEFAULT: ... }; (Please don't suggest 'enum' solutions since they are not as dynamic and are confined to very small domain) Any suggestions, ideas & etc? With best regards Kasra

Kasra (Math & ComSci) wrote:
The library should do something like:
BOOST_SWITCH( "hello world" ) { BOOST_CASE( "hello" ): BOOST_CASE( "world" ): ... break; BOOST_DEFAULT: ... };
I hardly see how this could work for a O(1) lookup (the point of the switch statement). For it to work on strings, you would need to work to provide the possibilities as compile-time strings and generate an automaton with nested switch statements. Something like that, yes, that would be very useful. I suppose the switch_ utility can be reused to simplify matters.
participants (2)
-
Kasra (Math & ComSci)
-
Mathias Gaunard