|
Boost Users : |
From: Paul Baxter (pauljbaxter_at_[hidden])
Date: 2005-12-08 09:34:19
I have a fixed list of parameter names and with each an associated set of
attributes. I wish to access the attributes via the parameter name rather
than the equivalent list entry index.
In the past, we've created ENUMs with meaningful names to represent the
parameter name->index mapping but I can't help feeling there must be a
better way usng the name directly without this extra artificial mapping
type.
Rather than access an attribute of a given parameter via a numerical index
into an array of attribute structures or similar, I'd like to be able to use
the name field directly. I would like the name->index mapping to happen at
compile time so as not to include some run-time overhead.
// Define a list of all allowable parameter names along with associated
attributes
..
// Not necessarily the required syntax
unsigned config_offset = parameter["third parameter"].get_byte_offset();
I want a compile time error if "third parameter" isn't a valid name, and if
it is valid, I want the code to reduce to parameter[3].get_byte_offset()
which the compiler would further reduce to an inlined access to the right
attribute.
I've tried looking at the MPL map, but am having difficulty with the
documentation though I confess part of this may be a lack of familiarity
with meta template programming.
Can anyone point me to the right area of Boost for doing this name->index
mapping at compile time.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net