#include <iostream>
#include <string>
using namespace std;
class function_set {
public:
static bool overload( const char * s ) { cout << "一つ目 " << s << " で呼ばれた" << endl; return true; }
static bool overload( string s ) { cout << "一つ目 " << s << " で呼ばれた" << endl; return false; }
};
// [&] で呼び出したスコープで有効なものを可視にしてる
// 関数の呼び出し処理の前や後に内部の処理を入れたかった
#define probe3( funct, ... ) \
[&]() -> decltype( funct( __VA_ARGS__ ) ) { \
if( !has_dummy_result ) { \
return funct( __VA_ARGS__ ); \
} \
return dummy_result; \
}()
bool dummy_result = false;
bool has_dummy_result = false;
void clear_dummy_result() { has_dummy_result = false; }
void set_dummy_result( bool result ) { dummy_result = result; has_dummy_result = true; }
void probe3_test() {
cout << "一つ目 " << boolalpha << probe3( function_set::overload, "aaaa" ) << " を返した" << endl;
cout << "二つ目 " << boolalpha << probe3( function_set::overload, (string)"aaaa" ) << " を返した" << endl;
}
int main() {
clear_dummy_result();
probe3_test();
set_dummy_result( false );
probe3_test();
set_dummy_result( true );
probe3_test();
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgZnVuY3Rpb25fc2V0IHsKcHVibGljOgoJc3RhdGljIGJvb2wgb3ZlcmxvYWQoIGNvbnN0IGNoYXIgKiBzICkgeyBjb3V0IDw8ICLkuIDjgaTnm64gIiA8PCBzIDw8ICIg44Gn5ZG844Gw44KM44GfIiA8PCBlbmRsOyByZXR1cm4gdHJ1ZTsgfQoJc3RhdGljIGJvb2wgb3ZlcmxvYWQoIHN0cmluZyBzICkgeyBjb3V0IDw8ICLkuIDjgaTnm64gIiA8PCBzIDw8ICIg44Gn5ZG844Gw44KM44GfIiA8PCBlbmRsOyByZXR1cm4gZmFsc2U7IH0KfTsKCi8vIFsmXSDjgaflkbzjgbPlh7rjgZfjgZ/jgrnjgrPjg7zjg5fjgafmnInlirnjgarjgoLjga7jgpLlj6/oppbjgavjgZfjgabjgosKLy8g6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