Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:34:28

0001 #pragma once
0002 
0003 #include <cstdint>
0004 #include <string>
0005 #include <type_traits>
0006 
0007 // Safe type conversions (without narrowing) to be used for properties,
0008 // gets arround the limitations of type-erasure without explicitly needing
0009 // to specify template arguments in setProperty etc.
0010 
0011 namespace algorithms::detail {
0012 template <typename T, typename Enable = void> struct upcast_type { using type = T; };
0013 template <typename UInt>
0014 struct upcast_type<UInt, std::enable_if_t<std::is_integral_v<UInt> && !std::is_signed_v<UInt>>> {
0015   using type = uint64_t;
0016 };
0017 template <typename Int>
0018 struct upcast_type<Int, std::enable_if_t<std::is_integral_v<Int> && std::is_signed_v<Int>>> {
0019   using type = int64_t;
0020 };
0021 template <typename Enum> struct upcast_type<Enum, std::enable_if_t<std::is_enum_v<Enum>>> {
0022   using type = int64_t;
0023 };
0024 template <typename Float>
0025 struct upcast_type<Float, std::enable_if_t<std::is_floating_point_v<Float>>> {
0026   using type = double;
0027 };
0028 template <typename String>
0029 struct upcast_type<String, std::enable_if_t<std::is_convertible_v<String, std::string>>> {
0030   using type = std::string;
0031 };
0032 template <> struct upcast_type<bool> { using type = bool; };
0033 
0034 template <class T> using upcast_type_t = typename upcast_type<T>::type;
0035 
0036 template <class T> upcast_type_t<T> upcast(T&& value) { return value; }
0037 
0038 } // namespace algorithms::detail
0039