Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-07-15 08:50:39


"Dean Michael Berris" <mikhailberis_at_[hidden]> writes:

> // ...
> dispatcher <void (std::string), std::string, my_validator, my_router> d;
> d["1234"] = void_function_takes_string; // will throw an
> invalid_index<std::string> exception
> d["12345"] = void_function_takes_string; // will map the callback to the hash
> // of "12345" as defined in the router policy
> d["23456"]("my string input"); // if "23456" hashes the same as "12345"
> // then `void_function_takes_string' is called where "my string input"
> // is passed accordingly
>
> [end code]
>
> This is called strategized index validation, and strategized routing
> implementation -- both being concepts that will need much
> documentation. This is documented in the dispatcher.design.dispatcher
> section in the included documentation.

There's too much coupling of unrelated concepts in this design, it
seems to me. All that's required to do this is a generic wrapper over
string:

    template <class T, class Validate, class Hash>
    struct strategized_index
    {
        // Throws an exception unless Validate()(x). Stores x as a member
        strategized_index(T const& x);

        // returns Hash()(*this.x) < Hash()(rhs)
        bool operator<(strategized_index const& rhs);
    };

If you really need comparison and hashing to be stateful, then you do
need to parameterize the container... but you still don't need to tie
it to dispatching; just choose to store boost::function objects as
Kevin suggested:

    template <class K, class V, class Validate, class Hash>
    struct strategized_unordered_map;

no?

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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