00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00047 #ifndef STLSOFT_INCL_STLSOFT_CONVERSION_HPP_LITERAL_CAST
00048 #define STLSOFT_INCL_STLSOFT_CONVERSION_HPP_LITERAL_CAST
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define STLSOFT_VER_STLSOFT_CONVERSION_HPP_LITERAL_CAST_MAJOR 4
00052 # define STLSOFT_VER_STLSOFT_CONVERSION_HPP_LITERAL_CAST_MINOR 0
00053 # define STLSOFT_VER_STLSOFT_CONVERSION_HPP_LITERAL_CAST_REVISION 4
00054 # define STLSOFT_VER_STLSOFT_CONVERSION_HPP_LITERAL_CAST_EDIT 44
00055 #endif
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00070 # include <stlsoft/stlsoft.h>
00071 #endif
00072 #ifndef STLSOFT_INCL_STLSOFT_UTIL_H_LIMIT_TRAITS
00073 # include <stlsoft/util/limit_traits.h>
00074 #endif
00075
00076
00077
00078
00079
00080 #ifndef _STLSOFT_NO_NAMESPACE
00081 namespace stlsoft
00082 {
00083 #endif
00084
00085
00086
00087
00088
00089 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00090 # ifdef STLSOFT_CF_64BIT_INT_SUPPORT
00091 typedef ss_sint64_t literal_cast_int_t;
00092 typedef ss_uint64_t invalid_int_t;
00093 # else
00094 typedef ss_sint32_t literal_cast_int_t;
00095 typedef ss_uint32_t invalid_int_t;
00096 # endif
00097 #endif
00098
00099 #if 0
00100 template< ss_typename_param_k T
00101 , literal_cast_int_t V
00102 >
00103 inline T literal_cast()
00104 {
00105 #if defined(STLSOFT_CF_MEMBER_CONSTANT_SUPPORT)
00106
00107 const int __literal_cast_value_too_large__ = V <= limit_traits<T>::maximum_value;
00108 const int __literal_cast_value_too_small__ = V >= limit_traits<T>::minimum_value;
00109
00110 STLSOFT_STATIC_ASSERT(__literal_cast_value_too_large__);
00111 STLSOFT_STATIC_ASSERT(__literal_cast_value_too_small__);
00112 #else
00113
00114 const int __literal_cast_value_too_large__ = V <= limit_traits<T>::maximum();
00115 const int __literal_cast_value_too_small__ = V >= limit_traits<T>::minimum();
00116
00117 STLSOFT_MESSAGE_ASSERT("Literal cast value is too large", __literal_cast_value_too_large__);
00118 STLSOFT_MESSAGE_ASSERT("Literal cast value is too small", __literal_cast_value_too_small__);
00119 #endif
00120
00121 return T(V);
00122 }
00123 #else
00124
00140 template< ss_typename_param_k T
00141 , literal_cast_int_t V
00142 >
00143 class literal_cast
00144 {
00145 public:
00146 operator T () const
00147 {
00148 #if defined(STLSOFT_CF_MEMBER_CONSTANT_SUPPORT)
00149
00150 const int __literal_cast_value_too_large__ = V <= limit_traits<T>::maximum_value;
00151 const int __literal_cast_value_too_small__ = V >= limit_traits<T>::minimum_value;
00152
00153 STLSOFT_STATIC_ASSERT(__literal_cast_value_too_large__);
00154 STLSOFT_STATIC_ASSERT(__literal_cast_value_too_small__);
00155 #else
00156
00157 const int __literal_cast_value_too_large__ = V <= limit_traits<T>::maximum();
00158 const int __literal_cast_value_too_small__ = V >= limit_traits<T>::minimum();
00159
00160 STLSOFT_MESSAGE_ASSERT("Literal cast value is too large", __literal_cast_value_too_large__);
00161 STLSOFT_MESSAGE_ASSERT("Literal cast value is too small", __literal_cast_value_too_small__);
00162 #endif
00163
00164 return T(V);
00165 }
00166 };
00167
00168
00169 #ifdef STLSOFT_CF_TEMPLATE_PARTIAL_SPECIALISATION_SUPPORT
00170
00172 template<literal_cast_int_t V>
00173 class literal_cast<invalid_int_t, V>
00174 {
00175 public:
00176 # if 0
00177 literal_cast()
00178 {
00179 const int STLSOFT_LITERAL_CAST_INVALID_TYPE_WARNING = 0;
00180
00181 STLSOFT_STATIC_ASSERT(STLSOFT_LITERAL_CAST_INVALID_TYPE_WARNING);
00182 }
00183 # endif
00184
00185 private:
00186 operator invalid_int_t () const
00187 {
00188 const int __literal_cast_cannot_cast_to_largest_unsigned_integer_type__ = 0;
00189
00190 STLSOFT_STATIC_ASSERT(__literal_cast_cannot_cast_to_largest_unsigned_integer_type__);
00191
00192 return 0;
00193 }
00194
00195 # if defined(STLSOFT_COMPILER_IS_GCC)
00196 public: static void f() {}
00197 # endif
00198 };
00199 #endif
00200
00201 #endif
00202
00204
00205
00206 #ifdef STLSOFT_UNITTEST
00207 # include "./unittest/literal_cast_unittest_.h"
00208 #endif
00209
00210
00211
00212 #ifndef _STLSOFT_NO_NAMESPACE
00213 }
00214 #endif
00215
00216
00217
00218 #endif
00219
00220