Skip to content

feat(utility): add bind_front for enum_switch partial application (#200) - #471

Open
ezralicodes wants to merge 4 commits into
Neargye:masterfrom
ezralicodes:feat/bind-front-200
Open

feat(utility): add bind_front for enum_switch partial application (#200)#471
ezralicodes wants to merge 4 commits into
Neargye:masterfrom
ezralicodes:feat/bind-front-200

Conversation

@ezralicodes

Copy link
Copy Markdown

Summary

Adds magic_enum::bind_front to magic_enum_utility.hpp as a C++17-friendly partial-application helper. Maintainer suggested this for nested enum_switch use cases on MSVC (#200).

Also documents the GCC 16 C++26 enum_flags_cast workaround (#467).

Test plan

  • New doctest bind_front case in test/test.cpp
  • CI matrix (existing tests)

…argye#200)

Signed-off-by: ezralicodes <ezralicodes@users.noreply.github.com>
…argye#200)

Signed-off-by: ezralicodes <ezralicodes@users.noreply.github.com>
…argye#200)

Signed-off-by: ezralicodes <ezralicodes@users.noreply.github.com>
…argye#200)

Signed-off-by: ezralicodes <ezralicodes@users.noreply.github.com>
Comment thread doc/limitations.md

* Zero is not reflected for flag enums.

* GCC 16 with `-std=c++26` may miscompile string parsing that uses `find`/`remove_prefix` on flag names. `enum_flags_cast` uses an explicit token loop instead; see [#467](https://github.com/Neargye/magic_enum/issues/467).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was never required and should be removed; internal documentation remains in the comments.

Comment thread test/test.cpp
}
}

TEST_CASE("bind_front") {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test does not verify fix for issue #200.

@Neargye

Neargye commented Aug 15, 2026

Copy link
Copy Markdown
Owner

Please also export bind_front from magic_enum.cppm and cover it in test_module.cpp.

constexpr decltype(auto) operator()(CallArgs&&... call_args) const {
return std::apply(
fn_,
std::tuple_cat(bound_,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid tuple_cat here: it copies bound arguments into a temporary and breaks mutable callables, lvalue references, move-only values, and reference returns. Invoke the stored arguments directly via std::get, preserving the wrapper value category with &, const&, &&, and const&& overloads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants