map with polymorphic key???

D

Daniel Suen

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.
 
J

John Harrison

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top