|
Boost : |
From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-02-03 11:03:03
----- Original Message -----
From: "Daryle Walker" <darylew_at_[hidden]>
> I tried something like
>
> template < class ObjectType, typename AspectType, AspectType
(ObjectType::*
> Getter)(), AspectType (ObjectType::* GetSetter)(AspectType) >
> class get_set_base
> {
> public:
> explicit get_set_base( ObjectType &o )
> : s_( &o ), a_( o.*Getter() )
> {}
> get_set_base( ObjectType &o, AspectType a )
> : s_( &o ), a_( o.*GetSetter(a) )
> {}
> ~get_set_base()
> { s_->*GetSetter(a_); }
>
> private:
> ObjectType * const s_;
> AspectType const a_;
> };
>
> But my compiler choked on the third template parameter, saying it was an
> unimplemented feature.
That'll choke MSVC as well, at least in some circumstances. However, you can
use intermediary policies to get around this problem:
template < class ObjectType, typename AspectType, class Accessor >
class get_set_base
{
public:
explicit get_set_base( ObjectType &o )
: s_( &o ), a_( Accessor::get(o) )
{}
get_set_base( ObjectType &o, AspectType a )
: s_( &o ), a_( Accessor::get_set(o, a) )
{}
~get_set_base()
{ Accessor::get_set(*s_, a_); }
private:
ObjectType * const s_;
AspectType const a_;
};
Accessor is a policies class which supplies get/get_set as static member
functions.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk