#compile time variadic argument check

29 messages · Page 1 of 1 (latest)

coarse pumiceBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

hardy horizon
#

Arguments of a function are never considered to be constexpr inside of the function

#

Even if the function is running at compile-time

#

Yet the return value of that function can be constexpr for its caller

#

The only way this can work is by making the function consteval, and instead of using a static_assert, failing in some other way, e.g. by throwing

rancid hamlet
hardy horizon
#

Typically (e.g. in std::format) they do this by wrapping the format string in a class like format_string<Args...> and giving that a constexpr consteval constructor from a string, and validating the format string in that constructor

#

So the rest of the format() function doesn't need to be consteval

hardy horizon
rancid hamlet
#

wat

#

how

#

why

hardy horizon
#

It means it successfully detected the format string error. If the throw wasn't actually reached, it would compile

rancid hamlet
hardy horizon
#

Yeah, but if you make the params constexpr, you suddenly have types in your function that can depend on those parameters

#

Essentially turning it into a template if it was allowed

rancid hamlet
hardy horizon
#

Yeah, but still having the types depend on values would be wild

blazing wharf
hardy horizon
blazing wharf
#

normally in C++ you know from identity of a function and the argument types what the result type will be, not sure you'd want to drop that

hardy horizon
#

Yep

rancid hamlet
#

yeah that makes sense.

coarse pumiceBOT
#

This question is being automatically marked as stale.
If your question has been answered, type !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.