The Wayback Machine - https://web.archive.org/web/20240826183114/https://www.geeksforgeeks.org/removed-features-of-cpp17/
Open In App

Removed Features of C++17

Last Updated : 02 Nov, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

C++17 enables writing simple, clearer, and more expressive code. Some of the features introduced in C++17 are:

  • Nested Namespaces
  • Variable declaration in if and switch
  • if constexpr statement
  • Structured bindings
  • Fold Expressions
  • Direct list initialization of enums

With the new version of C++17, many new functions are introduced but some features are removed or deprecated. These are listed below:

  • Removal of deprecated operator ++
  • Removal of registers
  • Removal of auto_ptr
  • Trigraphs
  • throw(typeid)
  • Allocator support in std::function
  • std::pointer_to_unary_function and std::pointer_to_binary_function
  • std::binder1st and std::binder2nd
  • std::bind1st and std::bind2nd
  • Other functions.

Let’s start discussing these functions in detail.

1. Removal of the deprecated operator ++: Postfix and prefix Increment (++) expressions are now not valid for bool operands since the prefix and postfix operator++ were overloaded for type bool, but in both cases, the return value for a bool argument is true. The bool type does not support the full set of arithmetic types. Since the launch of C++98, this change has been awaited. In the new version of C++17, it is no longer considered an arithmetic type and these operators have been deprecated.

Alternatives: The std::exchange can be used as an alternative for this, but only where the postfix operator has valid uses. The exchange function replaces the value of the object with a new value and returns the old value of the object.

2. Removal of registers: Long back, in C++11 register keyword was deprecated. The register keyword specifies or gives a hint to the compiler that the variable can be put in a register for fast access or these variables might be heavily used so that it can do optimization by storing them in a CPU register. But compilers do implicit optimizations and the hint was rarely used. Therefore, in the new version, the register keyword is removed, although the keyword is still reserved for future versions.

Syntax:

register string s = "Register on GfG"

 Alternatives: There is no alternative for register as the compiler does the same work automatically.

3. Removal of auto_ptr: auto_ptr was used to create a smart pointer to handle an object’s lifetime.  It is the owner of the object to which it refers. When an object gets destroyed, auto_ptr also gets destroyed automatically. This smart pointer quietly steals ownership of the managed object in its copy constructor and copy assignment from the right-hand argument. As a result, the copy is not the same as the original smart pointer object. Because of these copy semantics, auto_ptr does not work as CopyConstructible, and therefore it is deprecated. 

Alternatives: The auto_ptr can easily be replaced by, unique_ptr which is also a smart pointer with similar work but with improved security. It was introduced in C++11 as a direct replacement for auto_ptr as it provides new features (deletes) and support for arrays. Moreover, it allows only one owner of the referencing pointer. So, while using unique_ptr, there can only be at most one unique_ptr for one resource and when it is destroyed, the resource is automatically claimed. If there is an attempt to make a copy of unique_ptr, then it will cause a compile-time error.

Example:

unique_ptr<T> p1 (new T);
unique_ptr<T> p2 = p1;
// Error: can't copy unique_ptr

4. Trigraphs: The Trigraphs are a group of three characters. Basically, it is a special character sequence that is used as an alternative for some characters.  It is represented by two question marks.

Example:

??- produces ~ 
??= produces #
??/ produces \
??’ produces ^
??( produces [
??) produces ]
??! produces |
??< produces {
??> produces }

But they produce much confusion as they are parsed before comments and therefore removed in the latest version.

Alternatives: The C++17 does not provide any alternatives for Trigraph, as modern keyboards have all these features. Moreover, it produces a lot of bugs in the code.

5. throw(typeid): If any function is declared with type T listed in its exception specification, the function may throw exceptions to that type or a type derived from it. This is the non-throwing version of the dynamic exception specification that has been deprecated and is now removed. It has been replaced with noexcept which has a clearer meaning.

Syntax:

throw(typeid, typeid, ...)

Example:

void throwsInt(int x) throw(int) 
{
cout<<"throw function replaced with noexcept :)";
if (x == 0)
{
throw 1;
}
}

Alternatives: As mentioned above, throw can have a better alternative with noexcept. It specifies whether the functions can throw exceptions or not without specifying their type. But use it only when the invocation of the function cannot throw any error, otherwise, the program will terminate.

6. Allocator support in std::function: Several constructors allow to specify an allocator used for allocating internal memory. std::function also has constructors that take an allocator argument, but the semantics are unclear, and there are technical glitches with storing an allocator in a type-erased context and then recovering that allocator later for any allocations needed during copy assignment. Therefore, these constructor overloads were removed in C++17.

Alternatives: No such feature is present in C++, which replaces the allocator.

7. std::pointer_to_unary_function, std::pointer_to_binary_function: std::pointer_to_unary_function, std::pointer_to_binary_function function objects that act as wrappers around unary or binary functions. These functions include a constructor which constructs a new pointer_to_unary_function object with the supplied function and operator() function which calls the stored function.

Alternatives: These two functions  std::function and std::ref replace std::pointer_to_unary_function, std::pointer_to_binary_function.

8. std::binder1st and std::binder2nd: These are function objects that bind an argument to a binary function. The value of the parameter is passed to the object at the construction time and stored within the object. Whenever the function object is invoked through the operator() function, the stored value is passed as one of the arguments, the other argument is passed as an argument of operator(). The resulting function object is a unary function.

  • binder1st: Binds the first parameter to the value given at the time of the construction of the object.
  • binder2nd: Binds the second parameter to the value given at the time of the construction of the object.

Alternatives: Lambdas, std::bind are two features that can be alternatives for binder1st and binder2nd.

9. std::bind1st and std::bind2nd: These are helper functions that create instances of std::binder1st or std::binder2nd, which binds a given argument to a first or second parameter of a given binary function object. But these are of no use with the introduction of lambdas in C++11, therefore they were deprecated.

10. Other functions:

  • std::mem_fun_t,
  • std::mem_fun1_t
  • std::const_mem_fun_t
  • std::const_mem_fun1_t
  • std::mem_fun_ref_t
  • std::mem_fun1_ref_t
  • std::const_mem_fun_ref_t
  • std::const_mem_fun1_ref_t

These are function objects that wrap a pointer to a member function with no parameters or one parameter. The class instance whose member function to call is passed as a pointer to the operator() ie, the object whose member function to call is passed by the pointer to the call operator for the latter, is passed as a reference. They are deprecated because they are limited to member functions with either none or just one argument and different functions and function objects are required for handling pointers or references to the class instance.

Alternatives: The alternative to the above functions is std::mem_fn which can handle member functions with any number of variables and not only references or pointers to objects, but also smart pointers.



Similar Reads

Minimum number of digits to be removed so that no two consecutive digits are same
Given a number N. The task is to count the minimum number of digits to be removed from the number so that no two consecutive digits are the same.Examples: Input : N = 11344 Output : 2 Explanation : Remove the digit 1 from 2nd place and 4 from the end so that the number becomes 134. Thus no two consecutive digits are same. Hence answer is 2.Input :
5 min read
Shortest subarray to be removed to make all Array elements unique
Given an array arr[] containing N elements, the task is to remove a subarray of minimum possible length from the given array such that all remaining elements are distinct. Print the minimum possible length of the subarray.Examples: Input: N = 5, arr[] = {1, 2, 1, 2, 3} Output: 2 Explanation: Remove the sub array {2, 1} to make the elements distinct
12 min read
Maximum array elements that can be removed along with its adjacent values to empty given array
Given an array arr[] of size N. In each operation, pick an array element X and remove all array elements in the range [X - 1, X + 1]. The task is to find the maximum number of steps required such that no coins left in the array. Examples: Input: coins [] = {5, 1, 3, 2, 6, 7, 4} Output: 4 Explanation: Picking the coin coins[1] modifies the array arr
7 min read
Minimum number of alternate subsequences required to be removed to empty a Binary String
Given a binary string S consisting of N characters, the task is to print the minimum number of operations required to remove all the characters from the given string S by removing a single character or removing any subsequence of alternate characters in each operation. Examples: Input: S = "010101"Output: 1Explanation:Below are the operations perfo
6 min read
Check if sequence of removed middle elements from an array is sorted or not
Given an array arr[] consisting of N integers, the task is to check if the sequence of numbers formed by repeatedly removing the middle elements from the given array arr[] is sorted or not. If there are two middle elements, then remove any one of them. Examples: Input: arr[] = {4, 3, 1, 2, 5}Output: YesExplanation:The order of removing of elements
7 min read
Why Variable Length Array were Removed in C++?
While historically a feature in the C language, the variable length array is not part of standard C++. This article discusses the C++'s approach to dynamic memory allocation, showing an alternative strategy employed to achieve a similar outcome. Variable Length ArrayThe Array is said to be a variable length array if the size is defined at the runti
3 min read
Features and Use of Pointers in C/C++
Pointers store the address of variables or a memory location. Syntax: datatype *var_name; Example: pointer "ptr" holds the address of an integer variable or holds the address of memory whose value(s) can be accessed as integer values through "ptr" int *ptr; Features of Pointers: Pointers save memory space.Execution time with pointers is faster beca
2 min read
Features of C++ 17
C++17 enables writing simple, clearer, and more expressive code. Some of the features introduced in C++17 are: Nested NamespacesVariable declaration in if and switchif constexpr statementStructured bindingsFold ExpressionsDirect list initialization of enumsNested Namespaces Namespaces are a very convenient tool to organize and to structure the code
14 min read
Features of C++
C++ is a general-purpose programming language that was developed as an enhancement of the C language to include an object-oriented paradigm. It is an imperative and compiled language. C++ has a number of features, including: Object-Oriented ProgrammingMachine IndependentSimpleHigh-Level LanguagePopularCase-sensitiveCompiler BasedDynamic Memory Allo
6 min read
Features of C++ 20
C++ has a tradition of introducing new improvements and features in every 3 years in the form of a standard. With the last standard having released in 2017 as C++ 17, C++20 is going to be the latest standard. Below here are some major features in C++ 20: C++ Concepts library3-way comparisonsMap containsRange-based for loopNew identifiers ( import,
8 min read
Yahoo Finance : Meaning, Features, and Benefits
What is Yahoo Finance?Yahoo Finance is a comprehensive online platform that provides a wide range of financial information and services to users. Launched by Yahoo in 1997, it has since become one of the most popular and trusted sources for financial data, analysis, and news. Yahoo Finance aims to empower individuals with the knowledge they need to
7 min read
HostArmada Review: Details, Features, & Pricing
Whether you're a passionate blogger or a growing business, a reliable and feature-rich host is essential for a seamless online presence. But finding a perfect web hosting platform for your website can be tricky, especially when you are not aware of the options. Surprisingly, many web hosting companies are emerging that are providing unparalleled we
7 min read
QA Wolf: Introduction, Features, and Capabilities
In today's fast-paced software development world, striking the balance between quality and speed is a constant battle. Here, Quality Assurance (QA) plays a pivotal role in guaranteeing software reliability, efficiency, and user satisfaction. However, manual end-to-end testing can be time-consuming and inconsistent, hindering efficiency while tradit
6 min read
SaneBox: Features, Benefits, & Pricing
Digital Debris is real today and can easily be found in your email box. No matter how hard you try to remove that junk from your email list, it's never enough. Getting rid of emails that you never signed up for becomes a dream. And then suddenly SaneBox pops up as the most-awaited solution. It is the email management tool that is here to save you f
5 min read
C++ Programming Language
C++ is the most used and most popular programming language developed by Bjarne Stroustrup. C++ is a high-level and object-oriented programming language. This language allows developers to write clean and efficient code for large applications and software development, game development, and operating system programming. It is an expansion of the C pr
9 min read
30 OOPs Interview Questions and Answers (2024)
Object-Oriented Programming, or OOPs, is a programming paradigm that implements the concept of objects in the program. It aims to provide an easier solution to real-world problems by implementing real-world entities such as inheritance, abstraction, polymorphism, etc. in programming. OOPs concept is widely used in many popular languages like Java,
15+ min read
vector erase() and clear() in C++
Prerequisite: Vector in C++ Vectors are the same as dynamic arrays with the ability to resize themselves automatically when an element is inserted or deleted, with their storage being handled automatically by the container. vector::clear() The clear() function is used to remove all the elements of the vector container, thus making it size 0. Syntax
6 min read
Substring in C++
The substring function is used for handling string operations like strcat(), append(), etc. It generates a new string with its value initialized to a copy of a sub-string of this object. In C++, the header file which is required for std::substr(), string functions is &lt;string&gt;. The substring function takes two values pos and len as an argument
8 min read
Inheritance in C++
The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important features of Object Oriented Programming in C++. In this article, we will learn about inheritance in C++, its modes and types along with the information about how it affects different properties of the
15+ min read
C++ Classes and Objects
In C++, classes and objects are the basic building block that leads to Object-Oriented programming in C++. In this article, we will learn about C++ classes, objects, look at how they work and how to implement them in our C++ program. What is a Class in C++?A class is a user-defined data type, which holds its own data members and member functions, w
9 min read
Converting Number to String in C++
In C++, converting integers to strings or converting numbers to strings or vice-versa is actually a big paradigm shift in itself. In general or more specifically in competitive programming there are many instances where we need to convert a number to a string or string to a number. Let's look at some methods to convert an integer or a number to a s
4 min read
Convert String to int in C++
Converting a string to int is one of the most frequently encountered tasks in C++. As both string and int are not in the same object hierarchy, we cannot perform implicit or explicit type casting as we can do in case of double to int or float to int conversion. Conversion is mostly done so that we can convert numbers that are stored as strings. Exa
8 min read
std::sort() in C++ STL
We have discussed qsort() in C. C++ STL provides a similar function sort that sorts a vector or array (items with random access) It generally takes two parameters, the first one being the point of the array/vector from where the sorting needs to begin and the second parameter being the length up to which we want the array/vector to get sorted. The
6 min read
How to implement Min Heap using STL?
In C++ STL, there is priority_queue that can directly be used to implement Max Heap. In order to fully understand the code, make sure you are familiar with following concepts in C++ Container Adaptors in STLFunctors See below example: C/C++ Code // C++ program to show that priority_queue is by // default a Max Heap #include &lt;bits/stdc++.h&gt; us
4 min read
Priority Queue in C++ Standard Template Library (STL)
A C++ priority queue is a type of container adapter, specifically designed such that the first element of the queue is either the greatest or the smallest of all elements in the queue, and elements are in non-increasing or non-decreasing order (hence we can see that each element of the queue has a priority {fixed order}). In C++ STL, the top elemen
11 min read
Vector in C++ STL
Vectors are the same as dynamic arrays with the ability to resize themselves automatically when an element is inserted or deleted, with their storage being handled automatically by the container. Vector elements are placed in contiguous storage so that they can be accessed and traversed using iterators. In vectors, data is inserted at the end. Inse
10 min read
Set in C++ Standard Template Library (STL)
Sets are a type of associative container in which each element has to be unique because the value of the element identifies it. The values are stored in a specific sorted order i.e. either ascending or descending. The std::set class is the part of C++ Standard Template Library (STL) and it is defined inside the &lt;set&gt; header file. Syntax: std:
7 min read
Map in C++ Standard Template Library (STL)
Maps are associative containers that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have the same key values. std::map is the class template for map containers and it is defined inside the &lt;map&gt; header file. Basic std::map Member FunctionsSome basic functions associated with std::
8 min read
Object Oriented Programming in C++
Object-oriented programming - As the name suggests uses objects in programming. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc. in programming. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data
9 min read
Bitwise Operators in C
In C, the following 6 operators are bitwise operators (also known as bit operators as they work at the bit-level). They are used to perform bitwise operations in C. The &amp; (bitwise AND) in C takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1.  The | (bitwise OR) in C takes two n
7 min read
Article Tags :
Practice Tags :