|
Boost : |
From: Larry Evans (cppljevans_at_[hidden])
Date: 2008-01-03 00:07:05
On 01/02/08 15:08, Stjepan Rajko wrote:
> The review of the Switch library by Steven Watanabe will begin this
> Saturday, Jan 5th.
>
> Description:
>
> The built in C/C++ switch statement is very efficient. Unfortunately,
> unlike a chained if/else construct there is no easy way to use it when
> the number of cases depends on a template parameter. The Switch
The attachment contains an alternative which uses no preprocessing.
It uses more memory because of the static fun_vec in:
fun_switch_impl::our_vec
However, it would probably use less code because of no preprocessor
generated switch statements. OTOH, it would be slower because
the function has to be looked up in the vector.
Are there any other comparisons you can think of. It would be
useful to outline the pro's and cons of alternative implementations
you've considered.
I've done a simple test of the attached by using it in a slightly
modified test_switch.cpp. I just added the #include and:
BOOST_CHECK_EQUAL((fun_switch<test_range>(5, f())), 6);
-regards,
Larry
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk