ivl 679
ivl/details/core/types/types.hpp
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>.
00002    A C++ template library extending syntax towards mathematical notation.
00003 
00004    Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr>
00005    Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr>
00006 
00007    ivl is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU Lesser General Public License 
00009    version 3 as published by the Free Software Foundation.
00010 
00011    Alternatively, you can redistribute it and/or modify it under the terms 
00012    of the GNU General Public License version 2 as published by the Free 
00013    Software Foundation.
00014 
00015    ivl is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00018    See the GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License 
00021    and a copy of the GNU Lesser General Public License along 
00022    with ivl. If not, see <http://www.gnu.org/licenses/>. */
00023 
00024 #ifndef IVL_CORE_DETAILS_TYPES_TYPES_HPP
00025 #define IVL_CORE_DETAILS_TYPES_TYPES_HPP
00026 
00027 namespace ivl {
00028 namespace types {
00029 
00030 template <class T, class ENABLE = t_true>
00031 struct apply_ref : public apply_ref<T, typename ENABLE::type> {};
00032 
00033 template <class T>
00034 struct apply_ref<T, t_false>
00035 {
00036         typedef T type;
00037 };
00038 
00039 template <class T>
00040 struct apply_ref<T, t_true>
00041 {
00042         typedef T& type;
00043 };
00044 
00045 template <class T>
00046 struct apply_ref<T&, t_true>
00047 {
00048         typedef T& type;
00049 };
00050 
00051 //--------------------------------------------
00052 
00053 template <class T, class ENABLE= t_true>
00054 struct apply_const : public apply_const<T, typename ENABLE::type> {};
00055 
00056 template <class T>
00057 struct apply_const<T, t_false>
00058 {
00059         typedef T type;
00060 };
00061 
00062 template <class T>
00063 struct apply_const<T, t_true>
00064 {
00065         typedef const T type;
00066 };
00067 
00068 template <class T>
00069 struct apply_const<T&, t_true>
00070 {
00071         typedef const T& type;
00072 };
00073 
00074 template <class T>
00075 struct apply_const<const T&, t_true>
00076 {
00077         typedef const T& type;
00078 };
00079 
00080 template <class T>
00081 struct apply_const<T*, t_true>
00082 {
00083         typedef const T* type;
00084 };
00085 
00086 template <class T>
00087 struct apply_const<const T*, t_true>
00088 {
00089         typedef const T* type;
00090 };
00091 
00092 //--------------------------------------------
00093 
00094 template <class T, class OBJ>
00095 struct best_ref :
00096         public best_ref<T, typename types::is_const<OBJ>::type> {};
00097 
00098 template <class T>
00099 struct best_ref<T, t_true>
00100 {
00101         typedef const T& type;
00102 };
00103 
00104 template <class T>
00105 struct best_ref<T&, t_true>
00106 {
00107         typedef T& type;
00108 };
00109 
00110 template <class T>
00111 struct best_ref<T, t_false>
00112 {
00113         typedef typename apply_ref<T>::type type;
00114 };
00115 
00116 //--------------------------------------------
00117 
00118 template <class T>
00119 struct remove_const {
00120         typedef T type;
00121 };
00122 template <class T>
00123 struct remove_const<const T> {
00124         typedef T type;
00125 };
00126 template <class T>
00127 struct remove_const<const T*> {
00128         typedef T* type;
00129 };
00130 template <class T>
00131 struct remove_const<const T&> {
00132         typedef T& type;
00133 };
00134 
00135 //--------------------------------------------
00136 
00137 template <class T>
00138 struct remove_ref {
00139         typedef T type;
00140 };
00141 template <class T>
00142 struct remove_ref<const T> {
00143         typedef const T type;
00144 };
00145 template <class T>
00146 struct remove_ref<T&> {
00147         typedef T type;
00148 };
00149 template <class T>
00150 struct remove_ref<const T&> {
00151         typedef const T type;
00152 };
00153 //--------------------------------------------
00154 
00155 // bare_type<T> gets the type T without reference and without const
00156 template <class T>
00157 struct bare_type {
00158         typedef T type;
00159 };
00160 template <class T>
00161 struct bare_type<T&> {
00162         typedef T type;
00163 };
00164 template <class T>
00165 struct bare_type<const T&> {
00166         typedef T type;
00167 };
00168 template <class T>
00169 struct bare_type<const T> {
00170         typedef T type;
00171 };
00172 
00173 //--------------------------------------------
00174 
00175 template <class T>
00176 struct deref_ptr {
00177         typedef T type;
00178 };
00179 
00180 template <class T>
00181 struct deref_ptr<T*> {
00182         typedef T type;
00183 };
00184 
00185 template <class T>
00186 struct deref_ptr<const T*> {
00187         typedef T type;
00188 };
00189 
00190 } /* namespace types */
00191 } /* namespace ivl */
00192 
00193 #endif // IVL_CORE_DETAILS_TYPES_TYPES_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations