#include <iostream>
#include <type_traits>
template<int I,class T>
struct static_case {
static constexpr int value = I;
using type = T;
};
template<int I, class DefaultType, class Case1, class... OtherCases>
struct static_switch{
using type = typename std::conditional< I==Case1::value ,
typename Case1::type,
typename static_switch<I,DefaultType,OtherCases...>::type
>::type;
};
struct fail_on_default {};
template<int I, class DefaultType, class LastCase>
struct static_switch<I,DefaultType,LastCase> {
using type = typename std::conditional< I==LastCase::value ,
typename LastCase::type,
DefaultType
>::type;
static_assert(!(std::is_same<type, fail_on_default>::value),
"Default case reached in static_switch!");
};
template<class T>
typename static_switch<sizeof(T)
,fail_on_default // default case
,static_case<sizeof(long long),long long>
>::type foo(T bar){ return reinterpret_cast<decltype(foo(bar))&>(bar);}
struct test{
int a,b,c;
};
auto val = foo(13.0);
//auto val = foo(test());
static_assert(std::is_same<long long, decltype(val)>::value,"Not converted to long long!");
using namespace std;
int main(){
// your code goes here
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+IAogCnRlbXBsYXRlPGludCBJLGNsYXNzIFQ+IApzdHJ1Y3Qgc3RhdGljX2Nhc2UgeyAKCXN0YXRpYyBjb25zdGV4cHIgaW50IHZhbHVlID0gSTsgCgl1c2luZyB0eXBlID0gVDsgCn07Cgp0ZW1wbGF0ZTxpbnQgSSwgY2xhc3MgRGVmYXVsdFR5cGUsIGNsYXNzIENhc2UxLCBjbGFzcy4uLiBPdGhlckNhc2VzPiAKc3RydWN0IHN0YXRpY19zd2l0Y2h7IAoJdXNpbmcgdHlwZSA9IHR5cGVuYW1lIHN0ZDo6Y29uZGl0aW9uYWw8IEk9PUNhc2UxOjp2YWx1ZSAsICAKCQkJCQl0eXBlbmFtZSBDYXNlMTo6dHlwZSwgCgkJCQkJdHlwZW5hbWUgc3RhdGljX3N3aXRjaDxJLERlZmF1bHRUeXBlLE90aGVyQ2FzZXMuLi4+Ojp0eXBlIAoJCQkJICAgICA+Ojp0eXBlOyAKfTsgCgpzd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