Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
1 vote
1 answer
215 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-...
6 votes
4 answers
286 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
  • 4,945
2 votes
1 answer
253 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 ...
0 votes
1 answer
132 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
239 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 ...
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 ...
2 votes
2 answers
115 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, ...
0 votes
1 answer
317 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 ...
1 vote
3 answers
301 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 ...
2 votes
1 answer
299 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?...
0 votes
1 answer
89 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. ...
1 vote
2 answers
225 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. ...
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 ...
0 votes
1 answer
149 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. ...
0 votes
1 answer
178 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 ...

15 30 50 per page
1
2 3 4 5

AltStyle によって変換されたページ (->オリジナル) /