#include <iostream>
using namespace std;
struct Foo {};
int foo(int) { return 0; }
Foo foo(double) { return Foo(); }
// no foo(const char*)
struct Bar { Bar(bool) {} };
ostream& operator << (ostream& ost, Bar&& bar) { return ost << "BARR"; }
Bar operator , (Foo&&, bool) { return Bar(true); } // ВНЕЗАПНО!
// требование к then-ветке функции: чтобы была определена функция foo(T)
template<class T> auto test1(T&& t) -> decltype(foo(t), true) { return true; }
auto test1(...) -> bool { return false; }
template<class T> auto test2(T&& t) -> decltype(foo(t), void(0), true) { return true; }
auto test2(...) -> bool { return false; }
int main()
{
cout << boolalpha << test1(1) << " " << test1(1.) << " " << test1("") << endl; // true BARR false
cout << boolalpha << test2(1) << " " << test2(1.) << " " << test2("") << endl; // true true false
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IEZvbyB7fTsKCmludCBmb28oaW50KSB7IHJldHVybiAwOyB9CkZvbyBmb28oZG91YmxlKSB7IHJldHVybiBGb28oKTsgfQovLyBubyBmb28oY29uc3QgY2hhciopCgpzdHJ1Y3QgQmFyIHsgQmFyKGJvb2wpIHt9IH07Cm9zdHJlYW0mIG9wZXJhdG9yIDw8IChvc3RyZWFtJiBvc3QsIEJhciYmIGJhcikgeyByZXR1cm4gb3N0IDw8ICJCQVJSIjsgfQoKQmFyIG9wZXJhdG9yICwgKEZvbyYmLCBib29sKSB7IHJldHVybiBCYXIodHJ1ZSk7IH0gLy8g0JLQndCV0JfQkNCf0J3QniEKCi8vINGC0YDQtdCx0L7QstCw0L3QuNC1INC6IHRoZW4t0LLQtdGC0LrQtSDRhNGD0L3QutGG0LjQuDog0YfRgtC+0LHRiyDQsdGL0LvQsCDQvtC/0YDQtdC00LXQu9C10L3QsCDRhNGD0L3QutGG0LjRjyBmb28oVCkKCnRlbXBsYXRlPGNsYXNzIFQ+IGF1dG8gdGVzdDEoVCYmIHQpIC0+IGRlY2x0eXBlKGZvbyh0KSwgdHJ1ZSk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