#include <cassert>
#include <type_traits>
#include <iostream>
class CByteArray { public: CByteArray() {}};
class Variant {};
template<typename T>
CByteArray serializePodType(const T&)
{
printf("serializePodType\n");
return CByteArray();
}
CByteArray serializeVariant(const Variant& v)
{
printf("serializeVariant\n");
return CByteArray();
}
template <typename T>
typename std::enable_if<std::is_pod<T>::value, CByteArray>::type serialize(const T& value)
{
return serializePodType(value);
}
template <typename T>
typename std::enable_if<std::is_convertible<T, Variant>::value && !std::is_pod<T>::value, CByteArray>::type serialize(const T& value)
{
return serializeVariant(Variant(value));
}
class ConvertibleToVariant : public Variant { virtual void foo(); };
struct POD {};
struct NonPOD { virtual void foo(); };
int main()
{
POD pod;
ConvertibleToVariant ctv;
//NonPOD nonpod;
const auto ctv_serialised = serialize(ctv);
const auto pod_serialised = serialize(pod);
//const auto nonpod_serialised = serialize(nonpod);
}
I2luY2x1ZGUgPGNhc3NlcnQ+CiNpbmNsdWRlIDx0eXBlX3RyYWl0cz4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgQ0J5dGVBcnJheSB7IHB1YmxpYzogQ0J5dGVBcnJheSgpIHt9fTsKCmNsYXNzIFZhcmlhbnQge307Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBUPgpDQnl0ZUFycmF5IHNlcmlhbGl6ZVBvZFR5cGUoY29uc3QgVCYpCnsKICBwcmludGYoInNlcmlhbGl6ZVBvZFR5cGVcbiIpOwogIHJldHVybiBDQnl0ZUFycmF5KCk7Cn0KCkNCeXRlQXJyYXkgc2VyaWFsaXplVmFyaWFudChjb25zdCBWYXJpYW50JiB2KQp7CiAgcHJpbnRmKCJzZXJpYWxpemVWYXJpYW50XG4iKTsKICByZXR1cm4gQ0J5dGVBcnJheSgpOwp9Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4KdHlwZW5hbWUgc3RkOjplbmFibGVfaWY8c3RkOjppc19wb2Q8VD46OnZhbHVlLCBDQnl0ZUFycmF5Pjo6dHlwZSBzZXJpYWxpemU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