Questions tagged [constant-expression]

Use this whenever compile-time expression is implemented (currently exists in C++ and D). Do not use this tag if the compile-time evaluation property is achieved through template metaprogramming in C++ (in which case use the [template-meta-programming] tag).

Filter by
Sorted by
Tagged with
3 votes
1 answer
134 views

Row-sparse constexpr 2D array, generated at compile-time from array coordinate/value entries

The goal of the code is to enable me to express a 2D array in an unsorted coordinate-sparse representation in my code (i.e. a list of individual x, y, value entries ...
AJMansfield's user avatar
  • 1,513
8 votes
1 answer
1k views

Enabling bitset-like behavior for enum classes (C++20)

I want to enable bitmask-like behavior (ie. overloaded operator|, operator& and operator^...
Frederic Schönberger's user avatar
5 votes
1 answer
483 views

Compile-time Matrix Class

Intended as a small project to test out various C++20 features, as well as learn a little bit more about matrices and their uses, I decided to implement a relatively simple matrix class. After ...
Dnarok's user avatar
  • 53
5 votes
1 answer
117 views

Compiletime (constexpr) Differential Equation System Description for use in Optimal Control

Background In the field of optimal control, it is part of everyday business to solve ordinary differential equations numerically. A differential equation system or dynamic system describes e.g. the ...
ab.o2c's user avatar
  • 306
2 votes
1 answer
2k views

constexpr hash function

Here's a constexpr hash function, that will pack a string into the largest unsigned integral type available. So, what do you think? ...
user1095108's user avatar
  • 1,414
10 votes
1 answer
499 views

Two constexpr ceil functions

ceil_constexpr is is based on: https://stackoverflow.com/questions/8377412/ceil-function-how-can-we-implement-it-ourselves/8378022#8378022 ceil_constexpr2 is a simpler version that takes advantage of ...
VevsVire's user avatar
  • 101
2 votes
1 answer
144 views

type erased pointer to member function callable and SFINAE [closed]

I'm implementing a std::function like class that uses type erasure. So far it can be used with function objects (functions/function pointers, functors, lamdas) and pointer to member function. But to ...
Luca's user avatar
  • 123
2 votes
1 answer
370 views

Flatten 2d-array at compiletime

In my code, I need to flatten a two-dimensional std::array into a one-dimensional one at compile time. While writing the code I realized, that I am unsure about ...
mutableVoid's user avatar
2 votes
1 answer
2k views

C++ ring buffer using some C++ 17 and coming C++ 20 std::span

When I heard about the new Linux I/O interface io_uring I searched about the ring buffer. I then thought I may replace my safe queue which is base on C++ 11 ...
dev65's user avatar
  • 293
6 votes
1 answer
1k views

A cartesian product of tuples in C++17

I would like to write a function that computes a cartesian product of two tuples in C++17 (the tuples can be of type std::tuple or ...
Vladimir Reshetnikov's user avatar
3 votes
1 answer
104 views

Simple DP problem solved in compile time

The problem is taken from one of recent SO questions: Finding max sum of matrix elements with following constraints: Exactly one row element has to be included in the sum If element at (i, j) is ...
paler123's user avatar
  • 291
3 votes
0 answers
820 views

C++ compile time counter/accumulator [closed]

I could not find a compile time counter/accumulator to achieve something like the following: ...
user190902's user avatar
6 votes
2 answers
2k views

Check array contains element at compile time

We have a modifyCoefficient(const char* name, int value) function that updates the value of a coefficient in a container. The names are known at compile time, they ...
Synck's user avatar
  • 191
6 votes
1 answer
2k views

Constexpr unit tests and asserts

I'm trying out some different programming styles to experiment with the new C++ concepts. Within the experiment I was looking into how constexpr could be helpful ...
JVApen's user avatar
  • 1,161
1 vote
0 answers
682 views

constexpr hashtable string to user type

This creates something like constexpr mar<String, T> using C++14. Collision resolution is with static_assert and manually ...
Nick's user avatar
  • 1,490
12 votes
1 answer
3k views

User defined literal for std::integral_constant

I created a user defined literal _c to convert an "integer" literal into an std::integral_constant. Basically, the goal is to ...
Morwenn's user avatar
  • 19.9k