default template arguments...

default template arguments...

Post by Chris Thom » Wed, 04 Jun 2008 22:41:42


Is the following use of default template arguments Kosher?
_______________________________________________________________
template<
typename T,
void (T::*T_fp_start) () = &T::start,
void (T::*T_fp_join) () = &T::join

T object;

struct guard {
T& object;

guard(T& _object) : object(_object) {
(object.*T_fp_start)();
}

~guard() {
(object.*T_fp_join)();
}
};

active() {
(object.*T_fp_start)();
}

~active() {
(object.*T_fp_join)();
}
};

_______________________________________________________________



Basically, I want to allow objects which have a common interface of
`T::start()/join()' to be able to use the template above like:

active<object> o;




However, if an object has a custom function it wants to use instead of start
and/or join, it could do something like:


active<object, &object::spawn> o;


-or-


active<object, &object::spawn, &object::wait> o;




Is that okay? I am not a C++ expert. However, it seems to compile on GCC and
Comeau...

;^)




--
Chris M. Thomasson
http://www.yqcomputer.com/