Skip to content

C++23 #1027

@elazarg

Description

@elazarg

High-Value Changes

  • std::unreachable() - Replace assert(false); return {}
    15+ sites in marshal.cpp, cfg_builder.cpp, printing.cpp, finite_domain.cpp. The current pattern compiles out in Release, silently entering UB. std::unreachable() makes the intent explicit and lets the optimizer exploit it.

  • std::expected<T, E> - Replace std::variant<T, std::string> for errors
    unmarshal() returns std::variant<InstructionSeq, std::string> — a classic error-or-value. std::expected is purpose-built for, enables monadic .and_then() chaining, and is clearer at every call site (check.cpp, ebpf_yaml.cpp, test_verify.cpp).

  • std::optional monadic operations (.and_then(), .transform())
    20+ sites follow the pattern if (!opt) return; use(*opt). Especially impactful in ebpf_checker.cpp, ebpf_transformer.cpp,
    finite_domain.cpp, array_domain.cpp where multiple optional checks chain together.

  • std::flat_map / std::flat_set - Replace boost::container::flat_map
    zone_domain.cpp already uses boost::container::flat_map. Switching to std::flat_map removes a Boost dependency. Many small std::map/std::set uses in type_domain.cpp (median ~3 entries) and the static lookup tables in parse.cpp would also benefit from cache-friendly flat containers.

  • std::move_only_function - Replace std::function
    The join_over_types callback in type_to_num.hpp is a hot path. The lambdas passed to it capture large state but are never copied - std::move_only_function avoids the heap allocation std::function requires. Also applies in label.hpp and marshal.cpp.


Medium-Value Changes

  • std::to_underlying() - Replace manual static_cast<uint32_t>(enum_val)
    ~10 sites, mainly the flag operators in kfunc.hpp and type_to_bit() in type_encoding.hpp. Small readability win.

  • views::enumerate - Replace manual index loops
    type_domain.cpp has several for (size_t i = 0; i < v.size(); i++) loops that could be for (auto [i, val] : v | views::enumerate).

  • views::join_with - Replace manual separator logic
    typeset_to_string() in type_domain.cpp manually iterates with a "not-last" check for commas. views::join_with(", ") expresses directly.

  • std::format / std::print adoption
    20+ string concatenation sites (std::string("prefix: ") + std::to_string(val)) in kfunc.cpp, ebpf_checker.cpp, etc. std::format is C++20 so already available; C++23 adds std::print/std::println to avoid intermediate strings.


Low-Value / Opportunistic

  • static lambdas -Minor codegen improvement
  • Deducing this for Visitor structs in ebpf_checker.cpp, printing.cpp. Useful if const/non-const overloads appear

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions