gtopt/map_reserve.hpp file

Generic capacity-reservation helper for associative containers.

Defines a single free function gtopt::map_reserve(map, n) that reserves capacity for n elements in any standard or boost associative container, dispatched via C++26 requires-expressions on the actual argument type rather than on the flat_map backend macros in fmap.hpp.

Behaviour by container:

  • boost::container::flat_map, std::unordered_map, any vector-backed container exposing .reserve(size_t) → calls .reserve(n).
  • std::flat_map (which has no .reserve() of its own) → extracts the underlying key/value containers, reserves on each, then replace()s.
  • std::map, std::set, etc. (no reserve, no extract) → no-op.

Calling with n == 0 is a no-op for every container, mirroring the behaviour of the legacy helper that previously lived in fmap.hpp.

This header intentionally pulls in nothing beyond <utility> so that TUs which only use std::unordered_map (and never touch flat_map) do not have to transitively include <flat_map> or boost::container.

Namespaces

namespace gtopt