Skip to content

Commit f51815a

Browse files
author
Michael Blome
committed
local merge
2 parents ca5dc9d + 32df055 commit f51815a

14 files changed

+107
-108
lines changed

docs/cpp/attributes2.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ caps.latest.revision: 11
1111
manager: "ghogen"
1212
---
1313
# Attributes in C++
14-
The C++ standard defines a set of attributes and also allows compiler vendors to define their own attributes (within a vendor-specific namespace), but compilers are required to recognize only those attributes defined in the standard.
15-
In some cases, standard attributes overlap with compiler-specific declspec parameters. Visual C++, you can use the [[deprecated]] attribute instead of using declspec(deprecated) and the attribute will be recognized by any conformant compiler. For all other declspec parameters such as dllimport and dllexport, there is as yet no standard attribute equivalent so you must continue to use declspec syntax. Attributes do not affect the type system, and they don’t change the meaning of a program. Compilers ignore attribute values they don't recognize.
14+
The C++ Standard defines a set of attributes and also allows compiler vendors to define their own attributes (within a vendor-specific namespace), but compilers are required to recognize only those attributes defined in the standard.
1615

17-
**Visual Studio 2017 version 15.3 and later:**(available with [/std:c++latest](../build/reference/std-specify-language-standard-version.md)) In the scope of an attribute list, you can specify the namespace for all names with a single `using` introducer:
16+
In some cases, standard attributes overlap with compiler-specific declspec parameters. In Visual C++, you can use the `[[deprecated]]` attribute instead of using `declspec(deprecated)` and the attribute will be recognized by any conformant compiler. For all other declspec parameters such as dllimport and dllexport, there is as yet no attribute equivalent so you must continue to use declspec syntax. Attributes do not affect the type system, and they don’t change the meaning of a program. Compilers ignore attribute values they don't recognize.
17+
18+
**Visual Studio 2017 version 15.3 and later**(available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)): In the scope of an attribute list, you can specify the namespace for all names with a single `using` introducer:
1819

1920
```cpp
2021
void g() {
@@ -39,9 +40,9 @@ void Foo(int);
3940

4041
- `deprecated` - **Visual Studio 2015 and later:** Specifies that a function is not intended to be used, and might not exist in future versions of a library interface. The compiler can use this to generate an informational message when client code attempts to call the function. Can be applied to declaration of a class, a typedef-name, a variable, a non-static data member, a function, a namespace, an enumeration, an enumerator, or a template specialization.
4142

42-
- `fallthrough` - **Visual Studio 2017 and later:**(available with [/std:c++latest](../build/reference/std-specify-language-standard-version.md)) The `[[fallthrough]]` attribute can be used in the context of [switch](switch-statement-cpp.md) statements as a hint to the compiler (or anyone reading the code) that the fallthrough behavior is intended. The Visual C++ compiler currently does not warn on fallthrough behavior, so this attribute has no effect compiler behavior.
43+
- `[[fallthrough]]` - **Visual Studio 2017 and later:** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)) The `[[fallthrough]]` attribute can be used in the context of [switch](switch-statement-cpp.md) statements as a hint to the compiler (or anyone reading the code) that the fallthrough behavior is intended. The Visual C++ compiler currently does not warn on fallthrough behavior, so this attribute has no effect compiler behavior.
4344

44-
- `nodiscard` **Visual Studio 2017 version 15.3 and later:**(available with [/std:c++latest](../build/reference/std-specify-language-standard-version.md)) Specifies that a function's return value is not intended to be discarded. Raises warning C4834, as shown in the following example
45+
- `[[nodiscard]]` **Visual Studio 2017 version 15.3 and later:** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)) Specifies that a function's return value is not intended to be discarded. Raises warning C4834, as shown in the following example
4546

4647
```cpp
4748
[[nodiscard]]
@@ -54,7 +55,7 @@ int main()
5455
}
5556
```
5657
57-
- `[[maybe_unused]]` **Visual Studio 2017 version 15.3 and later:**(available with [/std:c++latest](../build/reference/std-specify-language-standard-version.md)) Specifies that a variable, function, class, typedef, non-static data member, enum, or template specialization may intentionally not be used. The compiler does not warn when an entity marked `[[maybe_unused]]` is not used. An entity that is declared without the attribute can later be redeclared with the attribute and vice versa. An entity is considered marked after its first declaration that is marked is analyzed, and for the remainder of translation of the current translation unit.
58+
- `[[maybe_unused]]` **Visual Studio 2017 version 15.3 and later:** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)) Specifies that a variable, function, class, typedef, non-static data member, enum, or template specialization may intentionally not be used. The compiler does not warn when an entity marked `[[maybe_unused]]` is not used. An entity that is declared without the attribute can later be redeclared with the attribute and vice versa. An entity is considered marked after its first declaration that is marked is analyzed, and for the remainder of translation of the current translation unit.
5859
5960
## Microsoft-specific attributes
6061

docs/cpp/bool-cpp.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ translation.priority.ht:
3939
---
4040
# bool (C++)
4141
This keyword is a built-in type. A variable of this type can have values [true](../cpp/true-cpp.md) and [false](../cpp/false-cpp.md). Conditional expressions have the type `bool` and so have values of type `bool`. For example, `i!=0` now has **true** or **false** depending on the value of `i`.
42+
43+
**Visual Studio 2017 version 15.3 and later** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)): The operand of a postfix or prefix increment or decrement operator may not be of type `bool`.
4244

4345
The values **true** and **false** have the following relationship:
4446

docs/cpp/enumerations-cpp.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ namespace ScopedEnumConversions
166166

167167
Notice that the line `hand = account_num;` still causes the error that occurs with unscoped enums, as shown earlier. It is allowed with an explicit cast. However, with scoped enums, the attempted conversion in the next statement, `account_num = Suit::Hearts;`, is no longer allowed without an explicit cast.
168168

169-
## Enums with no enumerators (Visual Studio 2017 version 15.3 and later)
170-
By defining an enum (regular or scoped) with an explicit underlying type and no enumerators, you can in effect introduce a new integral type that has no implicit conversion to any other type. By using this type instead of its built-in underlying type, you can eliminate the potential for subtle errors caused by inadvertent implicit conversions.
169+
## Enums with no enumerators
170+
**Visual Studio 2017 version 15.3 and later** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)): By defining an enum (regular or scoped) with an explicit underlying type and no enumerators, you can in effect introduce a new integral type that has no implicit conversion to any other type. By using this type instead of its built-in underlying type, you can eliminate the potential for subtle errors caused by inadvertent implicit conversions.
171171

172172

173173
```cpp
@@ -185,8 +185,8 @@ E e2 = E{ 0 };
185185
186186
struct X
187187
{
188-
E e{ 0 };
189-
X() : e{ 0 } { }
188+
E e{ 0 };
189+
X() : e{ 0 } { }
190190
};
191191
192192
E* p = new E{ 0 };
@@ -195,12 +195,12 @@ void f(E e) {};
195195
196196
int main()
197197
{
198-
f(E{ 0 });
199-
byte i{ 42 };
200-
byte j = byte{ 42 };
198+
f(E{ 0 });
199+
byte i{ 42 };
200+
byte j = byte{ 42 };
201201
202-
// unsigned char c = j; // C2440: 'initializing': cannot convert from 'byte' to 'unsigned char'
203-
return 0;
202+
// unsigned char c = j; // C2440: 'initializing': cannot convert from 'byte' to 'unsigned char'
203+
return 0;
204204
}
205205
```
206206

docs/cpp/examples-of-lambda-expressions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ int main()
282282

283283
### Example
284284
You can use lambda expressions in the body of a function. The lambda expression can access any function or data member that the enclosing function can access. You can explicitly or implicitly capture the `this` pointer to provide access to functions and data members of the enclosing class.
285-
**Visual Studio 2017 version 15.3 and later**: Capture `this` by value (`[*this]`) when the lambda will be used in asynchronous or parallel operations where the code might execute after the original object goes out of scope.
285+
**Visual Studio 2017 version 15.3 and later** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)): Capture `this` by value (`[*this]`) when the lambda will be used in asynchronous or parallel operations where the code might execute after the original object goes out of scope.
286286

287287
You can use the `this` pointer explicitly in a function, as shown here:
288288

docs/cpp/functions-cpp.md

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ template<typename F, typename Tuple = tuple<T...>,
278278
```
279279
## Returning multiple values from a function
280280
There are various ways to return more than one value from a function:
281+
281282
1. Encapsulate the values in a named class or struct object. Requires the class or struct definition to be visible to the caller:
282283
283284
```cpp
@@ -288,25 +289,27 @@ using namespace std;
288289
289290
struct S
290291
{
291-
string name;
292-
int num;
292+
string name;
293+
int num;
293294
};
294295
295296
S g()
296297
{
297-
string t{ "hello" };
298-
int u{ 42 };
299-
return { t, u };
298+
string t{ "hello" };
299+
int u{ 42 };
300+
return { t, u };
300301
}
301302
302303
int main()
303304
{
304-
S s = g();
305-
cout << s.name << " " << s.num << endl;
306-
return 0;
305+
S s = g();
306+
cout << s.name << " " << s.num << endl;
307+
return 0;
307308
}
308309
```
310+
309311
2. Return a std::tuple or std::pair object:
312+
310313
```cpp
311314
#include <tuple>
312315
#include <string>
@@ -317,29 +320,30 @@ using namespace std;
317320

318321
tuple<int, string, double> f()
319322
{
320-
int i{ 108 };
321-
string s{ "Some text" };
322-
double d{ .01 };
323-
return { i,s,d };
323+
int i{ 108 };
324+
string s{ "Some text" };
325+
double d{ .01 };
326+
return { i,s,d };
324327
}
325328

326329
int main()
327330
{
328-
auto t = f();
329-
cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << endl;
331+
auto t = f();
332+
cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << endl;
330333

331-
// --or--
334+
// --or--
332335

333-
int myval;
334-
string myname;
335-
double mydecimal;
336-
tie(myval, myname, mydecimal) = f();
337-
cout << myval << " " << myname << " " << mydecimal << endl;
336+
int myval;
337+
string myname;
338+
double mydecimal;
339+
tie(myval, myname, mydecimal) = f();
340+
cout << myval << " " << myname << " " << mydecimal << endl;
338341

339-
return 0;
342+
return 0;
340343
}
341344
```
342-
3. Use structured bindings (**Visual Studio 2017 version 15.3 and later**): The advantage of structured bindings is that the variables that store the return values are initialized at the same time they are declared, which in some cases can be significantly more efficient. In this statement --`auto[x, y, z] = f();`-- the brackets introduce and intialize names that are in scope for the entire function block.
345+
346+
3. **Visual Studio 2017 version 15.3 and later** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)): Use structured bindings. The advantage of structured bindings is that the variables that store the return values are initialized at the same time they are declared, which in some cases can be significantly more efficient. In this statement --`auto[x, y, z] = f();`-- the brackets introduce and intialize names that are in scope for the entire function block.
343347

344348
```cpp
345349
#include <tuple>
@@ -350,36 +354,36 @@ using namespace std;
350354

351355
tuple<int, string, double> f()
352356
{
353-
int i{ 108 };
354-
string s{ "Some text" };
355-
double d{ .01 };
356-
return { i,s,d };
357+
int i{ 108 };
358+
string s{ "Some text" };
359+
double d{ .01 };
360+
return { i,s,d };
357361
}
358362
struct S
359363
{
360-
string name;
361-
int num;
364+
string name;
365+
int num;
362366
};
363367

364368
S g()
365369
{
366-
string t{ "hello" };
367-
int u{ 42 };
368-
return { t, u };
370+
string t{ "hello" };
371+
int u{ 42 };
372+
return { t, u };
369373
}
370374

371375
int main()
372376
{
373-
auto[x, y, z] = f(); // init from tuple
374-
cout << x << " " << y << " " << z << endl;
377+
auto[x, y, z] = f(); // init from tuple
378+
cout << x << " " << y << " " << z << endl;
375379

376-
auto[a, b] = g(); // init from POD struct
377-
cout << a << " " << b << endl;
378-
return 0;
380+
auto[a, b] = g(); // init from POD struct
381+
cout << a << " " << b << endl;
382+
return 0;
379383
}
380384
```
381385

382-
4. Although not "returning values" in the strict sense, you can define any number of parameters to use pass-by reference so that the function can modify or initialize the values of objects that the caller provides. For more information, see [Reference-Type Function Arguments](reference-type-function-arguments.md).
386+
4. In addition to using the return value itself, you can "return" values by defining any number of parameters to use pass-by-reference so that the function can modify or initialize the values of objects that the caller provides. For more information, see [Reference-Type Function Arguments](reference-type-function-arguments.md).
383387

384388
## Function pointers
385389
C++ supports function pointers in the same manner as the C language. However a more type-safe alternative is usually to use a function object.

docs/cpp/if-else-statement-cpp.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int main()
118118
}
119119
```
120120
## if statement with an initializer
121-
**Visual Studio 2017 version 15.3 and later**: An **if** statement may also contain an expression that declares and initializes a named variable. Use this form of the if-statement when the variable is only needed within the scope of the if-block.
121+
**Visual Studio 2017 version 15.3 and later** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)): An **if** statement may also contain an expression that declares and initializes a named variable. Use this form of the if-statement when the variable is only needed within the scope of the if-block.
122122

123123
```cpp
124124
## Example
@@ -171,20 +171,25 @@ int main()
171171
The **else** clause of an `if...else` statement is associated with the closest previous **if** statement in the same scope that does not have a corresponding **else** statement.
172172

173173
## constexpr if statements
174-
**Visual Studio 2017 version 15.3 and later**: In function templates, you can use a **constexpr if** statement to make compile-time branching decisions without having to resort to multiple function overloads. For example, you can write a single function that handles parameter unpacking (no zero-parameter overload is needed):
174+
**Visual Studio 2017 version 15.3 and later** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)): In function templates, you can use a **constexpr if** statement to make compile-time branching decisions without having to resort to multiple function overloads. For example, you can write a single function that handles parameter unpacking (no zero-parameter overload is needed):
175175

176176
```cpp
177177
template <class T, class... Rest>
178178
void f(T&& t, Rest&&... r)
179179
{
180-
// handle t
181-
do_something(t);
180+
// handle t
181+
do_something(t);
182182

183+
// handle r conditionally
183184
constexpr if (sizeof...(r))
184185
{
185-
// handle r
186+
186187
f(r...);
187188
}
189+
else
190+
{
191+
g(r...);
192+
}
188193
}
189194
```
190195

docs/cpp/lambda-expressions-constexpr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ms.author: "mblome"
1919
manager: "ghogen"
2020
---
2121
# constexpr Lambda Expressions in C++
22-
In Visual Studio 2017 version 15.3 and later, a lambda expression may be declared as `constexpr` or used in a contant expression when the initialization of each data member that it captures or introduces is allowed within a constant expression.
22+
**Visual Studio 2017 version 15.3 and later** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)): A lambda expression may be declared as `constexpr` or used in a contant expression when the initialization of each data member that it captures or introduces is allowed within a constant expression.
2323

2424
```cpp
2525
int y = 32;

docs/cpp/lambda-expressions-in-cpp.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ void f(Args... args) {
119119
```
120120

121121
To use lambda expressions in the body of a class method, pass the `this` pointer to the capture clause to provide access to the methods and data members of the enclosing class.
122-
**Visual Studio 2017 version 15.3 and later**: The `this` pointer may be captured by value by specifying `*this` in the capture clause. Capture by value means that the entire *closure*, which is the anonymous function object that encapulates the lambda expression, is copied to every call site where the lambda is invoked. Capture by value is useful when the lambda will execute in parallel or asynchronous operations, especially on certain hardware architectures such as NUMA.
122+
123+
**Visual Studio 2017 version 15.3 and later** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)): The `this` pointer may be captured by value by specifying `*this` in the capture clause. Capture by value means that the entire *closure*, which is the anonymous function object that encapulates the lambda expression, is copied to every call site where the lambda is invoked. Capture by value is useful when the lambda will execute in parallel or asynchronous operations, especially on certain hardware architectures such as NUMA.
123124

124125
For an example that shows how to use lambda expressions with class methods, see "Example: Using a Lambda Expression in a Method" in [Examples of Lambda Expressions](../cpp/examples-of-lambda-expressions.md).
125126

@@ -336,7 +337,7 @@ vector v after 2nd call to fillVector(): 10 11 12 13 14 15 16 17 18
336337
For more information, see [generate_n](../standard-library/algorithm-functions.md#generate_n).
337338

338339
## constexpr lambda expressions
339-
**Visual Studio 2017 version 15.3 and later**: A lambda expression may be declared as `constexpr` or used in a contant expression when the initialization of each data member that it captures or introduces is allowed within a constant expression.
340+
**Visual Studio 2017 version 15.3 and later** (available with [/std:c++17](../build/reference/std-specify-language-standard-version.md)): A lambda expression may be declared as `constexpr` or used in a constant expression when the initialization of each data member that it captures or introduces is allowed within a constant expression.
340341

341342
```cpp
342343
int y = 32;

0 commit comments

Comments
 (0)