fork download
  1. #include <algorithm>
  2. #include <memory>
  3. #include <vector>
  4. #include <iostream>
  5.  
  6. struct Boo {
  7. int val;
  8. explicit Boo(const int val) : val(val) {}
  9. };
  10.  
  11.  
  12. int main() {
  13. std::vector<std::shared_ptr<Boo>> vec;
  14. vec.push_back(std::make_shared<Boo>(1));
  15. vec.push_back(std::make_shared<Boo>(2));
  16. vec.push_back(std::make_shared<Boo>(3));
  17. auto min1 = std::min_element(vec.begin(), vec.end(), [](auto& x, auto& y) { return x->val < y->val; });
  18. auto min2 = *std::min_element(vec.begin(), vec.end(), [](auto& x, auto& y) { return x->val < y->val; });
  19. std::cout << typeid(min1).name() << "\n" << typeid(min2).name();
  20. return 0;
  21. }
Success #stdin #stdout 0s 4344KB
stdin
Standard input is empty
stdout
N9__gnu_cxx17__normal_iteratorIPSt10shared_ptrI3BooESt6vectorIS3_SaIS3_EEEE
St10shared_ptrI3BooE