#include <stdio.h>
#include <type_traits>
#include <typeinfo>
struct Base {};
struct OfBase: public Base {};
struct NotBase {};
template <typename T1, typename T2, typename = void>
struct select_base
{
typedef T1 type;
};
template <typename T1, typename T2>
struct select_base<T1, T2, typename std::enable_if<
std::is_base_of<Base, T2>::value, T2>::type>
{
typedef T2 type;
};
int main()
{
printf("Expected OfBase: %s\n", typeid(typename select_base<NotBase, OfBase>::type).name());
printf("Expected OfBase: %s\n", typeid(typename select_base<OfBase, NotBase>::type).name());
return 0;
}
ICAgICNpbmNsdWRlIDxzdGRpby5oPgogICAgI2luY2x1ZGUgPHR5cGVfdHJhaXRzPgogICAgI2luY2x1ZGUgPHR5cGVpbmZvPgoKICAgIHN0cnVjdCBCYXNlIHt9OwogICAgc3RydWN0IE9mQmFzZTogcHVibGljIEJhc2Uge307CiAgICBzdHJ1Y3QgTm90QmFzZSB7fTsKICAgIHRlbXBsYXRlIDx0eXBlbmFtZSBUMSwgdHlwZW5hbWUgVDIsIHR5cGVuYW1lID0gdm9pZD4KICAgIHN0cnVjdCBzZWxlY3RfYmFzZQogICAgewogICAgICAgIHR5cGVkZWYgVDEgdHlwZTsKICAgIH07CiAgICB0ZW1wbGF0ZSA8dHlwZW5hbWUgVDEsIHR5cGVuYW1lIFQyPgogICAgc3RydWN0IHNlbGVjdF9iYXNlPFQxLCBUMiwgdHlwZW5hbWUgc3RkOjplbmFibGVfaWY8CiAgICAgICAgc3RkOjppc19iYXNlX29mPEJhc2UsIFQyPjo6dmFsdWUsIFQyPjo6dHlwZT4KICAgIHsKICAgICAgICB0eXBlZGVmIFQyIHR5cGU7CiAgICB9OwogICAgaW50IG1haW4oKQogICAgewogICAgICAgcHJpbnRmKCJFeHBlY3RlZCBPZkJhc2U6ICVzXG4iLCB0eXBlaWQodHlwZW5hbWUgc2VsZWN0X2Jhc2U8Tm90QmFzZSwgT2ZCYXNlPjo6dHlwZSkubmFtZSgpKTsKICAgICAgIHByaW50ZigiRXhwZWN0ZWQgT2ZCYXNlOiAlc1xuIiwgdHlwZWlkKHR5cGVuYW1lIHNlbGVjdF9iYXNlPE9mQmFzZSwgTm90QmFzZT46OnR5cGUpLm5hbWUoKSk7CiAgICAgICByZXR1cm4gMDsKICAgIH0=