Top "Constexpr" questions

constexpr is a modifier introduced in C++11, which informs the compiler that the value of a function or variable is known or can be calculated at compile time.

Difference between `constexpr` and `const`

What's the difference between constexpr and const? When can I use only one of them? When can I use both …

c++ c++11 constants constexpr
When should you use constexpr capability in C++11?

It seems to me that having a "function that always returns 5" is breaking or diluting the meaning of "calling a …

c++ c++11 constexpr
const vs constexpr on variables

Is there a difference between the following definitions? const double PI = 3.141592653589793; constexpr double PI = 3.141592653589793; If not, which style is preferred …

c++ variables c++11 constants constexpr
Is it possible to use std::string in a constexpr?

Using C++11, Ubuntu 14.04, GCC default toolchain. This code fails: constexpr std::string constString = "constString"; error: the type ‘const string {aka …

c++11 stdstring constexpr
Does static constexpr variable inside a function make sense?

If I have a variable inside a function (say, a large array), does it make sense to declare it both …

c++ static c++11 constexpr
Undefined reference to static constexpr char[]

I want to have a static const char array in my class. GCC complained and told me I should use …

c++ c++11 static-members constexpr
Create N-element constexpr array in C++11

Hello i'm learning C++11, I'm wondering how to make a constexpr 0 to n array, for example: n = 5; int array[] = {0 ... n}; …

c++ c++11 constexpr array-initialization
constexpr vs. static const: Which one to prefer?

For defining compile-time constants of integral types like the following (at function and class scope), which syntax is best? static …

c++ c++11 constants constexpr
Constexpr vs macros

Where should I prefer using macros and where should I prefer constexpr? Aren't they basically the same? #define MAX_HEIGHT 720 …

c++ c++11 macros constexpr
constexpr not compiling in VC2013

This constexpr code does not compiled in Visual Studio 2013 version 12.0.21005.1 REL Is there a newer Visual Studio compiler that works …

c++ c++11 visual-studio-2013 constexpr