corvusoft


A new standard is born

Prior to twenty-eleven C++, too most, was a 33-year-old general purpose programming language with a dishevelled appearance facing years of neglect, underdevelopment, and competition from modern feature rich languages led by vibrate and active communities; the likes of Ruby and Python too name a few.

All this began to change, after some delay, on the 12th August 2011 with the approval of the C++11 standard. Superseded 1103 days later on 18th August 2014 by the ISO C++14 Standard, which was more of a patch to C++11 than a major release. It did however introduce a few new features.

The primary design goals of C++11/14 are as follows:

Now fast forward several years for the ratification of C++17 at a standards meeting in Oulu, Finland. Similarly to C++14 this release has no major updates and squarely places the cross hairs on readable and modifiable development.

"We may not be getting the groundbreaking major updates everybody was hoping for with C++17, but what we are getting is a grab-bag of smaller features that are going to go a long way in making the language more easily readable and modifiable.” — Bjarne Stroustrup

What follows is a list of the features expected to make an impact on our software development teams in the near to immediate future.

† The standard was previously known as C++0x as it was expected to be released before 2010.

Specifiation Alterations


Issues resolved

A list of active issues and their current states can be located at www.open-std.org.

Deprecated

Exception/Throw Expressions

Exception-specification and throw-expression sections have undergone a cosmetic clean-up to help improve their interpretation.

"The changes are intended to be editorial only, not changing semantics. Due to the size of the changes, it seems prudent to have a full CWG (Core Working Group) review for these instead of leaving the issue to the project editor alone." — N4285 revision of N4133

C++17 library is based on C11

C11 attempts to fix multiple issues with C99 that hindered its adoption. Many of the C99 mandatory features have become optional as they have caused implementation issues for many compilers. C11 code will also increase its robustnus against security loopholes and malware attacks.

For an overview of the difference between C99 and C11 please see the following SmartBear blog post.

Language & Library Features


std::shared_mutex

The shared_mutex class is a synchronization mechanism used to protect data from simultaneious write access by multiple threads. However, many actors are permitted to read from the resource without causing data races.

If statement; initialiser

The addition of the if initialiser helps address a common code case enabling developers to keep variable scope tight.

if ( auto status = get_http( ); status not_eq 200 )
{
    error_handler( );
}
    

std::filesystem

This feature is fairly self explantory and covers the most common use cases when interacting with the local filesystem. The addition of this library will greatly ease cross compatibility when creating portable solutions across multiple operating systems.

std::any

Finally we have access to a type-safe generic container that is capable of holding single values of any form.

std::optional

The optional template is a generic container that may or may not contain an item. This can help clean-up default argument declarations and/or null values with the benefit of a vocabulary type; indicating its intended use without the need for detailed analysis by developers.

std::string_view

The purpose of the string_view feature, previously known as string_ref, is to avoid copying data which is already owned elsewhere when only immutable access is required.

std::observer_ptr

The observer_ptr is a dumb pointer type that is intended to improve self-documenting code. It has no ownership or responsibility for its underlying pointer. It is intended as a drop-in substitute for raw pointers with the benefit of a vocabulary type, indicating its intended use without the need for detailed analysis by developers.

::erase_if

erase_if functionality has been introduced for all the major containers, string, deque, vector, forward_list, list, map, multimap, set, multisite, unordered_map, unordered_multimap, unordered_set and unordered_multiset, etc...

This feature erases all elements within a collection that staisfy a specific criteria from the range [first, last], returning a past-the-end iterator for the new end of range.

// Before
items.erase( std::remove_if( items.begin( ), items.end( ), predicate ), items.end( ) );

// After
items.erase_if( items.begin( ), items.end( ), predicate );

std::source_location

The source_location feature is intended to replace predefined macros __LINE__ and __FILE__, used during logging, testing, and/or debugging. It offers column, line, file and function name in a easily consumed and readable package, helping to further clean-up your codebase.

std::propagate_const

Constant propagation is the ability to carry through the constant properties for pointers and pointer-like objects. It treats the contained entity as a pointer to const when accessed through a constant path.

std::not_fn

This feature is intended to improve readability by deprecating the C++03 negators std::not1 and std::not2.

What didn’t make the cut


Network

The network library based on the fantastic ASIO framework written by Chris Kohlhoff has unfortunately not met the desired criteria for C++17.

Modules

No modules, yet. Hopefully the next standard release rolls in this feature and lives up to the hype around resolving issues with the #include mechanism.

Conclusion


Overall, the features introduced deliver new functionality to the language, improving readability, cross-compatability, and extensibility. This ought to make it an easier language to work with and improve the maintenance of existing and new products alike.

While not mentioned here, many more improvements were broadly welcomed, including but not limited to lambdas, attributes, templates, dynamic memory allocation, data-types, parallelism, and more.

For a comprehensive list of proposals to be included in the latest standard please review Isocpp.org and the further reading section below.

A list of popular compilers and their current level of compliance can be found in tabular form on the compiler support page at cppreference.com.

Further Reading


← Last Article What WWII spy masters can teach you about your business. Next Article → Selling Software to North America.