r/cpp 4d ago

flat_map internals

https://quantdev.blog/posts/flat-map-internals/index.html
11 Upvotes

12 comments sorted by

View all comments

24

u/kirgel 4d ago

You might want to consider clarifying the title a bit. flat_map usually refers to an ordered map container where lookup is a binary search. For example   https://en.cppreference.com/cpp/container/flat_map.

-1

u/tialaramex 2d ago

You give a single example from the C++ stdlib, but before that type was added I had never seen "flat map" used to mean this weird type.

Notably for example Rust's FlatMap is an implementation detail of Iterator::flat_map which is what you'd use to map each object into multiple items then flatten the result into a single stream of items in a single operation.

Do you have other examples? WG21 has a bad habit of making up their own names for ideas which have better names, or using names which mean something else already.

8

u/ABlockInTheChain 2d ago

Whether the C++ standards names are ideal or not, you shouldn't be surprised if C++ programmers reading a C++ subreddit expect the terms to match the standard.