You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f51815a
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/cpp/attributes2.md
+7-6Lines changed: 7 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,10 +11,11 @@ caps.latest.revision: 11
11
11
manager: "ghogen"
12
12
---
13
13
# 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.
16
15
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:
18
19
19
20
```cpp
20
21
voidg() {
@@ -39,9 +40,9 @@ void Foo(int);
39
40
40
41
-`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.
41
42
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.
43
44
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
45
46
46
47
```cpp
47
48
[[nodiscard]]
@@ -54,7 +55,7 @@ int main()
54
55
}
55
56
```
56
57
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.
Copy file name to clipboardExpand all lines: docs/cpp/bool-cpp.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,8 @@ translation.priority.ht:
39
39
---
40
40
# bool (C++)
41
41
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`.
42
44
43
45
The values **true** and **false** have the following relationship:
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.
168
168
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.
171
171
172
172
173
173
```cpp
@@ -185,8 +185,8 @@ E e2 = E{ 0 };
185
185
186
186
struct X
187
187
{
188
-
E e{ 0 };
189
-
X() : e{ 0 } { }
188
+
E e{ 0 };
189
+
X() : e{ 0 } { }
190
190
};
191
191
192
192
E* p = new E{ 0 };
@@ -195,12 +195,12 @@ void f(E e) {};
195
195
196
196
int main()
197
197
{
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 };
201
201
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'
Copy file name to clipboardExpand all lines: docs/cpp/examples-of-lambda-expressions.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -282,7 +282,7 @@ int main()
282
282
283
283
### Example
284
284
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.
286
286
287
287
You can use the `this` pointer explicitly in a function, as shown here:
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.
343
347
344
348
```cpp
345
349
#include<tuple>
@@ -350,36 +354,36 @@ using namespace std;
350
354
351
355
tuple<int, string, double> f()
352
356
{
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 };
357
361
}
358
362
structS
359
363
{
360
-
string name;
361
-
int num;
364
+
string name;
365
+
int num;
362
366
};
363
367
364
368
S g()
365
369
{
366
-
string t{ "hello" };
367
-
int u{ 42 };
368
-
return { t, u };
370
+
string t{ "hello" };
371
+
int u{ 42 };
372
+
return { t, u };
369
373
}
370
374
371
375
intmain()
372
376
{
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;
375
379
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;
379
383
}
380
384
```
381
385
382
-
4.Although not "returning values" in the strict sense, you can define any number of parameters to use pass-byreference 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).
383
387
384
388
## Function pointers
385
389
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.
Copy file name to clipboardExpand all lines: docs/cpp/if-else-statement-cpp.md
+10-5Lines changed: 10 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -118,7 +118,7 @@ int main()
118
118
}
119
119
```
120
120
## 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.
122
122
123
123
```cpp
124
124
## Example
@@ -171,20 +171,25 @@ int main()
171
171
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.
172
172
173
173
## 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):
Copy file name to clipboardExpand all lines: docs/cpp/lambda-expressions-constexpr.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ ms.author: "mblome"
19
19
manager: "ghogen"
20
20
---
21
21
# 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.
Copy file name to clipboardExpand all lines: docs/cpp/lambda-expressions-in-cpp.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -119,7 +119,8 @@ void f(Args... args) {
119
119
```
120
120
121
121
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.
123
124
124
125
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).
125
126
@@ -336,7 +337,7 @@ vector v after 2nd call to fillVector(): 10 11 12 13 14 15 16 17 18
336
337
For more information, see [generate_n](../standard-library/algorithm-functions.md#generate_n).
337
338
338
339
## 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.
0 commit comments