A
abir
Hi, I have a class which once created , can not be changed. However as
it has a few states, which need to be set with a few function call, I
thought to activate(enable) those functions only a certain trait is
present in the caller class.
eg,
class Stroke{
private:
typedef std:air<uint32_t,uint32_t> PointPair;
PointPair points_;
StrokeType type_; ///< StrokeType is an enum;
Dir dir_; //< another enum
std::size_t drawingID_ ; //some stroke id
...
public:
Stroke(Drawing& d,PointPair& points, std::size_t id);
void setDir(Dir d);
};
now my constructor sets a few fields, when the class is created.
The remaining things i want to set only using some classes, which has
certain traits.
Like I want a class which has a trait can_set_dir, has setDir enabled
(using boost::enable_if or equivalent), But the class which doesn't
have the trait can't call the function (it will be removed from the
definition).
This is kind of selective friendship I want to achieve, without using
friend keyword which is intrusive in nature.
Is it possible to make this kind of selective function calling based
on trait ? ( I am free to modify signature of setDir for that purpose)
thanks
abir
it has a few states, which need to be set with a few function call, I
thought to activate(enable) those functions only a certain trait is
present in the caller class.
eg,
class Stroke{
private:
typedef std:air<uint32_t,uint32_t> PointPair;
PointPair points_;
StrokeType type_; ///< StrokeType is an enum;
Dir dir_; //< another enum
std::size_t drawingID_ ; //some stroke id
...
public:
Stroke(Drawing& d,PointPair& points, std::size_t id);
void setDir(Dir d);
};
now my constructor sets a few fields, when the class is created.
The remaining things i want to set only using some classes, which has
certain traits.
Like I want a class which has a trait can_set_dir, has setDir enabled
(using boost::enable_if or equivalent), But the class which doesn't
have the trait can't call the function (it will be removed from the
definition).
This is kind of selective friendship I want to achieve, without using
friend keyword which is intrusive in nature.
Is it possible to make this kind of selective function calling based
on trait ? ( I am free to modify signature of setDir for that purpose)
thanks
abir