Skip to content

Fix C++17 support - #702

Open
RobLoach wants to merge 5 commits into
ChaiScript:developfrom
RobLoach:fixes-for-c17
Open

Fix C++17 support#702
RobLoach wants to merge 5 commits into
ChaiScript:developfrom
RobLoach:fixes-for-c17

Conversation

@RobLoach

@RobLoach RobLoach commented May 2, 2026

Copy link
Copy Markdown
Contributor

This attempts to fix some of the C++17 compatibility. ChaiScript is advertised as C++17 compatible, so we should either do that, or move to C++20.

@lefticus lefticus mentioned this pull request Aug 12, 2026
@lrosenthol

Copy link
Copy Markdown

For context: we independently wrote our own C++17-compatibility shims for the same set of issues this PR addresses (std::span, std::type_identity_t, string_view::starts_with/ends_with, std::ssize/parser pointer arithmetic, and a couple of dependent-name typename fixes). Comparing the two approaches side by side turned up a few things that might be useful here:

Issue This PR (#702) Our independent fix
std::span (C++20-only) Re-adds the old pre-span Function_Params class as the C++17 fallback (constexpr, begin/end pointers). Normalizes call sites to Function_Params{&x, &x+1} (begin, end) so behavior matches in both modes. New minimal fallback with a generic SFINAE'd container constructor and a (ptr, count) constructor, mirroring std::span's primary constructor. Call sites use Function_Params{&x, 1} (ptr, count) instead. Also guards with _MSVC_LANG >= 202002L in addition to __cplusplus, since MSVC won't report __cplusplus correctly without /Zc:__cplusplus — worth adding here too, otherwise the C++17 fallback path may silently be taken (or not) incorrectly on MSVC.
std::type_identity_t Defines type_identity/type_identity_t inside namespace std, which is technically UB (users can't add non-specialization declarations to std::). Defines it in chaiscript:: instead — avoids the namespace pollution.
string_view::starts_with/ends_with #if-branches between the real methods (C++20) and a hand-written compare()-based version (C++17). Same compare()-based logic, but written once, unconditionally — valid under both standards without the #if branch.
std::ssize/std::next in the parser #if-branches between std::ssize (C++20) and (int)std::size (C++17). std::next(begin, static_cast<ptrdiff_t>(size)) unconditionally, sidestepping the need for std::ssize entirely.

Happy to share the full internal diff if useful, but figured the comparison itself might be worth having on this thread.

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