fork(2) download
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. struct Trace
  8. {
  9. Trace() { cout << "X()\n"; }
  10. ~Trace() { cout << "~X()\n"; }
  11. Trace(Trace const &) { cout << "X(X&)\n"; }
  12. Trace(Trace&&) { cout << "X(X&&)\n"; }
  13. void operator=(Trace const &) { cout << "X::op=(X&)\n"; }
  14. void operator=(Trace &&) { cout << "X::op=(X&&)\n"; }
  15. };
  16.  
  17. struct Big
  18. {
  19. vector<int> vec;
  20. Big(size_t n): vec(n) {}
  21. bool operator<(Big const &r) const { return vec.size() < r.vec.size(); }
  22.  
  23. Trace trace;
  24. };
  25.  
  26. template<typename T>
  27. T mmin( std::initializer_list<T> x )
  28. {
  29. return * std::min_element( x.begin(), x.end() );
  30. }
  31.  
  32. template<typename T, typename... Args> T vmin( T arg1, Args&&... args )
  33. {
  34. T *p[] = { &arg1, &args... };
  35.  
  36. return **std::min_element( begin(p), end(p),
  37. [](T *a, T *b) { return *a < *b; } );
  38. }
  39.  
  40. Big make_big(size_t n) { return Big(n); }
  41.  
  42. int main()
  43. {
  44. Big a(100), b(200);
  45.  
  46. Big const &t =
  47. //min<Big>({ make_big(400), b , a , make_big(600) })
  48. //mmin<Big>({ make_big(400), b , a , make_big(600) })
  49. vmin<Big>( make_big(400), b , a , make_big(600) )
  50. ;
  51.  
  52. cout << t.vec.size() << endl;
  53. }
  54.  
Success #stdin #stdout 0s 3228KB
stdin
Standard input is empty
stdout
X()
X()
X()
X()
X(X&)
~X()
~X()
100
~X()
~X()
~X()