2. Table of contents
● The standardization process, the committee
● C++ Standards
● The current status of the standardization process
● New language features
● New features in the standard libraries
● References
3. The standardization process
● A Commitee under ISO/IEC so multiple companies can co-operate and define
the language
● Work Group 21 (Google for wg21)
● Info on isocpp.org
○ Community site for publicizing for publicizing activity
● Work with Technical Specifications, TS:s
5. The Current Status
● Builds on C++14
● Significant library update
○ The additions and changes to the libraries are the biggest part of the new standard.
● Modest language update
● The standard has been agreed upon
● Will now be reviewed by ISO
● Expected release by the end of 2017
6.
7. New language features
Attributes
● [[fallthrough]] a case without breaking
● [[nodiscard]] warns on ignored function results
● [[maybe_unused]]
● Grammar supports attributes on namespaces
○ namespace std::relops [[deprecated]] { …. }
● Grammars supports attributes on enumeratiors
○ enum MyEnum {old_name [[deprecated]], new_name ]
8. New Language Features
Examples
● [[maybe_unsued]] int f() {} // Won’t issue warning if return value is not
catched.
● [[nodiscard]] int f() {} // Will issue warning if return value is not catched.
● Alos deducted from type:
○ struct [[nodiscard]] MyStruct {};
○ MyStruct f() {}; // Will give compiler warning if return value is not handled.
9. New Language Features
Lamda Expressions
● constexpr lamda expressions
● It is now possible to caputre a copy of this, e.g *this
10. New Language Features
Structured Bindings
● Declare multiple variables, bound by function result
○ auto [x, y] = *map.find(key) // Returns a pair
● Functions can return
○ An aggregate
○ an arry-by-reference
○ something that supports the tuple protocol: array, pair or tuple
● Works anywhere an initialization may be performed
for (auto& [first, second] : myMap) {
// use firts and secon
}
11. New Features In The Standard Libraries
● Multicore support and Parallelism 1
● Math functions
● Extended vocabulary
● Text Handling
● Filesystem
● Smart Pointers
12. Parallelism
Distinction between parallelism and concurrency
● Parallelism
○ Simultaneously executing many copies of the same task to speed a single computation
● Concurrency
○ Performing multiple actions at the same time, often to improve latency
13. Parallelism
● Added execution_policy overload to most functions in the <algorithm> and <numeric>
headers
● Almost all of the algorithms in the standard library now how a “paralliezed” version
● Excpet
○ Random nubers
○ Heap opertaions (other than is_hep and is_heap_until)
○ permutations operations
○ copy_backwards, move_backward, lowe_bound, upper_bound, equal_range,
binary_search, accumulate, partial_sum, iota
● Added some new
○ exclusive_scan
○ inclusive_scan
○ transform_reduce
○ redue
15. Math functions
● Adopted all of ISO 29124 (extensions to C++)
○ > 20 mathematical special functions
○ Bessel functions, beta function, riemann zeta etc
● hypot(x, y, z)
● gcd(a, b)
● lcm(a, b)
● A sampling function
○ sample(begin, end, out_iter, nSamples, rgb)
16. pair and tuple
● Unpack tuple arguments into a function call
○ apply(func, tuple{1, “two”, 3.14});
● Construct and object by unpacking a tuple
○ auto x = tuple{1, “two”, 3.14}
○ auto y = make_from_tuple<MyTYpe>(x);
17. Extended vocabulary
● Vocabulary types are the kind of types you would like to use in your interfaces
● Good with standardized vocabulary between libraries (for example)
● Already present
○ pair, tuple, array already in
● New ones
○ optinal<T>
○ any
○ variant<Types…>
○ string_view
18. optional<T>
#include <variant>
#include <string>
#include <string>
#include <iostream>
#include <optional>
// optional can be used as the return type of a factory that may fail
std::optional<std::string> create(bool b) {
if(b)
return "Godzilla";
else
return {};
}
int main()
{
std::cout << "create(false) returned "
<< create(false).value_or("empty") << 'n';
// optional-returning factory functions are usable as conditions of while and if
if(auto str = create(true)) {
std::cout << "create(true) returned " << *str << 'n';
}
}
19. variant<TYPES…>
#include <variant>
#include <string>
int main()
{
std::variant<int, float> v, w;
v = 12; // v contains int
int i = std::get<int>(v);
w = std::get<int>(v);
w = std::get<0>(v); // same effect as the previous line
w = v; // same effect as the previous line
// std::get<double>(v); // error: no double in [int, float]
// std::get<3>(v); // error: valid index values are 0 and 1
try {
std::get<float>(w); // w contains int, not float: will throw
}
catch (std::bad_variant_access&) {}
std::variant<std::string> v("abc"); // converting constructors work when unambiguous
v = "def"; // converting assignment also works when unambiguous
}
20. any
● Can hold any value as long as it is copy constructible
● Like varian except that it does not know what type it holds
● Will have to use any_cast to retrieve the value
21. any
int main()
{
boost::any a = 1;
std::cout << std::any_cast<int>(a) << 'n';
a = 3.14;
std::cout << std::any_cast<double>(a) << 'n';
a = true;
std::cout << std::boolalpha << std::any_cast<bool>(a) << 'n';
}
22. string_view
● string_view gives the ability to refer to an existing string in a non-owning way.
bool compare(const std::string& s1, const std::string& s2)
{
// do some comparisons between s1 and s2
}
int main()
{
std::string str = "this is my input string";
bool r1 = compare(str, "this is the first test string");
bool r2 = compare(str, "this is the second test string");
bool r3 = compare(str, "this is the third test string");
}
23. string_view
bool compare(std::string_view s1, std::string_view s2)
{
if (s1 == s2)
return true;
std::cout << '"' << s1 << "" does not match "" << s2 << ""n";
return false;
}
int main()
{
std::string str = "this is my input string";
compare(str, "this is the first test string");
compare(str, "this is the second test string");
compare(str, "this is the third test string");
return 0;
}
24. string_view
● In the last example only str is allocated.
● It is also possible to create string_view from a substring of a string.
○ The string_view points into the original string rather than to allocate a new string
○ string_view holds a pointer to a string and a size
25. Filesystem
● std::filesystem
● Specification based on POSIX standard semantics
○ NO protection against file system data races
● Uses system_error reporting introduced in C++11
● Functions and iterators to navigate a filesystem
● Functions to create, manipulate and query files (including directories and
symlinks)
26. Further Changes And Additions
● Smart pointers
● Allocators
● Memory Resources
27. Library Features Removed
● auto_ptr => Use unique_ptr
● bind1st, bind2nd, men_fun, men_fun_ref, ptr_fun, unary_function,
binary_funciton
● random_shuffle