fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Tensor
  5. {
  6. public:
  7. Tensor& setA() { cout << "A"; return *this; }
  8. Tensor& setB() { cout << "B"; return *this; }
  9. Tensor& setC() { cout << "C"; return *this; }
  10. Tensor& setD() { cout << "D"; return *this; }
  11. Tensor& setE() { cout << "E"; return *this; }
  12. Tensor& noOp() { return *this; }
  13. void build() { cout << endl; }
  14. };
  15.  
  16. void doTest(bool flag)
  17. {
  18. Tensor& (Tensor::*temp)() = flag ? &Tensor::setE : &Tensor::noOp;
  19.  
  20. (Tensor{}
  21. .setA()
  22. .setB()
  23. .setC()
  24. .setD()
  25. .*temp)()
  26. .build();
  27. }
  28.  
  29. int main()
  30. {
  31. doTest(false);
  32. doTest(true);
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5444KB
stdin
Standard input is empty
stdout
ABCD
ABCDE