synaps/base/TypeTests.h

00001 #ifndef SYNAPS_UTIL_TYPE_TESTS_H
00002 #define SYNAPS_UTIL_TYPE_TESTS_H
00003 #include <synaps/init.h>
00004 
00005 __BEGIN_NAMESPACE_SYNAPS
00006 
00007 namespace Type
00008 {
00009   struct false_t{};
00010   struct true_t{};
00011   struct null_t {};
00012   template<bool test, class A, class B>
00013   struct If 
00014   { 
00015     typedef A result_t;  
00016   };
00017   
00018   template<class A,class B>
00019   struct If<false,A,B> 
00020   { 
00021     typedef B result_t; 
00022   };
00023   
00024   template<class A,class B>
00025   struct Eq 
00026   { 
00027     enum { result = 0 }; 
00028     typedef false_t result_t; 
00029   };
00030   
00031   template<class A>
00032   struct Eq<A,A> 
00033   { 
00034     enum { result = 1 }; 
00035     typedef true_t result_t; 
00036   };
00037   
00038   template<class A>
00039   struct ValueType
00040   { 
00041     typedef typename A::value_type result_t; 
00042   };
00043   
00044   template<class A, int n >
00045   struct ValueType< A[n] >
00046   {
00047     typedef A result_t;
00048   };
00049   template<class A>
00050   struct ValueType<A*>
00051   { 
00052     typedef  A result_t; 
00053   };
00054   
00055   template<int n>
00056   struct Int {};
00057   
00058   template<bool b> struct BoolType { typedef false_t result_t; };
00059   template<> struct BoolType<true> { typedef true_t result_t; };
00060 
00061   template<class X>
00062   struct deconst{
00063     typedef X result_t;
00064   };
00065   template<class X>
00066   struct deconst< const X> { typedef X result_t; };
00067 
00068   template<class A,class B>
00069   struct Sup
00070   {
00071     typedef typename deconst<A>::result_t result_t;
00072   };
00073   
00074   template<class el, class nx>
00075   struct Pair
00076   {
00077     typedef el element_t;
00078     typedef nx next_t;
00079   };
00080   
00081 };
00082 
00083 #define typelist1(a)     Type::Pair< a, Type::null_t >
00084 #define typelist2(a,b)   Type::Pair< a, typelist1(b) >
00085 #define typelist3(a,b,c) Type::Pair< a, typelist2(b,c) >
00086 #define typelist4(a,b,c) Type::Pair< a, typelist3(b,c,d) >
00087 
00088 __END_NAMESPACE_SYNAPS
00089 
00090 #endif

SYNAPS DOCUMENTATION
logo