首页 > 为什么add_const<T>中的T若为引用则add_const<T>::type仍为T?

为什么add_const<T>中的T若为引用则add_const<T>::type仍为T?

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


引用只有底层const,没有顶层const。
假如add_const<int &>对int &产生改变,则其type会是int &const,显然是不对的


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

然后写了true和false的特化

要加reference有一个add_lvalue_referenceadd_rvalue_reference

【热门文章】
【热门文章】