fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template < typename Derived, typename R, typename T >
  5. struct cascade_call_base {
  6.  
  7. typedef R result_type;
  8.  
  9. typedef T param_type;
  10. typedef param_type const & param_ref;
  11.  
  12. typedef std::vector<param_type> params_type;
  13. typedef params_type const & params_ref;
  14.  
  15. struct param_packer {
  16. Derived & callee;
  17. params_type params;
  18.  
  19. param_packer( Derived & callee, param_ref first )
  20. : callee(callee), params( 1, first )
  21. { }
  22.  
  23. param_packer& operator,( param_ref append ) {
  24. params.push_back( append );
  25. return *this;
  26. }
  27.  
  28. operator result_type() {
  29. return callee.invoke( params );
  30. }
  31. };
  32.  
  33. param_packer
  34. operator,( param_ref first ) {
  35. return param_packer( static_cast<Derived&>(*this), first );
  36. }
  37. };
  38.  
  39. struct Test : cascade_call_base<Test,int,int> {
  40. result_type
  41. invoke( params_ref params ) {
  42. return params.size();
  43. }
  44. } test;
  45.  
  46. int main() {
  47.  
  48. using namespace std;
  49.  
  50. cout << (test,1,2,3) << endl;
  51. cout << (test,4,5) << endl;
  52. }
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
3
2