233 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
1
answer
128
views
It is possible to compute both the size and values for a std array in a constexpr function?
I am trying to express the structure of a sparse matrix (and the structure resulting from sparse matrix operations) at compile time with template parameters and constexpr functions.
I've defined this ...
2
votes
1
answer
434
views
static const vs contexpr in c23: what's the point?
c23 added the constexpr keyword to the standard, which seems to me to be quite puzzling.
I understand that the appeal would be that constexpr objects evaluate to constant expressions, whereas static ...
6
votes
1
answer
144
views
how to construct a constexpr static_string from constexpr std::string_view
I have a static_string template
template <std::size_t N>
struct static_string {
std::array<char, N + 1> elements_;
constexpr static_string() noexcept : elements_{} {}
...
1
vote
2
answers
143
views
Why "Each constant expression shall evaluate to..." instead of "Each evaluated constant expression shall evaluate to..."?
n3301, 6.6 Constant expressions, p4 (emphasis added):
Each constant expression shall evaluate to a constant that is in the range of representable values for
its type.
n3301, 6.5.15 Logical OR ...
0
votes
1
answer
43
views
How do I fix an error on the MainActivity, the R.id.nav keeps saying a constant expression is required?
I keep getting an error on while trying to create an App.
// Determine which fragment to display based on the item selected
switch (item.getItemId()) {
case R.id.nav_insert_meal:
...
6
votes
1
answer
281
views
Unexpected Output from Bit Shifting using len on a string vs. string subslice
I have a Go program that performs bit shifting and division operations on the length of a string constant, but the output is not what I expect. Here's the code:
package main
import "fmt"
...
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 ...
2
votes
1
answer
274
views
GCC and Clang are behaving differently with respect to constant evaluation
I'm observing an inconsistency between GCC and Clang with respect to what is a constant evaluated context. I played with different situations:
#include <iostream>
#include <type_traits>
...
3
votes
0
answers
102
views
Why doesn't this 'increment then decrement' generic const expression work in Rust?
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 ...
1
vote
1
answer
106
views
Cannot define constant variable that depends on another variable from a different header file in C
I have a set of C files that I'm trying to compile
//table.c
#include "row.h"
const uint32_t ROW_SIZE_1 = 50; //some random number
const uint32_t PAGE_SIZE = 4096;
const uint32_t ...
2
votes
1
answer
151
views
MSVC accepts constant pointer to int initialized with nullptr as constant expression
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 ...
0
votes
1
answer
186
views
constexpr pointer/reference initialization
I have an set of registers in MCU, and each of them has an unique adress. Imagine I have some register, that can be described with struct
struct RegisterDefinition{
u32 v1;
u32 v2;
u32 v3;
...
0
votes
0
answers
108
views
Add a pair to a std::map that has a const value
I need to update this map to include one more key-pair. The map is const std::map<char, std::shared_ptr<const TrieNode>> children_.
The const seems to block any method that is tried. ...
2
votes
3
answers
370
views
What happens if an assumption, i.e. [[assume]] fails in a constant expression?
In C++23, the [[assume(conditonal-expression)]] attribute makes it so that if conditional-expression doesn't evaluate to true, the behavior is undefined.
For example:
int div(int x, int y) {
[[...
1
vote
1
answer
81
views
Constexpr / Compile time constant expressions bugs
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 ...