C++ 如何从模板中的指针获取类型?

C++ 如何从模板中的指针获取类型?,c++,templates,C++,Templates,我知道如何编写一些东西,但我确信有一种标准的方法可以传递类似func()的内容,并使用模板魔术提取代码中使用的类型(可能是type::SomeStaticCall) 当传递ptr时,获取该类型的标准方法/函数是什么?我认为您希望从类型参数中删除指向该函数的指针。如果是这样的话,你可以这样做 template<typename T> void func() { typename remove_pointer<T>::type type; //you can

我知道如何编写一些东西,但我确信有一种标准的方法可以传递类似
func()
的内容,并使用模板魔术提取代码中使用的类型(可能是type::SomeStaticCall)


当传递ptr时,获取该类型的标准方法/函数是什么?

我认为您希望从类型参数中删除指向该函数的指针。如果是这样的话,你可以这样做

template<typename T>
void func()
{
    typename remove_pointer<T>::type type;
    //you can use `type` which is free from pointer-ness

    //if T = int*, then type = int
    //if T = int****, then type = int 
    //if T = vector<int>, then type = vector<int>
    //if T = vector<int>*, then type = vector<int>
    //if T = vector<int>**, then type = vector<int>
    //that is, type is always free from pointer-ness
}

在C++0x中,
删除\u指针
头文件中定义。但是在C++03中,您必须自己定义它。

您应该添加一些代码来澄清这个问题。你想做什么,输入是什么?@David:我有一些东西,但没有意识到它是作为标签过滤掉的(并且没有出现)。它是从ATM开始的吗?所以删除指针不在std中?这正是我想要的,但我的直觉告诉我,stl中有一些东西我可以使用(但可能不行?)@acidzombie24:在C++0x中,是的。在C++03中,不,该死,它在C++0x中是什么?(头和我猜结构名称如果不一样)我猜我是对的一半?@ AcjZoMeBe24:C++ +0x=传入C++版本:PFRY确实不错,虽然我认为C++ 0x ReavePyPosil指针每次只删除一个指针。
template<typename T>
struct remove_pointer
{
    typedef T type;
};

template<typename T>
struct remove_pointer<T*>
{
    typedef typename remove_pointer<T>::type type;
};