C++C++14C++17Learn C++Syntax

What Are The New Overloads For Ranges In C++ 14?

What Are The New Overloads For Ranges In C++ 14

In C++14, there are pretty good new overloads of std::equalstd::mismatch, and std::is_permutation that can be used to take a pair of iterators for the second range. They can be used with the new C++ Builder 12 along with the 11.x, or 10.x versions too. In this post, we explain these new overloads that we use ranges of iterations.

What are the new overloads for ranges in C++ 14?

In C++14, there are new overloads of std::equal, std::mismatch, and std::is_permutation that can be used to take a pair of iterators for the second range. We can pass them in two full ranges that have a beginning and end.

In modern C++, the range parameter is obtained from a std::list without the original list that needs to be traversed through to get the size. In C++11, std::equal, std::mismatch, and std::is_permutation had 3 parameters, these were First1, Last1 for the Range1 and First2 for the Range2. In C++ 14, there is one more parameter that you can use, it is the Last2 for the Range2.

What is the new overload for the std::equal in C++14?

In C++11, std::equal is defined as below.

The std::equal is defined in the <xutility> header included in the <algorithm> header that returns true if the range between the First1 and Last1 is equal to the range between the First2 and the First2 + (Last1 – First1), and it returns false if this is not satisfied.

In C++14, std::equal is defined with the new input iteration parameter as below,

In C++ 14, the std::equal returns true if the range between the First1 and the Last1 is equal to the range between the First2 and the Last2, and it returns false if this is not satisfied. Here is an example,

What is the new overload for the std::mismatch in C++14?

The std::mismatch is defined in the <algorithm> header that returns the first mismatching pair of elements from two different ranges. First range is defined by First1 and the Last1 and the another one is defined by First2 and Last2 as in definition below,

Here is an example:

What is the new overload for the std::is_permutation in C++14?

The std::is_permutation is defined in the <algorithm> header that returns true if there exists a permutation of the elements in the range between the First1 and Last1 that makes that range equal to the range between First2 and Last 2. If the Last2 t was not given it denotes first2 + (last1 – first1). It is defined as below.

Is there a full example about the new overloads for ranges in C++ 14?

Here is a full example about the new overloads for std::equalstd::mismatch, and std::is_permutation.

For more details, please see this https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3671.html

What Are The New Overloads For Ranges In C++ 14 C++ Builder logo

C++ Builder is the easiest and fastest C and C++ compiler and IDE for building simple or professional applications on the Windows operating system. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++Syntax

Learn Default Constructors Of Classes In Modern C++

Artificial Intelligence TechC++C++11C++14C++17Learn C++

How To Develop Special AI Activation Functions In C++?

Artificial Intelligence TechC++C++11C++14C++17Language FeatureLearn C++

Learn How To Read The WAV Waveform Audio File Format In C++

C++C++11Learn C++

What Is Assignment Operator Overloading?