#include <iostream>
#include <utility>
struct Foo {};
struct Bar { Foo _foo; };
struct Bad {};
template <typename T, typename U> struct same_type: std::false_type {};
template <typename T> struct same_type<T, T>: std::true_type {};
Foo const& to_foo(Bar const& b) { return b._foo; }
Foo& to_foo(Bar& b) { return b._foo; }
template <typename T>
struct ToFoo {
T const& _crt;
T& _rt;
template <typename U>
static auto to_foo_exists(U const& crt, U& rt) ->
decltype(to_foo(crt), to_foo(rt), std::true_type());
static std::false_type to_foo_exists(...);
static bool const value = same_type<decltype(to_foo_exists(_crt, _rt)), std::true_type>::value;
};
int main() {
std::cout << ToFoo<Bar>::value << "\n";
std::cout << ToFoo<Bad>::value << "\n";
}
ICAgICNpbmNsdWRlIDxpb3N0cmVhbT4KICAgICNpbmNsdWRlIDx1dGlsaXR5PgogCiAgICBzdHJ1Y3QgRm9vIHt9OwogICAgc3RydWN0IEJhciB7IEZvbyBfZm9vOyB9OwogICAgc3RydWN0IEJhZCB7fTsKICAgIAogICAgdGVtcGxhdGUgPHR5cGVuYW1lIFQsIHR5cGVuYW1lIFU+IHN0cnVjdCBzYW1lX3R5cGU6IHN0ZDo6ZmFsc2VfdHlwZSB7fTsKICAgIAogICAgdGVtcGxhdGUgPHR5cGVuYW1lIFQ+IHN0cnVjdCBzYW1lX3R5cGU8VCwgVD46IHN0ZDo6dHJ1ZV90eXBlIHt9OwogCiAgICBGb28gY29uc3QmIHRvX2ZvbyhCYXIgY29uc3QmIGIpIHsgcmV0dXJuIGIuX2ZvbzsgfQogICAgRm9vJiB0b19mb28oQmFyJiBiKSB7IHJldHVybiBiLl9mb287IH0KIAogICAgdGVtcGxhdGUgPHR5cGVuYW1lIFQ+CiAgICBzdHJ1Y3QgVG9Gb28gewogICAgICBUIGNvbnN0JiBfY3J0OwogICAgICBUJiBfcnQ7CiAKICAgICAgdGVtcGxhdGUgPHR5cGVuYW1lIFU+CiAgICAgIHN0YXRpYyBhdXRvIHRvX2Zvb19leGlzdHMoVSBjb25zdCYgY3J0LCBVJi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