标准C ++删除一个类型的所有指针11路 [英] standard c++11 way to remove all pointers of a type

查看:119
本文介绍了标准C ++删除一个类型的所有指针11路的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用一些C ++ 11或至多boost库做到这一点?

 的#include<&iostream的GT;
#包括LT&;&所属类别GT;
使用命名空间std;模板< typename的T>类remove_all_pointers {
上市:
    typedef的T形;
};模板< typename的T>类remove_all_pointers< T *> {
上市:
    的typedef typename的remove_all_pointers< T> ::类型类型;
};诠释主(){
    //打印正确的i上的gcc
    COUT<< typeid的(remove_all_pointers< INT ****> ::型)。名称()<< ENDL;
}


解决方案

无论是加速还是C ++ 11的特性这样的特征模板。但是你的code应该工作。

Is there a way to do this with some c++11 or at most a boost library?

#include <iostream>
#include <typeinfo>
using namespace std;

template <typename T> class remove_all_pointers{
public:
    typedef T type;
};

template <typename T> class remove_all_pointers<T*>{
public:
    typedef typename remove_all_pointers<T>::type type;
};

int main(){
    //correctly prints 'i' on gcc
    cout<<typeid(remove_all_pointers<int****>::type).name()<<endl;
}

解决方案

Neither Boost nor C++11 features such a trait template. But your code should work.

这篇关于标准C ++删除一个类型的所有指针11路的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆