|
Boost Users : |
Subject: [Boost-users] Unique parameter values for interfaces
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2009-05-06 02:12:09
I'm currently trying to fortify my class api by "make interfaces easy to
use correctly and hard to use incorrectly". I have a class as follows.
class api
{
api(ConfigName const& configName_, PathName const& pathName_)
: m_ConfigName(configName_.value)
, m_PathName(pathName_.value)
{}
std::string m_ConfigName;
std::string m_PathName;
};
Both ConfigName and PathName are typedef to a template structure as follows.
template<typename S>
struct ParameterValue
{
ParameterValue(S value_) : value(value_) {}
S value
};
typedef ParameterValue<std::string> ConfigName;
typedef ParameterValue<std::string> PathName;
I realized later that this method doesn't prevent the swapping of a
ConfigName with a PathName parameter. Since both parameters are typedef
to the same "type" of ParameterValue they're interchangeable. Is there
a boost class, library or C++ idiom that would provide what I'm looking
for? Since I'm going to be using this concept for other classes I
build, I'd like something that would easily create parameter classes to
use but not be interchangeable with other classes of the same type. I
know that I could do this with a macro but I'm leaving that for a last
resort.
Ryan
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