
Max Khesin wrote:
I have been playing around with a library to emulate Python 'in' syntax
if(a in [x1, x2]): stuff
the main motivation for this is the annoyance of repeating the || operator with the same value in C++
if(val==v1 || val==v2 || val==v3){ ^^^ ^^^ ^^^ }
I figured I would use tuple for the list to allow membership test for a list of heterogeneous types (just like python). The rough results are included below.
I am interested in your feedback: 1) how useful would you find this in general
Different types don't seem useful to me, otherwise it might be a handy tool from time to time.
2) there are 3 variations on syntax in the main() 1st is native(no macros) with more typing, 2 is less typing with macros, 3d is even less but does not compile :) (coule use a language lawer here). Do you like any of these? Alternative suggestions?
find( e ).in( v1, v2, v3, v4 ); Does seem more natural to me for a C++-program. I don't see why we should limit our thinking to a Python-like syntax. One thing to keep in mind: The ||-form has short-circuiting. While it might look convenient to have a nicer syntax, we should also think about what drawbacks it has if applied blindly by users, e.g. more errors, inefficiency. Maybe we should even consider a macro-only solution like: BOOST_CONTAINED( e )( v1 )( v2 )( v3 ); or something... Regards, Daniel -- Daniel Frey aixigo AG - financial solutions & technology Schloß-Rahe-Straße 15, 52072 Aachen, Germany fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99 eMail: daniel.frey@aixigo.de, web: http://www.aixigo.de