00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef GRAPHLAB_ROBUST_CAST_HPP
00019 #define GRAPHLAB_ROBUST_CAST_HPP
00020
00021 #include <boost/utility.hpp>
00022 #include <boost/type_traits/is_convertible.hpp>
00023 namespace graphlab {
00024
00025
00026
00027 template <typename Target, typename Source>
00028 typename boost::disable_if_c<boost::is_convertible<Source, Target>::value,
00029 Target>::type
00030 robust_cast(const Source &h) {
00031 return Target();
00032 }
00033
00034 template <typename Target, typename Source>
00035 typename boost::enable_if_c<boost::is_convertible<Source, Target>::value,
00036 Target>::type
00037 robust_cast(const Source &h) {
00038 return (Target)h;
00039 }
00040 }
00041
00042 #endif
00043
00044