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
5
votes
1answer
64 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 ...
6
votes
1answer
77 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 ...
2
votes
1answer
201 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? ...
10
votes
1answer
240 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 ...
2
votes
1answer
54 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 ...
3
votes
1answer
86 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 ...
2
votes
1answer
638 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 ...
6
votes
1answer
525 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 ...
3
votes
1answer
91 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 ...
3
votes
0answers
535 views

C++ compile time counter/accumulator [closed]

I could not find a compile time counter/accumulator to achieve something like the following: ...
3
votes
1answer
906 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 ...
6
votes
1answer
1k 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 ...
1
vote
0answers
597 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 ...
11
votes
1answer
2k 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 ...