CppUnit project page CppUnit home page

typetraits.h

Go to the documentation of this file.
00001 #ifndef CPPTL_TYPETRAITS_H_INCLUDED
00002 # define CPPTL_TYPETRAITS_H_INCLUDED
00003 
00004 # include <cpptl/forwards.h>
00005 
00006 // @todo move this to a header dedicated to basic generic programming technics
00007 
00008 
00009 namespace CppTL
00010 {
00011 
00016    template<class T>
00017    struct RemoveConst
00018    {
00019       typedef T type;
00020    };
00021 
00022    #if !defined( CPPTL_NO_TEMPLATE_PARTIAL_SPECIALIZATION )
00023 
00024    template<class T>
00025    struct RemoveConst<const T>
00026    {
00027       typedef T type;
00028    };
00029 
00030    #endif
00031 
00032 
00033 
00034 
00035 
00036 
00037    //@todo BooleanType should be moved to a simple generic programming header.
00038    template<const bool isTrue>
00039    struct BooleanType
00040    {
00041    };
00042 
00043    typedef BooleanType<false> FalseType;
00044    typedef BooleanType<true> TrueType;
00045 
00046 
00047 
00048 
00049 #if !defined(CPPTL_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
00050 
00056    template<typename A, typename B, const bool condition>
00057    struct IfType
00058    {
00059       typedef A type;
00060    };
00061 
00064    template<typename A, typename B>
00065    struct IfType<A,B,false>
00066    {
00067       typedef B type;
00068    };
00069 #else // work-around lack of template partial specialization using template member
00071    template<typename A, typename B, const bool condition>
00072    struct IfType
00073    {
00074       template<const bool condition>
00075       struct Selector
00076       {
00077          typedef A type;
00078       };
00079       template<>
00080       struct Selector<false>
00081       {
00082          typedef B type;
00083       };
00084 
00085       typedef CPPTL_TYPENAME Selector<condition>::type type;
00086    };
00087 #endif
00088 
00089 } // namespace CppTL
00090 
00091 #endif // CPPTL_TYPETRAITS_H_INCLUDED

SourceForge Logo hosts this site. Send comments to:
CppUnit Developers