fork download
  1. #include <bits/stdc++.h>
  2. #include <typeinfo>
  3. using namespace std;
  4. void show(string r,string t){printf("ref='%s'; tmp='%s';\n",r.c_str(),t.c_str());}
  5. template<class TYPE>
  6. void foo(TYPE&ref,bool a,bool b){
  7. TYPE tmp=ref; // <---- тут беда, если foo звать как foo<T&>(...);
  8. if(a)tmp="a";
  9. if(b)ref="b";
  10. show(ref,tmp);cout<<__PRETTY_FUNCTION__;
  11. }
  12. int main(){
  13. #define F(CODE){string s="s";printf("%s // ",#CODE);CODE;}
  14. F( foo<string&>(s,1,0); );
  15. F( foo<string >(s,1,0); );
  16. F( foo<string&>(s,0,1); );
  17. F( foo<string >(s,0,1); );
  18. F( foo<string&>(s,1,1); );
  19. F( foo<string >(s,1,1); );
  20. #undef F
  21. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
foo<string&>(s,1,0); // ref='a'; tmp='a';
void foo(TYPE &, bool, bool) [TYPE = std::__cxx11::basic_string<char> &]foo<string >(s,1,0); // ref='s'; tmp='a';
void foo(TYPE &, bool, bool) [TYPE = std::__cxx11::basic_string<char>]foo<string&>(s,0,1); // ref='b'; tmp='b';
void foo(TYPE &, bool, bool) [TYPE = std::__cxx11::basic_string<char> &]foo<string >(s,0,1); // ref='b'; tmp='s';
void foo(TYPE &, bool, bool) [TYPE = std::__cxx11::basic_string<char>]foo<string&>(s,1,1); // ref='b'; tmp='b';
void foo(TYPE &, bool, bool) [TYPE = std::__cxx11::basic_string<char> &]foo<string >(s,1,1); // ref='b'; tmp='a';
void foo(TYPE &, bool, bool) [TYPE = std::__cxx11::basic_string<char>]