Replace std::result_of (removed in C++20) with std::invoke_result - #155
Open
jsmbennett wants to merge 2 commits into
Open
Replace std::result_of (removed in C++20) with std::invoke_result#155jsmbennett wants to merge 2 commits into
jsmbennett wants to merge 2 commits into
Conversation
std::result_of was deprecated in C++17 and removed in C++20. libstdc++
still provides it as an extension, so GCC/Linux builds are unaffected,
but libc++ does not -- which makes the engine fail to compile on macOS
(and any other libc++ target) with:
error: no template named 'result_of' in namespace 'std'
Since simulant/signals/signal.h is reachable from nearly every public
header, this breaks essentially every translation unit, including those
of downstream projects linking the engine.
Three changes:
* threads/future.h: reimplement the local result_of_t alias on top of
std::invoke_result via a small partial specialization, so the existing
result_of_t<Function(Args...)> call sites are unchanged.
* coroutines/helpers.h: std::result_of<Func()>::type is spelled
std::invoke_result<Func>::type.
* signals/signal.h: drop `typedef std::result_of<Signature> result;`.
This one is not a mechanical substitution: Signature is a function
type such as void(int), so result_of treats the return type void as
the callable and the trait has no ::type at all. It resolves to an
empty struct, is unused in-tree, and cannot be meaningfully used out
of tree, so it is removed rather than translated.
std::invoke_result is C++17, so this keeps the C++17 compatibility added
in 2175228. Verified by building the engine on macOS/arm64 with
AppleClang and libc++, where it previously failed.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
AppConfig::resizable (default false, so existing behaviour is unchanged) is threaded to the platform window via Window::set_resizable(), which Application::construct_window calls before create_window -- SDL bakes the resize flag in at SDL_CreateWindow time. A setter rather than a create_window parameter keeps the KOSWindow/PSPWindow/AndroidWindow signatures untouched; those backends simply never read the flag. SDL2Window then ORs in SDL_WINDOW_RESIZABLE, applies a 320x240 minimum size, and handles SDL_WINDOWEVENT_SIZE_CHANGED (rather than RESIZED, which misses SDL_SetWindowSize and fullscreen toggles) by pushing the new size through the new Window::set_size(). That updates width_/height_ and dispatches EventListener::on_window_resize, joining the existing on_window_focus/blur/minimize/restore family. Consumers only need to recompute camera aspect ratios: Viewport stores ratios of the render target, so the compositor resolves glViewport from the new size every frame on its own. Also fixes a latent bug in the same handler: SDL_PollEvent is global and initialize_screen() can create a second "Virtual Screen" window, so SDL_WINDOWEVENT now filters on windowID before touching focus state. Note that engine code caching window size at construction (stats_panel, scenes/splash, input_manager's normalized coordinates) will be stale after a resize; those are untouched here. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
std::result_ofwas deprecated in C++17 and removed in C++20. libstdc++ still ships it as an extension, so GCC/Linux builds never notice — but libc++ does not, so the engine currently fails to compile on macOS (and any other libc++ target):Because
simulant/signals/signal.his reachable from nearly every public header, this breaks essentially every translation unit — both in-tree and in downstream projects that link the engine. On AppleClang 21 / macOS 15 arm64 a clean build produces 35 such errors.Changes
simulant/threads/future.h— the localresult_of_talias is reimplemented onstd::invoke_resultvia a small partial specialization, so the existingresult_of_t<Function(Args...)>call sites inasync()are untouched.simulant/coroutines/helpers.h—std::result_of<Func()>::type→std::invoke_result<Func>::type(3 sites, including the two friend declarations).simulant/signals/signal.h— removestypedef std::result_of<Signature> result;.This last one is deliberately not a mechanical substitution, and is worth a second look.
Signaturehere is a function type such asvoid(int), soresult_oftreats the return typevoidas the callable rather than the signature's return type. Since C++14result_ofis SFINAE-friendly, sostd::result_of<void(int)>is simply an empty struct with no::type:It is unused in-tree (
grepfinds no reference tosignal<...>::result) and can't be meaningfully used out of tree, so removing it seemed better than translating a typedef that never worked. Happy to instead define it as a real return-type trait if you'd prefer to keep the name.Compatibility
std::invoke_resultis C++17, so this preserves the C++17 compatibility added in 2175228. The replacement trait was checked against functors, lambdas, function pointers andvoid-returning callables under both-std=c++17and-std=c++20.Testing
SIMULANT_BUILD_SAMPLES=OFF SIMULANT_BUILD_TESTS=OFF) — previously failed outright.libsimulant.dyliband runs correctly against the GL2X renderer.std::invoke_resultis standard in both libstdc++ and libc++; I don't have a Linux box to hand, so a CI run there would be worth confirming.🤖 Generated with Claude Code