ensuring non-const equivalents

F

frs

How can I get an 'always non-const equivalent' for
the type "T" in the following example? Is there something
like a 'non_const_cast' as in the code fragment below?

template<typename T>
class A {

non_const_cast(T) x;
};

meaning that for T = 'const double',
the member x would be of type 'double'.


Thanks and Regards,

Frank
 
A

Alipha

frs said:
How can I get an 'always non-const equivalent' for
the type "T" in the following example? Is there something
like a 'non_const_cast' as in the code fragment below?

template<typename T>
class A {

non_const_cast(T) x;
};

meaning that for T = 'const double',
the member x would be of type 'double'.


Thanks and Regards,

Frank

write your own partial template specialization (hint: good google
phrase):

template<typename T>
struct non_const {
typedef T type;
};

template<typename T>
struct non_const<const T> {
typedef T type;
};

template<typename T>
class A {
typename non_const<T>::type x; // why typename here? dependent
names.
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top