c++ - 为什么add_const<T>中的T若为引用则add_const<T>::type仍为T?
阿神
阿神 2017-04-17 13:13:34
0
2
612

为什么add_const对引用无效,比如我认为,add_const<int &>::type应该是const int &才对,
而实际上,add_const<int &>::type仍旧是int &

阿神
阿神

闭关修行中......

reply all(2)
迷茫

References only have underlying const, not top-level const.
If add_const<int &> changes int &, its type will be int &const, which is obviously wrong

阿神
template <typename T, 
    bool = is_reference<T>::value ||
    is_function<T>::value ||
    is_const<T>::value
>
struct add_const;

Then I wrote specializations of true and false

To add a reference, there are one add_lvalue_reference and add_rvalue_reference

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template