Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
auto print(auto&... args) {
// c++17 fold expression
(std::cout << ... << args) << std::endl;
}
auto print_map_contents(auto mymap) {
// c++17 structured binding
for (auto [k, x] : mymap) {
print("mymap[", k, "] = ", x);
}
}
auto main() -> int {
// map is ordered map, iteration is ascending by key value
auto map = std::map<std::string, int> {
{"first entry", 12},
{"second entry", 42},
{"third entry", 3},
};
print_map_contents(map);
}
var sortedKeys = myMap.keys.toList()..sort();
for (var k in sortedKeys) {
print("Key=$k Value=${myMap[k]}");
}
mymap.sort { it.key }.each { println it}
[...mymap.entries()].sort().map(([_, x]) => console.log(x))
for k, x in pairs(mymap) do
print(k, x)
end
ksort($mymap);
foreach($mymap as $k => $v) {
echo 'k:', $k, ' ', 'v:', $v, PHP_EOL;
}
dict_pairs(D, _, Ps),
forall(member(K-V, Ps),
format("~w:~w~n", [K, V]))
for e in sorted(m.items()):
print(e)
for k in sorted(mymap):
print(mymap[k])
my_map.sort.each{|k,x| puts "#{k}: #{x}"}
for (k, x) in mymap {
println!("({}, {})", k, x);
}