Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
Best practices
1 vote
5 replies
173 views

Defining a string and converting it to bytes at runtime is one thing, but I would want to have a constant array of bytes defined at design time and then pupulate it with a mix of bytes and strings. ...
3 votes
1 answer
200 views

I am trying to implement a C++ Translate function for localization. // Language package, containing key-value pairs of translation, e.g., // g_LanguagePack["HELLO@1"] = "Hello, {}!"...
2 votes
2 answers
187 views

The latest C++20 standard supports dynamic allocation memory in compile time with a limitation. The memory allocation cannot "go outside" the constant expression. That means that vector cannot be ...
2 votes
1 answer
173 views

Application startup code looks like this: CPU 8086 _start: cld mov ax, ds dec ax mov es, ax mov ax, [es:3] cmp ax, word (_endbss + 768) / 16 jae .mem ; Code would be ...
0 votes
1 answer
66 views

The code compiles and runs, but I'm trying to understand how the expression (obj.*funcPtr)(12) can be evaluated at compile-time when obj is not declared as constexpr. I would expect that this might ...
1 vote
2 answers
100 views

I want to find the best possible way of initializing std:array in the below configuration (a better way would be able to use the cols and rows variables while declaring the array size): class Engine { ...
-1 votes
1 answer
244 views

I want to define a constexpr function strip_string which allows: Trim the string (removal of contiguous whitespaces in the beginning and end of the string. Normalize contiguous whitespaces in the ...
0 votes
1 answer
603 views

C23 added a keyword constexpr which can be used to define objects as compile-time constants instead of enumerations or macros. For example: constexpr int x = 10; constexpr int y = x+10; // Valid ...
2 votes
4 answers
126 views

The documentation states that a list constant in scalar context currently returns the number of values, but this may change in the future. It also states that, to use a list constant as an array, ...
3 votes
0 answers
101 views

I've been trying to make some of my code more airtight by moving some runtime operations to compile time. I thought it would be simpler because I'm only trying to increment or decrement a number by ...
-2 votes
1 answer
167 views

I have a base class and derived classes. The base class uses pure virtual methods to require the derived classes to implement methods - otherwise it doesn't compile. Classic. Can I also require from ...
2 votes
1 answer
151 views

After reading about constant expressions I wrote the following example that compiles with msvc but is rejected by both gcc and clang. int *const ptr2 = nullptr; static_assert(!ptr2); //msvc passes ...
1 vote
1 answer
149 views

As far as I can tell, the ternary ?: operator can be evaluated at compile time if at least the condition and the executed branch are compile-time constants. However, what if one of the unexecuted ...
4 votes
2 answers
195 views

I have a basic string structure: typedef struct String { size_t size; union { char *ptr, buf[sizeof(char *)]; }; } String; The idea is to be able to extract a char * from a String ...
1 vote
1 answer
81 views

I get the following error in my project upon compiling. Tried everything but unable to resolve this. Reproduced the error here: https://replit.com/join/egfoiwpgig-darshanpandhi Error error: constexpr ...

15 30 50 per page
1
2 3 4 5
...
21

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