61 questions
1 vote
1 answer
199 views
Making the non-trivial creation of an array constexpr
This is a follow-up of my answer to a question about initialization of arrays of non-default constructible types. The core of the question can be summarized to this snippet, which is an over-...
2 votes
1 answer
236 views
constexpr unsigned int * unsigned long not evaluated as unsigned long?
The following integer power function returns 0 when the result should be greater than 2^32 if the base argument is unsigned int, but works fine when the base argument type is changed to an unsigned ...
4 votes
1 answer
198 views
using throw in a constexpr or a consteval function in order to generate compile-time error
The problem Using static_assert to generate compile-time error is not always easy because it requires a constant expression as first argument. I found, on StackOverflow, several example where throw ...
2 votes
2 answers
108 views
Stroustrup book constexpr example does not compile in VS C++ 2022
I am trying to reproduce constexpr example from Stroustrup book "The C++ Programming Language" 4th Ed, pp. 265-266. I am using Visual Studio 2022 Community. The code below does not compile, ...
1 vote
3 answers
284 views
constexpr function that keeps multiplying a number until "it is big enough"
Ok, I completely messed up this question, first for the typo and second because my oversimplified minimum example didn't have any problem at all. I was considering to delete the question but seeing ...
0 votes
1 answer
88 views
How do `constexpr` "compile time pointers" work in C++?
Background Pointers cannot be used as T* p value parameters to a template (which is specialized at compile time), because the memory address &obj of some object T obj is only known at run time. ...
9 votes
2 answers
1k views
Why is it possible to use the return of a lambda, passed as argument of a constexpr function argument, in a constant expression within the function?
The wording of the question title is probably incorrect and I'll fix it happily from your suggestions. My question can be illustrated by this snippet: #include <array> template <typename ...
0 votes
1 answer
172 views
Where in the C++20 standard (N4860) does it say that an inline function must be defined before its use in a translation unit?
[dcl.constexpr]/1: The constexpr specifier shall be applied only to the definition of a variable or variable template or the declaration of a function or function template. The consteval specifier ...