|
Boost Users : |
Subject: Re: [Boost-users] Unique parameter values for interfaces
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2009-05-06 04:43:23
2009/5/6 Ryan McConnehey <mccorywork_at_[hidden]>
> Roman Perepelitsa wrote:
>
> template<typename S, *int N*>
> struct ParameterValue
> {
> ParameterValue(S value_) : value(value_) {}
> S value
> };
>
> typedef ParameterValue<std::string, *0*> ConfigName;
> typedef ParameterValue<std::string, *1*> PathName;
>
> Roman Perepelitsa.
>
>
> Is is possible to have the number be generated automatically so that it
> doesn't need to be defined by the user?
>
I don't think so. If you want to protect yourself from accidentally using
the same number with different types, you can try the following:
template<typename S, *typename Tag*>
struct ParameterValue
{
ParameterValue(S value_) : value(value_) {}
S value
};
*struct ConfigNameTag {};*
typedef ParameterValue<std::string, *ConfigNameTag*> ConfigName;
*struct PathNameTag {};*
typedef ParameterValue<std::string, *PathNameTag*> PathName;
Roman Perepelitsa.
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