Skip to main content
1 vote
1 answer
217 views

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-...
Oersted's user avatar
  • 4,029
6 votes
4 answers
288 views

Sometimes, it may be useful to build an integral value from a list of bits (in increasing order). Such a function could be named to_integral. Example: static_assert (to_integral(1,1,0,1,0,1) == ...
abcdefg's user avatar
  • 5,207
2 votes
1 answer
255 views

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 ...
user31597808's user avatar
0 votes
1 answer
133 views

A simple function like: constexpr int f(int x) { constexpr int y = x; return y; } Seems to not be legal because x is not constexpr. This complaint is made even before I call the function, ...
sh1's user avatar
  • 5,020
4 votes
1 answer
268 views

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 ...
Oersted's user avatar
  • 4,029
3 votes
0 answers
63 views

Here is the test code: #include <type_traits> enum class ShaderType:unsigned{ Vertex = 0, Fragment = 1, }; template<ShaderType type> struct ShaderTypeHolder{ static constexpr ...
Shenghua Lin's user avatar
2 votes
2 answers
116 views

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, ...
AR-47's user avatar
  • 23
0 votes
1 answer
331 views

I have a constexpr function that calculates CRC at compile time. I need to create a map between CRCs that are generated by this function and string inputs and use them in runtime (Even better if it is ...
Bahram Pouryousefi's user avatar
1 vote
3 answers
307 views

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 ...
PaperBirdMaster's user avatar
2 votes
1 answer
302 views

How can I get a constexpr size from a std::set, which I can use to return a std::array with the number of elements in the std::set in C++23 or to-be C++26, as far as supported by either G++ oder Clang?...
Torsten Knodt's user avatar
0 votes
1 answer
90 views

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. ...
vohir's user avatar
  • 23
1 vote
2 answers
231 views

I'm trying to make a constexpr function which will run both at compile and runtime depending on the call.The function will check a unsigned long and will return a number depending on it's value. ...
NormakLOE32's user avatar
9 votes
2 answers
1k views

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 ...
Oersted's user avatar
  • 4,029
0 votes
1 answer
152 views

I think cout is only allowed to run at runtime but the following code proves otherwise. Or am I not understanding something deeper? I only expected it to print the message once, but it printed twice. ...
ntos's user avatar
  • 379
0 votes
1 answer
180 views

[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 ...
John Kalane's user avatar
  • 1,195

15 30 50 per page
1
2 3 4 5