Eggs.KeyedSet
Eggs.KeyedSet is a C++23 ordered associative
container that stores unique Value objects indexed by a designated
member field —see it on Github—.
Contents
Requirements
The library requires a standard conformant implementation of C++23. There are no external dependencies.
The library is continuously tested with the following configurations:
- GCC 14
- Clang 18 (libstdc++ and libc++)
- Apple LLVM 16 (Xcode)
- MSVC 2022
Synopsis
namespace eggs {
template <
typename Value,
auto Key,
typename Compare = std::less<key-type>,
typename Allocator = std::allocator<Value>
>
class keyed_set;
} // namespace eggs
Quick Example
#include <eggs/keyed_set.hpp>
struct Employee { int id; std::string name; };
eggs::keyed_set<Employee, &Employee::id> roster;
roster.insert({101, "Alice"});
roster.insert({102, "Bob"});
roster.insert({103, "Carol"});
// Heterogeneous lookup: find by int, no Employee construction required
if (auto it = roster.find(102); it != roster.end())
std::cout << it->name << '\n'; // Bob
// Iteration is in ascending key order
for (auto const& e : roster)
std::cout << e.id << ' ' << e.name << '\n';
// Custom comparator: descending order
eggs::keyed_set<Employee, &Employee::id, std::greater<int>> desc;

