Changeset 7365 for code/branches/doc/src/libraries/util
- Timestamp:
- Sep 6, 2010, 2:35:53 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/doc/src/libraries/util/Convert.h
r7364 r7365 161 161 } 162 162 }; 163 164 ////////////165 // upcast //166 ////////////167 namespace detail168 {169 // perform a static cast if ToType is a base of FromType170 template<class ToType, class FromType>171 FORCEINLINE ToType upcast(FromType input, Loki::Int2Type<true>)172 {173 return static_cast<ToType>(input);174 }175 176 // return zero if ToType is not a base of FromType177 template<class ToType, class FromType>178 FORCEINLINE ToType upcast(FromType input, Loki::Int2Type<false>)179 {180 return 0;181 }182 }183 184 // performs an upcast if ToType is a base of FromType, returns zero otherwise185 template <class ToType, class FromType>186 FORCEINLINE ToType upcast(FromType input)187 {188 enum { probe = ImplicitConversion<FromType, ToType>::exists };189 return detail::upcast<ToType, FromType>(input, Loki::Int2Type<probe>());190 }191 163 } 192 164 … … 381 353 } 382 354 383 template<class FromType, class ToType>384 FORCEINLINE ToType getConvertedValue(const FromType& input)385 {386 ToType output;387 convertValue(&output, input);388 return output;389 }390 391 355 /// Directly returns the converted value, but uses the fallback on failure. @see convertValue 392 356 template<class FromType, class ToType> … … 443 407 /// Conversion would exhibit ambiguous << or >> operators when using iostream 444 408 template <> 445 template <>446 409 struct ConverterExplicit<unsigned char, std::string> 447 410 { … … 453 416 }; 454 417 /// Conversion would exhibit ambiguous << or >> operators when using iostream 455 template <>456 418 template <> 457 419 struct ConverterExplicit<std::string, char>
Note: See TracChangeset
for help on using the changeset viewer.