|
Boost : |
Subject: Re: [boost] [switch] Is there any interest in library switch extension?
From: Kasra Nassiri\(Math & ComSci\) (kasra_n500_at_[hidden])
Date: 2008-09-15 07:22:00
I am not sure how it could be performed on O(1), however, the current algorithm in O(n). Current algorithm is something like:
BOOST_SWITCH( "hello world" )
{
#include BOOST_PP_UPDATE_COUNTER()
BOOST_CASE("invalid case")
std::cout << "Reached invalid case!" << std::endl;
#include BOOST_PP_UPDATE_COUNTER()
BOOST_CASE("another string")
std::cout << "Reached invalid case!" << std::endl;
#include BOOST_PP_UPDATE_COUNTER()
BOOST_CASE( "hello world" )
std::cout << "Reached the correct code!" << std::endl;
#include BOOST_PP_UPDATE_COUNTER()
BOOST_CASE("hello world 1")
std::cout << "Reached the correct code! (no breaks)" << std::endl;
BOOST_BREAK;
#include BOOST_PP_UPDATE_COUNTER()
BOOST_CASE("hello world")
std::cout << "Should throw exception! (duplicated value)" << std::endl;
#include BOOST_PP_UPDATE_COUNTER()
BOOST_CASE("another string 1")
std::cout << "Reached invalid case! (broken)" << std::endl;
#include BOOST_PP_UPDATE_COUNTER()
BOOST_DEFAULT
std::cout << "Reached default Hello!" << std::endl;
} BOOST_SWITCH_END
It works fine but it is O(n) and uses hash tables.
I want to get rid of "#include BOOST_PP_UPDATE_COUNTER()" somehow, but at this time I can't.
Even when you use BOOST_BREAK at early statements it is still O(n), since it checks for duplicated values. But using break would change to O(m) : m < n.
The 'default' statement at the moment must be at the end of all other cases, however, it will be updated so it could be anywhere with in the switch.
By the way where is this switch_utility? Any other suggestions?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk