Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

map with polymorphic key???

0 views
Skip to first unread message

Daniel Suen

unread,
Jul 9, 2004, 6:24:42 AM7/9/04
to
Hi All,

I am trying to implement various kinds of finite automaton simulators; I
have abstract the transition mappings to be from a "Set" to another "Set"
taking on some "Input". I come up with the data structure like the following
to represent automatons,

map<Set, map<Input, Set> >

However, for deterministic finite automaton, I derive the class "State" from
the class "Set", and the class "Symbol" from the class "Input". Now, I want
to write a function that takes a string and run the automaton against the
string. Therefore, for deterministic finite automaton, the signature of the
function would be,

run(string s, map<State, map<Symbol, State> >);

I am wondering if there is any way for me to write something like the
following,

run(string s, map<Set, map<Input, Set> >);

so that I can pass different kinds of automaton representation to the
function.

If I am not on the right track in the design, could someone point me out how
I should structure the whole thing to make the code look beautiful?

-Daniel.


John Harrison

unread,
Jul 9, 2004, 1:35:00 PM7/9/04
to

Use a pointer (or preferably a smart pointer) for the key and a comparison
object to call a virtual method on the keys.

Whether that's good design for your application I couldn't say but it will
get you a map with a polymorphic key.

john


0 new messages