constexpr Questions
1
I have a source file with a large byte array representing an image.
Below an example (in reality it can be any random data):
const uint8_t image_test_image[] ={
0x00, 0x01, 0x02, 0x03, 0x04, 0x05,...
3
Solved
It's very natural to want to compare std::array's at compile time; and its operator==() is obviously constexpr'able. Yet - it isn't marked constexpr. Is this intentional or an oversight? And - what...
Lime asked 20/8, 2017 at 14:45
2
In the following if I use constexpr the compiler apparently the compiler says "expression must have a constant value", this happens on MSVC and GCC:
int main() {
constexpr auto nnn = {
...
Puberulent asked 19/9 at 7:56
1
Solved
Below is a recursive lambda expression that can compute the values of Fibonacci sequence both in runtime and during constant evaluation:
auto fib = [](this auto && f, auto && p) {
...
Dungaree asked 26/7 at 18:30
4
Solved
Maybe I missed something, but I can't find any hints: is there a constexpr ternary operator in C++17 equivalent to constexpr-if?
template<typename Mode>
class BusAddress {
public:
explicit ...
Lette asked 7/12, 2016 at 7:44
2
Solved
The CTRE library is able to parse and validate regular expressions at compile time using syntax like ctre::match<"REGEX">(text_to_search). I know this syntax is only supported...
Ecclesiolatry asked 17/6, 2021 at 18:12
1
Solved
I'm writing a constexpr code and I would like to inspect computed values at compile time.
The usual trick is to do something like this:
struct ReturnValue
{
int value1;
int value2;
};
constexpr...
10
Related: Function returning constexpr does not compile
I feel like constexpr is limited in usefulness in C++11 because of the inability to define two functions that would otherwise have the same s...
Caruso asked 20/1, 2012 at 3:54
1
Solved
Is it allowed to apply std::bit_cast to an object of empty class, converting it to some not-empty class of the same size? And especially is it allowed to do in a constant expression?
I was surprise...
Wnw asked 31/3 at 20:10
3
Solved
Since it is possible that a function declared as constexpr can be called during run-time, under which criteria does the compiler decide whether to compute it at compile-time or during runtime?
te...
Hornwort asked 9/1, 2013 at 23:18
4
Solved
Can virtual functions like X::f() in the following code
struct X
{
constexpr virtual int f() const
{
return 0;
}
};
be constexpr?
Eliathas asked 16/1, 2016 at 14:34
2
In C++, we can use macro or constexpr (as C++11 said). What can we do in C#?
Please see "Cannot declare..." comment for context:
static class Constant
{
// we must ensure this is compile time co...
Allanallana asked 22/4, 2013 at 9:39
3
Solved
Why code below has no problem with a2 but does not compile for z1?
#include <cmath> // std::nextafter
#include <limits> // std::numeric_limits
int main ()
{
constexpr float a1 {1.f};
...
2
Solved
I wrote the following program where if a class have a non-static data member then when an object of that type is passed as argument by value, then it can't be used in a constexpr context. After sea...
Riotous asked 3/3 at 9:24
1
Solved
I have this piece of code right there:
template <int V>
struct Constant {
constexpr operator int() const noexcept { return V; }
};
template <class T, int N>
struct Array { };
auto f...
Pachysandra asked 27/2 at 3:53
6
Solved
I've wrote several constexpr functions and use them in static_asserts to control some resource limits. But I'd like to not only enforce compile-time predicate but also to see the actual values calc...
Outspeak asked 4/3, 2015 at 10:51
0
Here is some simple program (reduced version when I was writing data for some unit tests):
#include <initializer_list>
#include <iostream>
#include <string_view>
#include <vect...
Intercessor asked 16/2 at 16:58
5
I am beginning with c++11, constexpr and template metaprogramming seems a nice way to save scarce ram on tiny microcontroler.
Is there a way to write a template to flatten a list of constexpr arr...
4
I want to check that a given double/float variable has the actual bit pattern 0x0. Don't ask why, it's used in a function in Qt (qIsNull()) that I'd like to be constexpr.
The original code used a ...
Esqueda asked 17/2, 2012 at 12:31
2
Solved
Consider the following code:
#include <stdio.h>
constexpr int f()
{
return printf("a side effect!\n");
}
int main()
{
char a[f()];
printf("%zd\n", sizeof a);
}
I would have expected t...
Marmion asked 4/3, 2014 at 15:57
2
Solved
Suppose I have a constexpr array (of known bound) of static storage duration:
constexpr T input[] = /* ... */;
And I have an output class template that needs a pack:
template<T...> struct...
Stereography asked 3/7, 2014 at 18:5
2
Solved
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 both...
2
Solved
I am learning about constexpr variables using the books listed here. In particular I read in C++ Primer that:
Variables declared constexpr are implicitly const and must be initialized with constan...
Whitherward asked 15/10, 2022 at 15:12
5
Solved
Consider the following function:
template <size_t S1, size_t S2>
auto concatenate(const std::array<uint8_t, S1> &data1,
const std::array<uint8_t, S2> &data2)
{
std::arra...
Thursby asked 10/1, 2019 at 8:52
2
Solved
I want to compute a lookup table at compile time for a mathematical function in a given range and then retrieve values from the table at run time. My code is as follows:
#include <iostream>
...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.