]> Dogcows Code - chaz/yoink/blob - src/cml/core/meta/common.h
now using cml for vectors and math stuff
[chaz/yoink] / src / cml / core / meta / common.h
1 /* -*- C++ -*- ------------------------------------------------------------
2
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
4
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
7
8 *-----------------------------------------------------------------------*/
9 /** @file
10 * @brief
11 */
12
13 #ifndef core_meta_common_h
14 #define core_meta_common_h
15
16 namespace cml {
17
18 /** Type of a true statement. */
19 struct true_type {};
20
21 /** Type of a false statement. */
22 struct false_type {};
23
24 template<bool B> struct is_true {
25 typedef false_type result;
26 };
27
28 template<> struct is_true<true> {
29 typedef true_type result;
30 };
31
32 /** A "type pair". */
33 template<typename T1, typename T2> struct type_pair {
34 typedef T1 first;
35 typedef T2 second;
36 };
37
38 /** A "type quadruple". */
39 template<typename T1, typename T2, typename T3, typename T4>
40 struct type_quad {
41 typedef T1 first;
42 typedef T2 second;
43 typedef T3 third;
44 typedef T3 fourth;
45 };
46
47 /** Match any type (for use with same_type<> and select_switch<>). */
48 struct any_type {};
49
50 /** Determine if two types are the same.
51 *
52 * Defaults to false.
53 */
54 template<typename T, typename U> struct same_type {
55 typedef false_type result;
56 enum { is_true = false, is_false = true };
57 };
58
59 /** Match the same type for both of same_type's template arguments. */
60 template<typename T> struct same_type<T,T> {
61 typedef true_type result;
62 enum { is_true = true, is_false = false };
63 };
64
65 /** Match a type and any_type. */
66 template<typename T> struct same_type<T,any_type> {
67 typedef true_type result;
68 enum { is_true = true, is_false = false };
69 };
70
71 /** Match a type and any_type. */
72 template<typename T> struct same_type<any_type,T> {
73 typedef true_type result;
74 enum { is_true = true, is_false = false };
75 };
76
77 /** Disambiguate pair of any_type's. */
78 template<> struct same_type<any_type,any_type> {
79 typedef true_type result;
80 enum { is_true = true, is_false = false };
81 };
82
83 } // namespace cml
84
85 #endif
86
87 // -------------------------------------------------------------------------
88 // vim:ft=cpp
This page took 0.0337 seconds and 4 git commands to generate.