Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/environment2/src/external/loki/TypeManip.h

Last change on this file was 7266, checked in by rgrieder, 14 years ago

Moved Loki library files to separate loki folder in externals.
Also added TypeManip.h (now used in Convert.h) and static_check.h.

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1////////////////////////////////////////////////////////////////////////////////
2// 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
17////////////////////////////////////////////////////////////////////////////////
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
24namespace Loki
25{
26////////////////////////////////////////////////////////////////////////////////
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
31////////////////////////////////////////////////////////////////////////////////
32
33    template <int v>
34    struct Int2Type
35    {
36        enum { value = v };
37    };
38   
39////////////////////////////////////////////////////////////////////////////////
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
44////////////////////////////////////////////////////////////////////////////////
45
46    template <typename T>
47    struct Type2Type
48    {
49        typedef T OriginalType;
50    };
51   
52////////////////////////////////////////////////////////////////////////////////
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.
60////////////////////////////////////////////////////////////////////////////////
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   
73////////////////////////////////////////////////////////////////////////////////
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)
80////////////////////////////////////////////////////////////////////////////////
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
Note: See TracBrowser for help on using the repository browser.