如何在C++中剥离一个类型的所有信息

How do i strip all info of a type in C++?

本文关键字:类型 一个 信息 C++ 剥离      更新时间:2023-10-16

假设我有一个static const int*constconst int&。我需要它的结果int,以便在模板中使用。如何去掉所有数据,得到一个简单的int

decayremove_pointer的组合:

#include <type_traits>
typedef typename std::remove_pointer<typename std::decay<T>::type>::type TStrip;

这将完成任务:

template <typename T>
struct strip
{
  typedef T type;
};
template <typename T>
struct strip<const T&>
{
  typedef T type;
};
template <typename T>
struct strip<const T* const>
{
  typedef T type;
};

请参阅http://ideone.com/ZNFkm

相关文章: