The C++17 is taken standing and putting new features to the classic programming language. This significant update is designed to create C++ an easier language to work alongside and delivers effective technical requirements.
During the latest criteria meeting in Oulu, Finland, the actual and final features list of C++ is finalised. This means that, C++17 has turned into a major release similar to C++98 and C++11.
The latest C++ 17 standards are launching new features such as structured bindings and if initialisers, creating this classic programming language “feature complete”.
The C++ community is calling C++17 the beginning of a new era designed to take robust technical specifications. The non-C++17 features will likely be revealed later as add-ons in the future releases.
Here’s the list of the highest features that were voted during the meeting:
Templates and Generic Code
- Template argument deduction for class templates
- Like how functions deduce template arguments, now constructors can deduce the template arguments of the class
template <auto>
- Represents a value of any (non-type template argument) type
- Non-type template arguments fixes
template<template<class...>typename bob> struct foo {}- ( Folding + ... + expressions )
auto x{8};is anint- constexpr if
- Much requested feature to simplify almost-generic code
Lambda
- constexpr lambdas
- Lambdas are implicitly constexpr if they qualify
- Capturing
*thisin lambdas
[*this]{ std::cout << could << " be " << useful << '\n'; }
Attributes
[[fallthrough]],[[nodiscard]],[[maybe_unused]]attributes[[attributes]]onnamespaces andenum { erator[[s]] }
Syntax cleanup
- Inline variables
- Like inline functions
- Compiler picks where the instance is instantiated?
namespace A::B- Simple
static_assert(expression);with no string
Cleaner multi-return and flow control
- Structured bindings
- Basically, first-class
std::tiewithauto - Example:
const auto [it, inserted] = map.insert( {"foo", bar} );- Creates variables
itandinsertedwith deduced type from thepairthatmap::insertreturns.
- Works with tuple/pair-likes &
std::arrays and relatively flat structs
- Basically, first-class
if (init; condition)andswitch (init; condition)
if (const auto [it, inserted] = map.insert( {"foo", bar} ); inserted)- Extends the
if(decl)to cases wheredeclisn't convertible-to-bool sensibly
- Generalizing range-based for loops
- Appears to be mostly support for sentinals, or end iterators that are not the same type as begin iterators, which helps with null-terminated loops and the like.
Misc
- Hexadecimal float point literals
- Dynamic memory allocation for over-aligned data
- Guaranteed copy elision (r1 accepted, not r0: have not found r1 on 'net yet)
- Finally!
- A weaker version of fixed order-of-evaluation for expressions
- "See Chandler's tweet and Alisdair's tweet" (cannot find Alisdair's tweet, linked to doc found in Chandler's tweet)
- Not including function arguments, but function argument evaluation interleaving now banned
- Makes a bunch of broken code work mostly
- Forward progress guarantees (FPG) (also, FPGs for parallel algorithms)
- I think this is saying "the implementation may not stall threads forever"?
u8'U', u8'T', u8'F', u8'8'character literals.- "noexcept" in type system
__has_include
- Test if a header file include would be an error
- Arrays of pointer conversion fixes
- inherited constructors fixes to some corner cases.
Library additions:
Data types
std::variant<Ts...>
- Almost-always non-empty last I checked?
- Tagged union type
std::optional
- Maybe holds one of something
std::any
- Holds one of anything
std::string_view
std::stringlike reference-to-character-array or substring
std::shared_mutex
- Untimed, which can be more efficient if you don't need it.
Invoke stuff
std::invoke- Call any callable (function pointer, function, member pointer) with one syntax. From the standard INVOKE concept.
std::apply- Takes a function-like and a tuple, and unpacks the tuple into the call.
std::is_callablestd::make_from_tuple,std::applyapplied to object construction
File System TS v1
[class.path][class.filesystem.error][class.file_status][class.directory_entry][class.directory_iterator]and[class.recursive_directory_iterator][fs.ops.funcs]
Parallelism TS v1
- The linked paper from 2014, may be out of date
- Parallel versions of
stdalgorithms, and related machinery
(parts of) Library Fundamentals TS v1 not covered above or below
[func.searchers]and[alg.search]- A searching algorithm and techniques
[pmr]
- Polymorphic allocator, like
std::functionfor allocators - And some standard memory resources to go with it.
- Polymorphic allocator, like
std::sample, sampling from a range?
Container Improvements
try_emplaceandinsert_or_assign- Splicing for
map<>,unordered_map<>,set<>, andunordered_set<>
- Paper from 2013, so maybe newer proposal accepted?
- non-const
.data()for string. - non-member
std::size,std::empty,std::data - Minimal incomplete type support in containers
- Contiguous iterator "concept"
constexpriterators
Other std datatype improvements:
{}construction ofstd::tupleand other improvementsatomic<T>.is_always_lockfree()lock_guard<Mutexes...>- Saves some
std::lockpain when locking more than one mutex at a time.
- Saves some
unique_ptr<T[]>fixes and otherunique_ptrtweaks.- TriviallyCopyable reference_wrapper, can be performance boost
Misc
- C++17 library is based on C11 instead of C99
- Reserved std[0-9]+ for future standard libraries
destroy(_at|_n),uninitialized_move(_n),uninitialized_value_construct(_n),uninitialized_default_construct(_n)- Special math functions
- hardware_*_interference_size
std::clamp()std::clamp( a, b, c ) == std::max( b, std::min( a, c ) )roughly
std::uncaught_exceptions- Required if you want to only throw if safe from destructors
std::as_conststd::bool_constant<bool>- A whole bunch of
_vtemplate variables std::void_t<T>- Surprisingly useful when writing templates
std::owner_less<void>- like
std::less<void>, but for smart pointers to sort based on contents
- like
std::chronopolishstd::conjunction,std::disjunction,std::negationexposedstd::not_fn- Rules for noexcept within
std - std::is_contiguous_layout, useful for efficient hashing
- std::to_chars, high performance number conversion
- std::default_order, indirection over
std::less.
Isocpp.org has an even more detailed list of documents, a few of which I looted for on top. Now it is not up-to-date exactly what is approved into C++17.
these slides had some features missing elsewhere.
Despite "what was eliminated" wasn't questioned, this is a short list of a few things ((mainly?) earlier deprecated) being removed in C++17 from C++:
Removed:
registerbool b; ++b;- trigraphs
- ios aliases
- auto_ptr, old
<functional>,random_shuffle - allocators in
std::function
Spec changes:
You can check out Reddit to obtain the detailed information of the new modifications arriving with C++17.
In conclusion, C++17 is actually a major update that includes plenty of smaller features which are likely to help make this language a lot more understandable.
Comment below.
http://i.imgur.com/uwKTFuA.png
ردحذف