Boost logo

Boost :

From: рустам абдумаликов (vigosslive2_at_[hidden])
Date: 2019-11-08 16:36:40


Hi All,

I wrote a library *eswitch* which provides enhanced functionality for* C++
switch*.
Please take a look and leave your comments.

*=====================*
*Motivation:*
*=====================*
To overcome "*native switch*" limitations:
- one parameter per "*native switch*"
- the parameter restricted to only *integral *types( int, char, enum ... ).

"*eswitch*" supports any number of parameters and almost without
restriction on their *type*,
as long as the *type *is comparable( i.e. has* operator==* ).

*=====================Why it is important?=====================*

Here is the most viewed questions on the *stackoverflow*:

FEATURE VIEWS
Multiple conditions in switch case
<https://stackoverflow.com/questions/68578/multiple-cases-in-switch-statement>
850k
Switch for string
<https://stackoverflow.com/questions/650162/why-the-switch-statement-cannot-be-applied-on-strings>
693k
Case match in range
<https://stackoverflow.com/questions/9432226/how-do-i-select-a-range-of-values-in-a-switch-statement/24133078#24133078>
133k
Over a million views indicate how many people out there are disappointed
with limited functionality of "*native switch*".
Building parallels with such operators as "*if*"/"*while*"... it is
expected by default that "*native switch*" should have the same
possibilities:

   - be able to work with *non-integral* types as well
   - be able to compose complex conditions like we do in other operators "
   *if*"/"*while*"...

Unfortunately it is not the case up till now. There was a proposal in
2013 *Relax
switch statement
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3627.html>*, and
committee agreed
about importance of this topic. There also was *StringSwitch
<http://llvm.org/doxygen/classllvm_1_1StringSwitch.html>*
implementation by *LLVM
*and *Case ranges
<https://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html>* non-standard
extension which is supported by *gcc*, *intel C/C++* and *clang*.
Nevertheless, we still don't have common and universal solution. People
want to overcome current "*native switch*" limitation either by implementing
their own solution, non-standard extension or even trying to standardize
it.
Making proposed *eswitch <https://github.com/rabdumalikov/eswitch_v4>*
functionality
part of the *Boost-Library *will provide millions of developers useful,
universal and agile functionality in order to finally fulfill their needs.

*=====================repository:=====================*
https://github.com/rabdumalikov/eswitch_v4

*=====================References:=====================/// "switch for
non-integral" on stackoverflow*
1.
https://stackoverflow.com/questions/650162/why-the-switch-statement-cannot-be-applied-on-strings
2.
https://stackoverflow.com/questions/16388510/evaluate-a-string-with-a-switch-in-c
3.
https://stackoverflow.com/questions/5452188/switch-case-statement-in-c-with-a-qstring-type
4.
https://stackoverflow.com/questions/19273092/character-in-switch-statement-c
5. https://stackoverflow.com/questions/4165131/c-c-switch-for-non-integers
6. https://stackoverflow.com/questions/27536575/switch-case-on-char

*/// "Multiple conditions" on stackoverflow*
7.
https://stackoverflow.com/questions/8644096/multiple-conditions-in-switch-case
8.
https://stackoverflow.com/questions/68578/multiple-cases-in-switch-statement

*/// "Ranges in case" on stackoverflow*
9.
https://stackoverflow.com/questions/9432226/how-do-i-select-a-range-of-values-in-a-switch-statement/24133078#24133078

*/// "Case ranges" - non-standard extension*
10. https://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html

*/// LLVM "StringSwitch"*
11. http://llvm.org/doxygen/classllvm_1_1StringSwitch.html

*/// "Relax switch statement" proposal*
12. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3627.html
*/// "N3627 Relaxed switch statement" c++ committee status*
13. https://cplusplus.github.io/EWG/ewg-active.html

*Best Regards.*


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