#include <iostream>
#include <type_traits>
#include <stdexcept>
#include <utility>
template <class Object, class MemFun, class... Args>
struct HasNoExceptMemFun
{
static constexpr bool value =
noexcept (((std::declval <Object> ()).*(MemFun ()))(std::declval <Args>()...));
};
template <bool which>
class Is;
template <>
struct Is <false>
{
void operator () ()
{
std::cout << "false" << std::endl;
}
};
template <>
struct Is <true>
{
void operator () ()
{
std::cout << "true" << std::endl;
}
};
class Foo
{
Foo (int) {}
public:
void Baz (int) noexcept (true)
{
}
};
class Bar
{
public:
void Baz (int) throw (std::runtime_error)
{
throw std::runtime_error ("help!");
}
};
template <typename T, typename F>
struct selection
{
static void dispatch ()
{
Is <HasNoExceptMemFun <T, F, int>::value> () ();
}
};
int main() {
selection <Foo, decltype (&Foo::Baz)>::dispatch ();
selection <Bar, decltype (&Bar::Baz)>::dispatch ();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+CiNpbmNsdWRlIDxzdGRleGNlcHQ+CiNpbmNsdWRlIDx1dGlsaXR5PgoKdGVtcGxhdGUgPGNsYXNzIE9iamVjdCwgY2xhc3MgTWVtRnVuLCBjbGFzcy4uLiBBcmdzPgpzdHJ1Y3QgSGFzTm9FeGNlcHRNZW1GdW4KewoJc3RhdGljIGNvbnN0ZXhwciBib29sIHZhbHVlID0KCSAgICBub2V4Y2VwdCAoKChzdGQ6OmRlY2x2YWwgPE9iamVjdD4gKCkpLiooTWVtRnVuICgpKSkoc3RkOjpkZWNsdmFsIDxBcmdzPigpLi4uKSk7Cn07Cgp0ZW1wbGF0ZSA8Ym9vbCB3aGljaD4KY2xhc3MgSXM7Cgp0ZW1wbGF0ZSA8PgpzdHJ1Y3QgSXMgPGZhbHNlPgp7Cgl2b2lkIG9wZXJhdG9yICgpICgpCgl7CgkgICAgc3RkOjpjb3V0IDw8ICJmYWxzZSIgPDwgc3RkOjplbmRsOwoJfQp9OwoKdGVtcGxhdGUgPD4Kc3RydWN0IElzIDx0cnV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