Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
std::set custom ordering with composition
#include <iostream> #include <unordered_set> #include <unordered_map> #include <set> struct S { S(int order) : order(order) {} int order; }; namespace std { template<> struct less<S*> { bool operator()(const S* lhs, const S* rhs) const noexcept { std::cout << "mijau\n"; return lhs->order < rhs->order; } }; } void f() { S x(1); S y(2); S z(3); std::set<S*> modules = {&x, &y, &z}; for(const auto& module : modules) std::cout << module->order << '\n'; std::unordered_map<int, std::set<S*>> map; map[0]; } void g() { const auto comparator = [](const S* lhs, const S* rhs) -> bool { std::cout << "mijau\n"; return lhs->order < rhs->order; }; S x(1); S y(2); S z(3); auto modules = std::set<S*, decltype(comparator)>({&x, &y, &z}, comparator); for(const auto& module : modules) std::cout << module->order << '\n'; std::unordered_map<int, std::set<S*, decltype(comparator)>> map; //map[0]; // breaks } int main() { f(); g(); }
run
|
edit
|
history
|
help
0
Tree Traversal and Node
regimeketopdfb
Composite pattern
Unqualified free functions
Integer conversions
HexDong
vector destruction - clang
sort
12/2
Fun with Pointers #2