Evolution in several areas, in parallel. Several just missed C++17. Many major features ended up in C++20.
Features are proposals or Technical Specifications (TS)
if constexpr (C++17)
if with variable declaration (C++17)
(string) literals as template parameters
more constexpr, consteval
class template argument deduction
if (auto v = f(); !v.get())
if constexpr (is_enum_v<T>)
MyTemplate<"a string">
auto [a, b] = getBoth()
for (auto && [k,v] : myMap)
variant<double, string> v{17.};
assert(get<double>(v) > 16); // good!
v.emplace<string>("ABC");
get<0>(v); // throws!
void func(span<double,4> lv);
array<double, 4> jetLV{...};
func(jetLV);
string message = format("The answer is {}.", 42);expects: condition on arguments
ensures: post-condition, a guarantee by the function
assert: a check to be performed within the function
int f(int i) [[expects: i > 0]];
int g(string& s) [[ensures: !s.empty()]] {
[[assert: s.empty()]]
s = "ABC";
}
Multiple contract levels default, audit, axiom
compiler flag defines which contracts are checked
- default checks default
- off: nothing
- audit: default and audit
axiom is thus never checked:
good for expensive conditions
int f(int i) [[expects default: i > 0]];
int g(int i) [[expects audit: i > 0]];
int h(int i) [[expects axiom: i > 0]];