Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

The way I see it, constexpr is a way to bring together the two C++ languages - the one that runs at runtime and the one that runs at compile time. Compile time programming is usually called meta-programming.

First there was C, with its macros. Macros were in fact little programs that were ran by the compiler. They had if statements (called #ifdef), variables (with #define). There's even an entire scripting language that runs in compile time.

When C++ came out, it had the C macros and nothing more. Then came the C++ templates. These introduced a different way of running compile-time code. The C++ meta-language was largely functional, allowing you to do loops with tail recursionloops with tail recursion, for example.

In C++ 11, they've decided that meta-programming can look better, so they've introduced constexpr. Now you can write C++ functions that are also meta-functions. In C++ 14 it gets better, because the restrictions on constexpr functions have been relaxed.

The way I see it, constexpr is a way to bring together the two C++ languages - the one that runs at runtime and the one that runs at compile time. Compile time programming is usually called meta-programming.

First there was C, with its macros. Macros were in fact little programs that were ran by the compiler. They had if statements (called #ifdef), variables (with #define). There's even an entire scripting language that runs in compile time.

When C++ came out, it had the C macros and nothing more. Then came the C++ templates. These introduced a different way of running compile-time code. The C++ meta-language was largely functional, allowing you to do loops with tail recursion, for example.

In C++ 11, they've decided that meta-programming can look better, so they've introduced constexpr. Now you can write C++ functions that are also meta-functions. In C++ 14 it gets better, because the restrictions on constexpr functions have been relaxed.

The way I see it, constexpr is a way to bring together the two C++ languages - the one that runs at runtime and the one that runs at compile time. Compile time programming is usually called meta-programming.

First there was C, with its macros. Macros were in fact little programs that were ran by the compiler. They had if statements (called #ifdef), variables (with #define). There's even an entire scripting language that runs in compile time.

When C++ came out, it had the C macros and nothing more. Then came the C++ templates. These introduced a different way of running compile-time code. The C++ meta-language was largely functional, allowing you to do loops with tail recursion, for example.

In C++ 11, they've decided that meta-programming can look better, so they've introduced constexpr. Now you can write C++ functions that are also meta-functions. In C++ 14 it gets better, because the restrictions on constexpr functions have been relaxed.

Source Link
zmbq
  • 39.1k
  • 15
  • 109
  • 189

The way I see it, constexpr is a way to bring together the two C++ languages - the one that runs at runtime and the one that runs at compile time. Compile time programming is usually called meta-programming.

First there was C, with its macros. Macros were in fact little programs that were ran by the compiler. They had if statements (called #ifdef), variables (with #define). There's even an entire scripting language that runs in compile time.

When C++ came out, it had the C macros and nothing more. Then came the C++ templates. These introduced a different way of running compile-time code. The C++ meta-language was largely functional, allowing you to do loops with tail recursion, for example.

In C++ 11, they've decided that meta-programming can look better, so they've introduced constexpr. Now you can write C++ functions that are also meta-functions. In C++ 14 it gets better, because the restrictions on constexpr functions have been relaxed.