Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
98 views

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 ...
bers's user avatar
  • 6,299
-5 votes
1 answer
92 views

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)...
Torph's user avatar
  • 38
2 votes
2 answers
171 views

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 ...
 sentientbottleofwine's user avatar
6 votes
2 answers
129 views

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(...
aep's user avatar
  • 1,737
0 votes
1 answer
107 views

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

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;...
Blair Davidson's user avatar
4 votes
0 answers
115 views

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 = ...
Fuz's user avatar
  • 325
3 votes
1 answer
174 views

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 ...
Crutch's user avatar
  • 33
0 votes
0 answers
45 views

I'm looking into C++20 features and I just stumbled upon idea of wrapping static_assert into differently named function e.g. constexpr void staticCheck(bool bCondition) { static_assert(bCondition); }...
ligazetom's user avatar
  • 153
0 votes
0 answers
53 views

I have the following code and it works, but it is clunky due to double call to get_vec5 that is required. namespace sr = std::ranges; namespace sv = std::views; template<int n> consteval auto ...
NoSenseEtAl's user avatar
  • 30.9k
2 votes
1 answer
75 views

Let's say I have a class with a consteval constructor that ensures a valid value at compile time. (There's also a std::expected-returning factory method that validates its argument at runtime, but ...
rkjnsn's user avatar
  • 985
0 votes
0 answers
144 views

I was solving https://projecteuler.net/problem=206, and wanted a compile time (consteval) solution. My idea was to check every number, until the answer is found. However, my code does not compile. ...
PlsHelp's user avatar
  • 337
1 vote
1 answer
146 views

I have a question about why I'm getting the two problems, this declaration has no storage class or type specifier, and expected a ';' ln 3 col 11, of the code: Main.cpp: #include <iostream> ...
SkullHeadI's user avatar
2 votes
1 answer
726 views

The following code does not compile with g++ 14.1 or clang++ 18.1: #include <type_traits> consteval int plusone(int n) { return n+1; } constexpr int maybeplusone(int n) { if (std::...
user3188445's user avatar
  • 4,980
1 vote
0 answers
68 views

Why is it not possible to create an array in a consteval function (and return it) if array size is not a function template argument but just a function argument? The argument must be known at compile ...
Rudolf Lovrenčić's user avatar
0 votes
0 answers
72 views

In the project I'm working on we have a large number of classes with methods named to match enum keys. This provides a means to call functions that can be dynamically detected. General example of ...
CJBrew's user avatar
  • 2,797
2 votes
1 answer
210 views

EDIT: this has been reported as a llvm bug here. The following code compiles on GCC and MSVC but is rejected by Clang: struct X { const void *p_; consteval X() : p_{this} { } }; static ...
Andrea Agostini's user avatar
2 votes
1 answer
255 views

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> ...
Oersted's user avatar
  • 3,732
2 votes
0 answers
159 views

Following This link, I came up to this question. I'm trying to understand how different would be the targeting the following two compile-time functions by a C++20 compiler. consteval int Factorial(int ...
Iman Abdollahzadeh's user avatar
5 votes
2 answers
946 views

I have a function that calculates the hash of a string literal: inline consteval uint64_t HashLiteral(const char* key) { // body not important here... return 0; } In another function I need ...
ScratchingTheSurface's user avatar
0 votes
1 answer
126 views

Alright, so I'm trying to make a function that will hash a string. consteval int hash_string(const char* str) { constexpr int magic_number = 13371337; int num1 = 1337; int num2 = 7331;...
Bard's user avatar
  • 35
0 votes
1 answer
142 views

the following works as expected: template<typename... Types> auto countNumberOfTypes() { return sizeof...(Types); } template<typename... Types> consteval auto functionReturnsFunction() { ...
XORer's user avatar
  • 73
0 votes
0 answers
79 views

I wanted to implement utility literals for evaluating roots of numbers. I implemented suffix literals that return root functions. Here's my code: #include <cmath> #include <stdexcept> ...
Samuel Okechukwu's user avatar
0 votes
1 answer
168 views

Is it possible, at compile time, to determine if a call to a function (a constexpr function mainly) is compile-time evaluated and than just make another version of that function (like what a template ...
user avatar
3 votes
2 answers
109 views

I have a class that wraps an integer into a range of values known only to the compiler (and the developer), the limits are unknown at runtime. The class implements operators such that the limits ...
wolfjazz's user avatar
  • 191