开发者

Is there a type-trait to remove top-level cv and reference at once?

I just want to know if there is already one provided by the standard. I know it's easy to make one yourself

// for C++03, use <tr1/type_traits> and std::tr1
#include <type_traits>

template<开发者_Python百科class T>
struct remove_toplevel{
  typedef typename std::remove_reference<T>::type noref_T;
  typedef typename std::remove_cv<noref_T>::type noref_nocv_T;
  typedef noref_nocv_T type;
};

but I think I forgot something in there or got the order wrong, so it'd be nice to have a prepared one, if one exists.


std::decay, I believe, performs this functionality.


I prefer combining the two functionalities since it describes exactly what the intention is:

C++11 std::remove_cv<std::remove_reference<T>::type>::type

C++14 std::remove_cv_t<std::remove_reference_t<T>>

C++20 std::remove_cvref_t<T>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜