common.h

Go to the documentation of this file.
00001 /* -*- C++ -*- ------------------------------------------------------------
00002  
00003 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
00004 
00005 The Configurable Math Library (CML) is distributed under the terms of the
00006 Boost Software License, v1.0 (see cml/LICENSE for details).
00007 
00008  *-----------------------------------------------------------------------*/
00013 #ifndef core_meta_common_h
00014 #define core_meta_common_h
00015 
00016 namespace cml {
00017 
00019 struct true_type {};
00020 
00022 struct false_type {};
00023 
00024 template<bool B> struct is_true {
00025     typedef false_type result;
00026 };
00027 
00028 template<> struct is_true<true> {
00029     typedef true_type result;
00030 };
00031 
00033 template<typename T1, typename T2> struct type_pair {
00034     typedef T1 first;
00035     typedef T2 second;
00036 };
00037 
00039 template<typename T1, typename T2, typename T3, typename T4>
00040 struct type_quad {
00041     typedef T1 first;
00042     typedef T2 second;
00043     typedef T3 third;
00044     typedef T3 fourth;
00045 };
00046 
00048 struct any_type {};
00049 
00054 template<typename T, typename U> struct same_type {
00055     typedef false_type result;
00056     enum { is_true = false, is_false = true };
00057 };
00058 
00060 template<typename T> struct same_type<T,T> {
00061     typedef true_type result;
00062     enum { is_true = true, is_false = false };
00063 };
00064 
00066 template<typename T> struct same_type<T,any_type> {
00067     typedef true_type result;
00068     enum { is_true = true, is_false = false };
00069 };
00070 
00072 template<typename T> struct same_type<any_type,T> {
00073     typedef true_type result;
00074     enum { is_true = true, is_false = false };
00075 };
00076 
00078 template<> struct same_type<any_type,any_type> {
00079     typedef true_type result;
00080     enum { is_true = true, is_false = false };
00081 };
00082 
00084 template<typename T> struct remove_reference {
00085     template<typename Q, typename Dummy> struct helper {
00086         typedef Q type;
00087     };
00088 
00089     template<typename Q> struct helper<Q&, void> {
00090         typedef Q type;
00091     };
00092 
00093     template<typename Q> struct helper<const Q&, void> {
00094         typedef const Q type;
00095     };
00096 
00097     typedef typename helper<T,void>::type type;
00098 };
00099 
00101 template<typename T> struct remove_const {
00102     template<typename Q, typename Dummy> struct helper {
00103         typedef Q type;
00104     };
00105 
00106     template<typename Q> struct helper<const Q, void> {
00107         typedef Q type;
00108     };
00109 
00110     typedef typename helper<T,void>::type type;
00111 };
00112 
00113 } // namespace cml
00114 
00115 #endif
00116 
00117 // -------------------------------------------------------------------------
00118 // vim:ft=cpp

Generated on Sat Jul 18 19:35:20 2009 for CML 1.0 by  doxygen 1.5.9