📜 ⬆️ ⬇️

C ++ 11 - removed and deprecated


Everything is already up to date with the release of the new standard C ++ 11, there have already been several articles on Habré about its features. But I decided to write about what was excluded from C ++ in the new version and for what reasons. It may not seem as important as new opportunities, but, as they say: "He who does not know history is doomed to repeat mistakes."

Dynamic exception specifications


You probably know that when declaring functions, you can specify which types of exceptions this function will generate. Somehow like this:
int A() throw(); //     int B() throw(A,B); //   A  B int (); //     

And it would seem - everything is fine, only in reality:
  1. Function A can generate any exception.
  2. Function B can generate any exception.
  3. Function C can generate nothing at all.
Who cares why this is so can read this article . I am already silent about the fact that the syntax of function A is completely unintuitive - when I first saw it, I decided that it was just function A that could generate any exceptions, but C - none. In addition, some compilers (for example, Microsoft Visual C ++) do not care about ads in the style of the function B - no checks will be performed, which warning will warn you honestly.

Now all this mess has been removed and one “noexcept” keyword has been added, explaining that the function cannot generate exceptions. And that's all.

auto_ptr


One type of smart pointers will no longer delight us with its presence in C ++. auto_ptr removed. The idea of ​​auto_ptr was good, but in practice it turned out that people absolutely do not read the documentation. And although it is clearly stated on the auto_ptr account that it cannot be used, for example, with STL collections, everyone did it all the time. And the worst thing is that it led to uncertain results. For example, here's the code:
 vector<auto_ptr<int> > vi; //..populate vi sort(vi.begin(), vi.end(), indirect_less()); 

Depending on the compiler, the OS, the STL version, and the phase of the moon, it may work, not work, or even fall at all. The C ++ Standardization Committee despaired of crying out to reason and replaced auto_ptr with unique_ptr, which in problems with auto_ptr behaves in a very definite way: either it works or it does not compile. I think everyone will agree that this is much more preferred behavior.
')

The concept of "point of following"


Lovers of questions "how much will be i ++ ++ i?" Always liked to talk about the points of following . Previously, the C ++ standard determined which operations are points of succession and which are not. Now the concept is abolished, although in fact nothing has changed. All operations are still divided into guaranteeing the sequence of performing certain actions and not guaranteeing. Now they say simply "the operation is consistent" or "the operation is not consistent." This change is explained by some ghostly hopes of simplifying the standardization of a new memory model (what is this all about?), Etc. It seems to me - a lie. Just “the point of following” sounded somehow very difficult. :)

Export templates


I think few people knew or used this feature. Here is an example:
 // File 1: #include <stdio.h> static void trace() { printf("File 1\n"); } // declaration only export template <class T> T const& min(T const&, T const&); int main() { trace(); return min(2, 3); } // File 2: #include <stdio.h> static void trace() { printf("File 2\n"); } //The definition export template <class T> T const& min(T const &a, T const &b) { trace(); return a<b ? a : b; } 

Please note that the template file is declared in one file, it is implemented in the other, the files do not include each other and each has its own version of the trace () function. More on this topic can be read here . The Edison Design Group company many years ago insisted on adding this feature to the standard. It seemed to them very important, they even did the implementation in their own compiler, though no one else did this (although their development, for example, used Borland). The time has passed and the EDG acknowledged that they were wrong. From the standard C ++ 11 export templates removed.

Good luck to everyone in studying the new standard, I will be very happy if the article turns out to be useful for someone.

Source: https://habr.com/ru/post/131512/


All Articles