fork download
  1. #include <iostream>
  2. #include <set>
  3.  
  4. template <typename ,typename>
  5. struct swap_set_comparator{};
  6.  
  7. template <typename new_comp,typename set_type,typename comp,typename alloc>
  8. struct swap_set_comparator<new_comp,std::set<set_type,comp,alloc> >
  9. {
  10. using type = std::set<set_type,new_comp,alloc>;
  11. };
  12.  
  13. template <typename container, typename... Args,typename Func>
  14. auto make_set(Args&&... args,Func&& f)
  15. {
  16. return typename swap_set_comparator<Func,container>::type(std::forward<Args>(args)...,std::forward<Func>(f));
  17. }
  18.  
  19.  
  20. int main()
  21. {
  22. auto comparator = [](int *a, int *b){return *a<*b;};
  23. std::set<int*,decltype(comparator)> S(comparator);
  24.  
  25. // or
  26.  
  27. auto S2 = make_set<std::set<int*>>([](int *a, int *b){return *a<*b;});
  28. return 0;
  29. }
Success #stdin #stdout 0s 4356KB
stdin
Standard input is empty
stdout
Standard output is empty