Skip to content

Allow asGetTypeTraits to be called in constexpr contexts#74

Open
CasualYT31 wants to merge 1 commit into
anjo76:masterfrom
CasualYT31:Make-asGetTypeTraits-constexpr
Open

Allow asGetTypeTraits to be called in constexpr contexts#74
CasualYT31 wants to merge 1 commit into
anjo76:masterfrom
CasualYT31:Make-asGetTypeTraits-constexpr

Conversation

@CasualYT31

Copy link
Copy Markdown

I've decided to move on to supporting value types in my reflective wrapper library early. As part of this, I'm working on the logic that determines which flags to apply to a given value type at compile time (which you were particularly keen on seeing implemented 👀).

Ideally, my implementation would first call asGetTypeTraits<T>(), and then compute the flags that said function cannot detect. The problem is that I only just found out that asGetTypeTraits() cannot be called at compile time. I took a quick look at its implementation and I couldn't find a reason why it shouldn't be callable at compile time, so I'm proposing that we make this function constexpr. It won't impact the way it's used today (as a constexpr function only specifies that it may be called at compile time), but it will allow me and others to call it within consteval functions, etc., should they wish to.

And seeing as constexpr was introduced in C++11, it should be perfectly fine to include it in a function that is excluded if the developer is working with an older version of the standard. But in fairness I haven't tried compiling this with anything other than the very new 16.1.0 version of GCC on Ubuntu that I'm working with.

@HenryAWE

Copy link
Copy Markdown

I'm also working on a wrapper library for AngelScript using C++20. I've reimplemented a constexpr version of asGetTypeTraits for my library (source ).
It has been tested on Clang 15-18, GCC 13-16, latest MSVC and Xcode (AppleClang). I'm pretty sure all you need is adding a single constexpr to its definition like your PR. The library can use macro to detect C++ version for keeping C++98 compatibility as it was required by some other issues iirc.

@anjo76

anjo76 commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Thanks for submitting this PR.

I can't think of any issue with declaring asGetTypeTraits as a constexpr. I'll review the PR and merge it when possible.

@anjo76 anjo76 self-assigned this Jul 16, 2026
@anjo76 anjo76 added the enhancement New feature or request label Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants