Questions tagged [c++14]

C++14 is the name of the C++ standard, approved in 2014. It builds upon the previous C++11 standard, improving the core language and standard library and adding some features.

C++14 is the name of the C++ standard, approved in 2014. It builds upon the previous standard, improving the core language and standard library and adding some features. Before the standard was approved, C++14 was commonly referred to as C++1y, following the pattern from C++0x, the pre-standardization name for C++11.

The ISO Standard, International Standard ISO/IEC 14882:2014(E) Programming Language C++, is available for purchase from the ISO website. The final draft was approved by the C++ working group on the 18th of August 2014. The draft closest to C++14 is N3936 (git), which will have only editorial differences from the full standard. It has been withdrawn from free distribution. The preceding draft N3797 remains available. The announcement of balloting mentions the set of final changes between these two documents will be minimal.

Please tag questions about C++14 with the tag, along with the tag.

Resources

New features

Core language

  • Polymorphic and variadic lambdas
  • Lambda capture initialization
  • Expanded return type deduction and decltype(auto)
  • Separators in numeric literals, ' (single quote) being the separator.
  • Relaxed constexpr functions and non-const constexpr member functions

Library

7718 questions
336
votes
2 answers

How to implement classic sorting algorithms in modern C++?

The std::sort algorithm (and its cousins std::partial_sort and std::nth_element) from the C++ Standard Library is in most implementations a complicated and hybrid amalgamation of more elementary sorting algorithms, such as selection sort, insertion…
TemplateRex
  • 65,583
  • 16
  • 147
  • 283
208
votes
2 answers

Can modern C++ get you performance for free?

It is sometimes claimed that C++11/14 can get you a performance boost even when merely compiling C++98 code. The justification is usually along the lines of move semantics, as in some cases the rvalue constructors are automatically generated or now…
alarge
  • 2,112
  • 2
  • 10
  • 14
185
votes
8 answers

Lambda capture as const reference?

Is it possible to capture by const reference in a lambda expression? I want the assignment marked below to fail, for example: #include #include #include #include using namespace std; int main() { string…
John Dibling
  • 94,084
  • 27
  • 171
  • 303
180
votes
6 answers

Does C++11, 14, 17 or 20 introduce a standard constant for pi?

There is a rather silly problem with the number pi in C and C++. As far as I know M_PI defined in math.h is not required by any standard. New C++ standards introduced a lot of complicated math in the standard library - hyperbolic functions,…
Amomum
  • 5,447
  • 5
  • 27
  • 54
168
votes
2 answers

What are some uses of decltype(auto)?

In c++14 the decltype(auto) idiom is introduced. Typically its use is to allow auto declarations to use the decltype rules on the given expression. Searching for examples of "good" usage of the idiom I can only think of things like the following…
Nikos Athanasiou
  • 24,831
  • 11
  • 72
  • 136
161
votes
2 answers

How does `void_t` work

I watched Walter Brown's talk at Cppcon14 about modern template programming (Part I, Part II) where he presented his void_t SFINAE technique. Example: Given a simple variable template that evaluates to void if all template arguments are well…
nonsensation
  • 3,317
  • 5
  • 26
  • 39
153
votes
7 answers

When should I use C++14 automatic return type deduction?

With GCC 4.8.0 released, we have a compiler that supports automatic return type deduction, part of C++14. With -std=c++1y, I can do this: auto foo() { //deduced to be int return 5; } My question is: When should I use this feature? When is it…
chris
  • 55,166
  • 13
  • 130
  • 185
149
votes
4 answers

Differences between std::make_unique and std::unique_ptr with new

Does std::make_unique have any efficiency benefits like std::make_shared? Compared to manually constructing std::unique_ptr: std::make_unique(1); // vs std::unique_ptr(new int(1));
NFRCR
  • 4,606
  • 4
  • 29
  • 34
147
votes
2 answers

Is #pragma once part of the C++11 standard?

Traditionally, the standard and portable way to avoid multiple header inclusions in C++ was/is to use the #ifndef - #define - #endifpre-compiler directives scheme also called macro-guard scheme (see code snippet below). #ifndef…
101010
  • 39,010
  • 10
  • 84
  • 149
136
votes
1 answer

Copy/move assignment in std::vector::erase() and std::deque::erase()

In the process of answering another question I stumbled upon slightly different wordings for std::vector::erase() and std::deque::erase(). This is what C++14 says about std::deque::erase ([deque.modifiers]/4-6, emphasis mine): Effects:…
Anton Savin
  • 38,277
  • 8
  • 49
  • 82
133
votes
2 answers

Advantages of using std::make_unique over new operator

What are the advantages of using std::make_unique over the new operator for initializing a std::unique_ptr? In other words, why is std::unique_ptr a = std::make_unique(SomeObject(...)) better than doing std::unique_ptr a =…
niting
  • 1,854
  • 3
  • 17
  • 20
120
votes
3 answers

How does generic lambda work in C++14?

How does generic lambda work (auto keyword as an argument type) in C++14 standard? Is it based on C++ templates where for each different argument type compiler generates a new function with the same body but replaced types (compile-time…
sasha.sochka
  • 12,899
  • 8
  • 41
  • 64
116
votes
3 answers

Is it safe to link C++17, C++14, and C++11 objects

Suppose I have three compiled objects, all produced by the same compiler/version: A was compiled with the C++11 standard B was compiled with the C++14 standard C was compiled with the C++17 standard For simplicity, let's assume all headers were…
ricab
  • 2,161
  • 3
  • 18
  • 26
112
votes
13 answers

How can I avoid "for" loops with an "if" condition inside them with C++?

With almost all code I write, I am often dealing with set reduction problems on collections that ultimately end up with naive "if" conditions inside of them. Here's a simple example: for(int i=0; i
Darkenor
  • 4,097
  • 8
  • 35
  • 65
110
votes
4 answers

What are transparent comparators?

In C++14, associative containers seem to have changed from C++11 – [associative.reqmts]/13 says: The member function templates find, count, lower_bound, upper_bound, and equal_range shall not participate in overload resolution unless the type…
Kerrek SB
  • 428,875
  • 83
  • 813
  • 1,025
1
2 3
99 100