gtopt/fmap.hpp file

flat_map type alias and map utility helpers

This module defines the flat_map alias and two map utility helpers:

map_reserve(map, n) Reserve capacity for n elements. Generic over flat_map, std::unordered_map, std::flat_map, and std::map (no-op). Defined in map_reserve.hpp, re-exported from this header for backward compatibility.

map_insert_sorted_unique(map, first, last) Insert from a pre-sorted, deduplicated range using the most efficient API for each backend.

Backend selection (can be overridden by defining one of the macros before including this header):

GTOPT_USE_STD_FLAT_MAP - std::flat_map (default for GCC >= 15 and Clang >= 23, only when <flat_map> is available) GTOPT_USE_BOOST_FLAT_MAP - boost::container::flat_map (default for all other compilers / older versions)

gtopt::flat_map must always resolve to a vector-backed flat map. There is deliberately no std::map fallback: if neither <flat_map> nor <boost/container/flat_map.hpp> is available the build fails with a #error. Call sites that genuinely want an ordered red-black-tree map must use std::map directly instead of gtopt::flat_map.

Namespaces

namespace gtopt