boost 提供了 remove_pointer ,不过不够,有的时候我们需要拿掉一个“指向指针的指针……的指针”类型上面所有的“指针”前缀,所以下面这个 remove_all_pointer 就有用了,当然它还很不完善,这里先备份,慢慢修改:
#include <boost/mpl/vector.hpp>#include <boost/mpl/find.hpp>#include <boost/mpl/size.hpp>#include <boost/mpl/empty.hpp>#include <boost/mpl/front.hpp>#include <boost/mpl/end.hpp>#include <boost/mpl/deref.hpp>#include <boost/type_traits/is_same.hpp>#include <boost/type_traits/is_pointer.hpp>#include <boost/type_traits/remove_pointer.hpp>using namespace std;using namespace boost;template <typename T>struct remove_all_pointer{ typedef T type;};template <typename T>struct remove_all_pointer<T*>{ typedef typename remove_all_pointer<T>::type type;};看来是非常容易,测试呢:
#include <string>#include <iostream>#include "remove_all_pointer.hpp"int main(){ typedef remove_all_pointer<char***>::type result; cout << typeid(result).name() << endl; typedef remove_pointer<char** const*>::type res1; cout << typeid(res1).name() << endl; cin.get();}结果不用我说了。
发表于 @
2005年11月15日 22:54:00 | | 编辑|
举报| 收藏