Skip to main content
Filter by
Sorted by
Tagged with
2 votes
2 answers
2k views

For example, if I wanted a constexpr std::array<int,100> initialised with all the multiples of 3 from 1-300 at compile time how can I do this? My first thought was to use std::generate, ...
nectarine's user avatar
  • 165
2 votes
1 answer
101 views

Suppose I have a static function which takes an enum and returns a cstring ptr for debugging. The function can be constexpr but no guarantee is made that it can always be evaluated at compile time. ...
GreenaGiant's user avatar
5 votes
0 answers
95 views

The following code doesn't compile; g++ 7.3.0 with --std=c++17 gives the error message invalid return type 'const C' of constexpr function 'constexpr const C operator+(const C&, int)' note: 'C' ...
TonyK's user avatar
  • 17.2k
5 votes
1 answer
1k views

I'm writting a simple C++ HTTP server framework. In my Server class, I can add Route's. Every route consists of a path, an HTTP method and a Controller (which is a pipeline of functions to be called ...
André Winston's user avatar
2 votes
1 answer
460 views

I made some code which is capable of dispatching to a function based upon the call-site providing a string associated with a given function (via a tuple of function pointers and a parallel array). ...
Sean's user avatar
  • 483
0 votes
1 answer
2k views

EDIT: Renamed, as my final solution does not use a poisoning method. I'm looking for a way to prevent a constexpr method from being called at runtime. I'm writing a function that accepts a string ...
Sean's user avatar
  • 483
3 votes
1 answer
125 views

The standard on constexpr functions states under point 5 of [decl.constexpr]: For a non-template, non-defaulted constexpr function or a non-template, non-defaulted, non-inheriting constexpr ...
bitmask's user avatar
  • 35.2k
-1 votes
2 answers
101 views

see code below, f() is defined below main function is regarded as ill-formed ? could anyone give me an explanation for this ? constexpr int f (); void indirection (); int main () { constexpr int n ...
lsbbo's user avatar
  • 312
31 votes
2 answers
4k views

I'm having some trouble with constexpr. The book C++ Primer shows a line of code: constexpr int sz = size(); // only size() is a constexpr function // this code is right ...
icecity96's user avatar
  • 1,227
26 votes
3 answers
38k views

I have a constexpr function taking a single argument, and I'm calling the function with a constant. However, it seems I can't use that argument as a constant expression: constexpr void f(const int i) ...
tower120's user avatar
  • 5,345
399 votes
15 answers
162k views

It seems to me that having a "function that always returns 5" is breaking or diluting the meaning of "calling a function". There must be a reason, or a need for this capability or ...
Warren  P's user avatar
  • 69.8k

1
2