Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
std::set custom ordering with composition
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#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(); }
clang++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.92 sec, absolute running time: 0.14 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 1,07 sec
edit mode
|
history
|
discussion
mijau mijau 1 2 3 mijau mijau 1 2 3