|
Boost Users : |
Subject: Re: [Boost-users] Using different variables based on template type
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2009-06-03 01:54:15
2009/6/2 Ryan McConnehey <mccorywork_at_[hidden]>:
>
> Being able just add a type to a typelist and then have the appropriate
> helper functions generated would be nice but not a necessary. Â So far I'm
> having to put some logic functions into my helper functions.
>
> void putUint16(std::string const& variableName, uint16 const variable) {
> Â m_CurrentStructure->remove(variableName);
> Â //This function call is duplicated in every helper function.
> Â m_CurrentStructure->m_Uint16Map[variableName] = variable; Â //This is
> needed in every helper function but the appropriate map is needs to be used.
> }
>
> Since all these helper functions are exactly the same except the map being
> called I was hoping to refactor to allow adding new type more easily.
>
And as mentioned, the "which map" issue can be handled in templates by
dispatching to an appropriate base class.
> By the way, what is a PP sequence?
>
The boost preprocessor library would allow you do do something like this:
UGLY_PREFIX_ALLOW_TYPES( (uint16)(uint32)(guid)(templated<something>) );
and auto-generate the macro invocations
UGLY_PREFIX_ALLOW_TYPE(uint16);
UGLY_PREFIX_ALLOW_TYPE(uint32);
and so on.
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