cpp14 library

Save to:
Instapaper Pocket Readability

C++14 Library Extensions

The following are the main additions and improvements to the C++ standard library in C++14. There are also miscellaneous smaller improvements besides those listed here, such as addressing tuples by type (e.g., get<string>(t)) and being able to omit the type of operator functors (e.g., greater<>(x) is okay).

Shared locking

See also:

User-defined literals for std:: types

C++11 added user-defined literals, but didn’t use them in the standard library. Now some very useful and popular ones work:

auto a_string = "hello there"s;   // type std::string
auto a_minute = 60s;              // type std::chrono::duration = 60 seconds
auto a_day    = 24h;              // type std::chrono::duration = 24 hours

Note s means “string” when used on a string literal, and “seconds” when used on an integer literal, without ambiguity.

See also:


This fixes an omission:

auto p1 = make_shared<widget>(); // C++11, type is shared_ptr
auto p2 = make_unique<widget>(); // new in C++14, type is unique_ptr

Unlike make_shared, using make_unique doesn’t add any optimization. What it does do is enable us to tell people “don’t write naked new any more to allocate an object on the heap” (except only perhaps in the internals of low-level data structures).

See also:

Type transformation _t aliases

As part of the movement of C++ away from “traits” types, C++14 added type aliases to avoid having to spell out typename and ::type, and actually make the traits more technically usable because they now work in deduced contexts.

// C++11
... typename remove_reference<T>::type ...
... typename make_unsigned<T>::type ...

// new in C++14 
... remove_reference_t<T> ...
... make_unsigned_t<T> ...

See also: