Policies and Default Template Arguments

Policies and Default Template Arguments

Post by Frank-Ren? » Thu, 19 Jan 2006 20:24:27


Is there a way to be able to use types from inside
a Policy as a default template argument for a class
definition? That is, something like:

template<typename T>
struct MyPolicy { typedef T my_type; };

template <
template <typename U> class Policy,
typename V = typename Policy<U>::my_type
>
struct Host {
...
};


[ See http://www.yqcomputer.com/ ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
 
 

Policies and Default Template Arguments

Post by Axte » Fri, 20 Jan 2006 00:38:56


One workaround method I used recently is to use a subclass.
Example:
struct value_arithmetic_semantic_policy
{
template<class T> struct return_type{typedef T type;}; //Subclass
};

template<class T,
class ARITHMETIC_SEMANTIC_POLICY = value_arithmetic_semantic_policy>
class smart_ptr
{
typedef typename ARITHMETIC_SEMANTIC_POLICY::template
return_type<smart_ptr>::type arith_retrn_type;
};

For the full example, see following link:
http://www.yqcomputer.com/


[ See http://www.yqcomputer.com/ ]
[ comp.lang.c++.moderated. First time posters: Do this! ]