fork(3) download
  1. template<typename... args>
  2. struct stream_op
  3. {
  4. unsigned int size() { return sizeof...(args); }
  5. };
  6.  
  7. template<typename... A, typename B>
  8. stream_op<A..., B> operator<<(stream_op<A...> a, B b)
  9. {
  10. // Do stuff
  11. return stream_op<A..., B>();
  12. }
  13.  
  14. stream_op<> empty;
  15.  
  16. #include <iostream>
  17. int main()
  18. {
  19. std::cout << "length = " << (empty << 1 << 2).size() << "\n";
  20. std::cout << "length = " << (empty << 1 << 2 << 3).size() << "\n";
  21. std::cout << "length = " << (empty << 1 << 2 << 3 << 4).size() << "\n";
  22. }
  23.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
length = 2
length = 3
length = 4