Created
July 20, 2022 12:31
magic_enum -- clang: OK, msvc: FAIL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <typeinfo> | |
#include "magic_enum.hpp" | |
enum DataID { DType1, DType2, DType3 }; | |
template< DataID c > struct DataType; | |
template<> struct DataType<DType1> { using type = char; }; | |
template<> struct DataType<DType2> { using type = int; }; | |
template<> struct DataType<DType3> { using type = float; }; | |
template< DataID c > | |
using DataType_t = typename DataType<c>::type; | |
template< typename > struct DataId; | |
template<> struct DataId< typename DataType<DType1>::type > { static inline constexpr DataID value = DType1; }; | |
template<> struct DataId< typename DataType<DType2>::type > { static inline constexpr DataID value = DType2; }; | |
template<> struct DataId< typename DataType<DType3>::type > { static inline constexpr DataID value = DType3; }; | |
template< typename T > | |
constexpr DataID DataId_v = DataId<T>::value; | |
template< typename TSrc, typename TDst > | |
void convert_tmpl( [[maybe_unused]] const TSrc* src, [[maybe_unused]] TDst *dst, [[maybe_unused]] size_t count ) | |
{ | |
std::cout << "convert from " << typeid(TSrc).name() << " to " << typeid(TDst).name() << std::endl; | |
} | |
void do_convert( DataID srcId, DataID dstId, const void *src, void *dst, size_t count ) | |
{ | |
magic_enum::enum_switch([dstId,src,dst,count](auto valSrc){ | |
constexpr DataID sId = valSrc; | |
using TypeSrc = DataType_t<sId>; | |
magic_enum::enum_switch([src,dst,count](auto valDst){ | |
constexpr DataID dId = valDst; | |
using TypeDst = DataType_t<dId>; | |
convert_tmpl<TypeSrc,TypeDst>( static_cast<const TypeSrc*>(src), static_cast<TypeDst*>(dst), count ); | |
}, dstId ); | |
}, srcId ); | |
} | |
int main() | |
{ | |
magic_enum::enum_for_each<DataID>([](auto val1){ | |
magic_enum::enum_for_each<DataID>([val1](auto val2){ | |
do_convert( val1, val2, nullptr, nullptr, 0 ); | |
}); | |
}); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment