Why does boost::add_const exclude T&?

R

Ruki

BOOST_TT_AUX_TYPE_TRAIT_DEF1(add_const,T,T const)
BOOST_TT_AUX_TYPE_TRAIT_PARTIAL_SPEC1_1(typename T,add_const,T&,T&)
 
D

dizzy

Ruki said:
BOOST_TT_AUX_TYPE_TRAIT_DEF1(add_const,T,T const)
BOOST_TT_AUX_TYPE_TRAIT_PARTIAL_SPEC1_1(typename T,add_const,T&,T&)

It does not exclude it, it actually makes it compile with reference types
too. You wouldn't want to try to form the type "T& const" now do you?
(since such a type is invalid in C++03). You would want it to return just
T& in that case.

In case you confuse "constification" of a "T&" type with making it a "T
const&" let me tell you, that boost::add_const does not do that for
pointers either, if you will add_const<T*>::type what you get is a "T*
const" type (this time, a valid C++03 unlike the above "T& const" one) and
not a "T const*" which is probably what you seem to be wanting.
 

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,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top