125 questions
0 votes
1 answer
101 views
Macro-free, MSVC-compatible std::format with check for extra argument
I use std::format in my logging, and it largely works great. However, std::format ignores extra arguments which I do not like. E.g., std::format("x = {}", x, y) compiles, so I want a ...
10 votes
1 answer
244 views
Cannot use std::not_fn with immediate functions
I try to apply std::not_fn wrapper to an immediate consteval function. But even the simplest C++20 example #include <functional> consteval bool f() { return false; } // ok in GCC and Clang, ...
-6 votes
1 answer
93 views
Can an executable call a static library's non-inline consteval function when using LTO?
Let's say I have the following function in a static library libutil (with the definition in one of the library's translation units, so it can't be inlined while compiling the caller's translation unit)...
2 votes
1 answer
173 views
Compile-time manipulation of std::source_location::current()
I want to write a function that can obtain caller's function name, or at least its length, at compile time. I think obtaining std::source_location::current() is close to what I want and currently I'm ...
2 votes
2 answers
185 views
Forward string literal to consteval function
My api would require calling runtime(constFoo(str)) to get the final result, I wanted to shorten this because the real function names are kind of verbose. To do this I need to somehow wrap the ...
5 votes
2 answers
138 views
What effect does consteval have on linkage in C++?
I have been looking at how different specifiers affect linkage but need some help understanding how consteval affects linkage. The working draft of the standard says consteval implies inline (source): ...
6 votes
2 answers
132 views
Constant expression error when consteval function called from another
I am trying to use the return value from a consteval function UniqueSize() inside another consteval function UniqueArra to declare an array, but this results in a compiler error saying that UniqueSize(...
4 votes
1 answer
206 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 ...
0 votes
1 answer
128 views
Need help to understand how std::format can check its format string at compile-time
Out of curiosity, and with hope of learning useful compile-time techniques, I'm trying to understand how std::format performs compile-time checking of its arguments. I started from the implementation ...
0 votes
1 answer
119 views
Is there any way to get `consteval`-like behavior in C++11?
I'm working on a project that must limit itself to the C++11 standard. There's one particular class I'm creating (some details below) whose most important method can, I think, often be evaluated at ...
0 votes
0 answers
54 views
constexpr function containing constexpr variable [duplicate]
If i have a constexpr function with a constexpr local variable its value must be known at compile time constexpr int addSquare(int x) { constexpr int multiplier = 2; return x * x + multiplier;...
13 votes
0 answers
224 views
Cannot call constexpr template member function in consteval constructor
// gcc: ok // clang: compile error struct arg { consteval arg(const int i) // consteval : i_(i) { chk<int>(i); // error!! } template <typename T> ...
4 votes
0 answers
117 views
Can I make a consteval function throw a deprecation warning for given arguments?
I have a function like: consteval int func(int n) { ... } I would like to throw a deprecation warning if passed certain argument values, e.g. if the argument is less than 5: constexpr int a = ...
1 vote
1 answer
155 views
Mutable static variables in consteval contxt
I'm trying to implement a consteval lambda to compute the nth Fibonacci number. I want to create a result cache in the lambda which I can use if the result is already cached. Here's what I have up ...
3 votes
1 answer
183 views
How can a sprintf-like function in C++20/23 verify that the number of format specifiers matches the number of provided arguments at compile time?
I’m trying to learn C++23 and thought a good exercise would be writing a sprintf()-like function that —- provided the given format string is a string literal —- does a compile-time check to ensure the ...