STL 中的iterator_traits與SGI專有的__type_traits在PJ中的使用

classShape

{

public:

 

     Shape()

     {

         cout<<"Shape"<<endl;

     }

};

struct__true_type{};

struct__false_type{};

template<class class_type>

struct__type_traits

{

     typedef __true_type this_dummy_memeber;

     typedef __false_type has_trivial_default_constructor;

     typedef __false_type has_trivial_copy_constructor;

     typedef __false_type has_trivial_assignment_operator;

     typedef __false_type has_trivial_destructor;

     typedef __false_type is_POD_type;

};

template<>struct __type_traits<Shape*>

{

     typedef __true_type has_trivial_default_constructor;

     typedef __true_type has_trivial_copy_constructor;

     typedef __true_type has_trivial_assignment_operator;

     typedef __true_type has_trivial_destructor;

     typedef __true_type is_POD_type;

};

template<class T>

inline void test(T& t)

{

     return__test(t,&iterator_traits<T*>::value_type());//生成了一個臨時對象

}

template<class T,class T1>

inline void __test(T& t,T1*)

{

     typedef typename__type_traits<T1*>::is_POD_type is_POD;

     return __test1(t,is_POD());

}

template<class T>

inline void __test1(T& t,__false_type)

{

     cout<<"test_1_false_type"<<endl;

}

template<class T>

inline void __test1(T t,__true_type)

{

     cout<<"test_1_true_type"<<endl;

}

 

intmain()

{

     Shapea;

     test(a);

     return 0;

}

發佈了27 篇原創文章 · 獲贊 15 · 訪問量 28萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章