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

I'm trying to generate compile-time info about my POD types. Getting the offset of each member has been challenging due to limitations like no pointer conversions in constexpr, but I think I've found ...
Joshua Maiche's user avatar
15 votes
1 answer
1k views

Why does this code compile? template<typename Callable> int foo(Callable callable) { static_assert(callable()); return 0; } static const auto r = foo([] { return true; }); Compiler ...
Teskann's user avatar
  • 163
8 votes
2 answers
171 views

I am trying to write a factory function that creates a constexpr object that uses new. Is this even possible? The following code does not compile: aa.cpp: In function ‘int main()’: aa.cpp:23:39: in ...
DuduArbel's user avatar
  • 1,298
3 votes
1 answer
129 views

I was experimenting with constexpr std::string and I found that gcc and clang both compile this code (inspect it at compiler explorer here) #include <string> static constexpr std::string FIRST =...
Lluís Alemany-Puig's user avatar
2 votes
1 answer
170 views

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 ...
GKxx's user avatar
  • 588
2 votes
3 answers
230 views

How to iterate over tuple in compile-time? problem code: #include <array> #include <cstddef> #include <tuple> namespace { class Solution { public: template <size_t ...
arniiiii_ua's user avatar
0 votes
1 answer
122 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,010
1 vote
1 answer
158 views

I'd like to share some constants between CPU and GPU in order to allow for execution of the same code (wrapped in between) on either. That includes some compile-time parameters which are most ...
niemc's user avatar
  • 113
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
2 votes
1 answer
114 views

This compiles on Clang and GCC, but not MSVC: #include <tuple> #include <cstdint> #include <cstdio> #include <array> template <uint32_t N> struct BitfieldBits { ...
Zebrafish's user avatar
  • 16.3k
1 vote
1 answer
157 views

I recently need to implement a Sobol sequence generator by CUDA. Now to pre-store the Sobol table, I can either use a C++ native constexpr like below: constexpr unsigned int sobol_table[NUM_DIMENSIONS]...
PkDrew's user avatar
  • 2,281
1 vote
1 answer
113 views

Given something like the following: struct numeric_limits_max_t { template<class T> constexpr operator T() const noexcept { return std::numeric_limits<T>::max(); } }; ...
darune's user avatar
  • 11.5k
0 votes
1 answer
119 views

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 ...
Dimitrije Kostic's user avatar
4 votes
1 answer
152 views

The following code produces an error with gcc in the latest versions: #include<stdio.h> #include<stdlib.h> int main(void) { constexpr double d = 2.2; constexpr int i = d*10; ...
Surge's user avatar
  • 425
8 votes
2 answers
1k views

I'm writing a compile-time parser PoC (compiling a literal string to std::tuple) based on C++20 (or 23 if necessary). Currently gcc, clang, and MSVC all crash for this code, and MSVC gives useful ...
Sprite's user avatar
  • 4,147
0 votes
0 answers
88 views

Is a debug_log written entirely as a if constexpr an appropriate (recommended) substitute for a traditional macro implementation of a debug log? Consider the following code compiled with -O3 and -...
Derek C.'s user avatar
  • 1,026
6 votes
1 answer
202 views

I have the following constexpr Fibonacci function: constexpr auto fibo(unsigned int number) -> unsigned long long { if (number < 2) return number; return fibo(number - 1) + fibo(number - ...
TheJanzap's user avatar
  • 173
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
5 votes
1 answer
233 views

I have a constant declared in one case of my switch statement: void foo( int& v ) { switch( v ) { case 0: static constexpr int c{ 0 }; break; case 1: v = c; ...
Fedor's user avatar
  • 24.7k
4 votes
2 answers
207 views

I am playing around with implementing C++ std library traits. I could implement is_integral like this: template <typename T> is_integral { static constexpr bool value = false; } template <&...
Tomáš Zato's user avatar
  • 53.9k
2 votes
1 answer
90 views

I have the following code from Ben Deane talk. #define CX_VALUE(...) [] { \ struct { \ constexpr auto operator()() const noexcept { return __VA_ARGS__; } \ using cx_value_tag = ...
NoSenseEtAl's user avatar
  • 30.9k
3 votes
2 answers
125 views

I want to assert that an object JsonKey if constructed with a string that is known at compile time doesn't contain a quote. Here's what I have: LiveDemo #include<iostream> template <size_t N&...
glades's user avatar
  • 5,356
2 votes
1 answer
359 views

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 ...
Badasahog's user avatar
  • 1,025
1 vote
1 answer
153 views

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 ...
Setu's user avatar
  • 1,086
1 vote
0 answers
49 views

I want to validate a c string at compile time (using static assert). I have already a constexpr function that is able to do. (I use C++17) template <std::size_t N> constexpr bool validate(const ...
Romà Pagès's user avatar

1
2 3 4 5
54