Orxonox  0.0.5 Codename: Arcturus
TypeManip.h
Go to the documentation of this file.
1 // The Loki Library
3 // Copyright (c) 2001 by Andrei Alexandrescu
4 // This code accompanies the book:
5 // Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
6 // Patterns Applied". Copyright (c) 2001. Addison-Wesley.
7 // Permission to use, copy, modify, distribute and sell this software for any
8 // purpose is hereby granted without fee, provided that the above copyright
9 // notice appear in all copies and that both that copyright notice and this
10 // permission notice appear in supporting documentation.
11 // The author or Addison-Welsey Longman make no representations about the
12 // suitability of this software for any purpose. It is provided "as is"
13 // without express or implied warranty.
14 //
15 // Changes by Orxonox (Reto Grieder)
16 // Removed templates we didn't need
18 #ifndef LOKI_TYPEMANIP_INC_
19 #define LOKI_TYPEMANIP_INC_
20 
21 // $Id: TypeManip.h 749 2006-10-17 19:49:26Z syntheticpp $
22 
23 
24 namespace Loki
25 {
27 // class template Int2Type
28 // Converts each integral constant into a unique type
29 // Invocation: Int2Type<v> where v is a compile-time constant integral
30 // Defines 'value', an enum that evaluates to v
32 
33  template <int v>
34  struct Int2Type
35  {
36  enum { value = v };
37  };
38 
40 // class template Type2Type
41 // Converts each type into a unique, insipid type
42 // Invocation Type2Type<T> where T is a type
43 // Defines the type OriginalType which maps back to T
45 
46  template <typename T>
47  struct Type2Type
48  {
49  typedef T OriginalType;
50  };
51 
53 // class template Select
54 // Selects one of two types based upon a boolean constant
55 // Invocation: Select<flag, T, U>::Result
56 // where:
57 // flag is a compile-time boolean constant
58 // T and U are types
59 // Result evaluates to T if flag is true, and to U otherwise.
61 
62  template <bool flag, typename T, typename U>
63  struct Select
64  {
65  typedef T Result;
66  };
67  template <typename T, typename U>
68  struct Select<false, T, U>
69  {
70  typedef U Result;
71  };
72 
74 // class template IsSameType
75 // Return true iff two given types are the same
76 // Invocation: SameType<T, U>::value
77 // where:
78 // T and U are types
79 // Result evaluates to true iff U == T (types equal)
81 
82  template <typename T, typename U>
83  struct IsSameType
84  {
85  enum { value = false };
86  };
87 
88  template <typename T>
89  struct IsSameType<T,T>
90  {
91  enum { value = true };
92  };
93 
94 } // namespace Loki
95 
96 
97 #endif // end file guardian
98 
Definition: NullType.h:21
Definition: TypeManip.h:34
Definition: TypeManip.h:83
T OriginalType
Definition: TypeManip.h:49
U Result
Definition: TypeManip.h:70
Definition: InputPrereqs.h:78
Definition: TypeManip.h:47
T Result
Definition: TypeManip.h:65
Definition: TypeManip.h:36
Definition: InputPrereqs.h:80
Definition: TypeManip.h:63