Skip to content

Commit ba9ccff

Browse files
author
Colin Robertson
committed
Remove extraneous tabs, fix other space issues
1 parent 5c60362 commit ba9ccff

18 files changed

+904
-964
lines changed

docs/cpp/function-overloading.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ int print(double dvalue, int prec)
9797
const int iPowZero = 6;
9898

9999
// If precision out of range, just print the number.
100-
if (prec < -6 || prec > 7)
101-
{
102-
return print(dvalue);
103-
}
100+
if (prec < -6 || prec > 7)
101+
{
102+
return print(dvalue);
103+
}
104104
// Scale, truncate, then rescale.
105105
dvalue = floor(dvalue / rgPow10[iPowZero - prec]) *
106106
rgPow10[iPowZero - prec];

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

+60-59
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ ms.workload: ["cplusplus"]
1515
# if-else Statement (C++)
1616

1717
Controls conditional branching. Statements in the *if-block* are executed only if the *if-expression* evaluates to a non-zero value (or TRUE). If the value of *expression* is nonzero, *statement1* and any other statements in the block are executed and the else-block, if present, is skipped. If the value of *expression* is zero, then the if-block is skipped and the else-block, if present, is executed. Expressions that evaluate to non-zero are
18+
1819
- TRUE
1920
- a non-null pointer,
2021
- any non-zero arithmetic value, or
2122
- a class type that defines an unambiguous conversion to an arithmetic, boolean or pointer type. (For information about conversions, see [Standard Conversions](../cpp/standard-conversions.md).)
2223

2324
## Syntax
2425

25-
```
26+
```cpp
2627
if ( expression )
2728
{
2829
   statement1;
@@ -70,49 +71,49 @@ using namespace std;
7071
class C
7172
{
7273
public:
73-
void do_somthing(){}
74+
void do_something(){}
7475
};
7576
void init(C){}
7677
bool is_true() { return true; }
7778
int x = 10;
7879

7980
int main()
8081
{
81-
if (is_true())
82-
{
83-
cout << "b is true!\n"; // executed
84-
}
85-
else
86-
{
87-
cout << "b is false!\n";
88-
}
89-
90-
// no else statement
91-
if (x == 10)
92-
{
93-
x = 0;
94-
}
95-
96-
97-
C* c;
98-
init(c);
99-
if (c)
100-
{
101-
c->do_something();
102-
}
103-
else
104-
{
105-
cout << "c is null!\n";
106-
}
82+
if (is_true())
83+
{
84+
cout << "b is true!\n"; // executed
85+
}
86+
else
87+
{
88+
cout << "b is false!\n";
89+
}
90+
91+
// no else statement
92+
if (x == 10)
93+
{
94+
x = 0;
95+
}
96+
97+
C* c;
98+
init(c);
99+
if (c)
100+
{
101+
c->do_something();
102+
}
103+
else
104+
{
105+
cout << "c is null!\n";
106+
}
107107
}
108108
```
109+
109110
## <a name="if_with_init"></a> if statement with an initializer
110111
111112
**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.
112113
113-
```cpp
114114
## Example
115115
116+
```cpp
116117
#include <iostream>
117118
#include <mutex>
118119
#include <map>
@@ -129,28 +130,28 @@ void unsafe_operation() {}
129130
int main()
130131
{
131132
132-
if (auto it = m.find(10); it != m.end())
133-
{
134-
cout << it->second;
135-
return 0;
136-
}
133+
if (auto it = m.find(10); it != m.end())
134+
{
135+
cout << it->second;
136+
return 0;
137+
}
137138
138-
if (char buf[10]; fgets(buf, 10, stdin))
139-
{
140-
m[0] += buf;
141-
}
139+
if (char buf[10]; fgets(buf, 10, stdin))
140+
{
141+
m[0] += buf;
142+
}
142143
143-
if (lock_guard<mutex> lock(mx); shared_flag)
144-
{
145-
unsafe_operation();
146-
shared_flag = false;
147-
}
144+
if (lock_guard<mutex> lock(mx); shared_flag)
145+
{
146+
unsafe_operation();
147+
shared_flag = false;
148+
}
148149
149-
string s{ "if" };
150+
string s{ "if" };
150151
if (auto keywords = { "if", "for", "while" }; any_of(keywords.begin(), keywords.end(), [&s](const char* kw) { return s == kw; }))
151-
{
152-
cout << "Error! Token must not be a keyword\n";
153-
}
152+
{
153+
cout << "Error! Token must not be a keyword\n";
154+
}
154155
}
155156
```
156157

@@ -166,18 +167,18 @@ The **else** clause of an `if...else` statement is associated with the closest p
166167
template <class T, class... Rest>
167168
void f(T&& t, Rest&&... r)
168169
{
169-
// handle t
170-
do_something(t);
171-
172-
// handle r conditionally
173-
if constexpr (sizeof...(r))
174-
{
175-
f(r...);
176-
}
177-
else
178-
{
179-
g(r...);
180-
}
170+
// handle t
171+
do_something(t);
172+
173+
// handle r conditionally
174+
if constexpr (sizeof...(r))
175+
{
176+
f(r...);
177+
}
178+
else
179+
{
180+
g(r...);
181+
}
181182
}
182183
```
183184

docs/cpp/lambda-expressions-constexpr.md

+19-16
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,38 @@ ms.workload: ["cplusplus"]
1717

1818
```cpp
1919
int y = 32;
20-
auto answer = [y]() constexpr
21-
{
22-
int x = 10;
23-
return y + x;
24-
};
20+
auto answer = [y]() constexpr
21+
{
22+
int x = 10;
23+
return y + x;
24+
};
2525

2626
constexpr int Increment(int n)
2727
{
28-
return [n] { return n + 1; }();
28+
return [n] { return n + 1; }();
2929
}
3030
```
31+
3132
A lambda is implicitly **constexpr** if its result satisfies the requirements of a **constexpr** function:
33+
3234
```cpp
33-
auto answer = [](int n)
34-
{
35-
return 32 + n;
36-
};
35+
auto answer = [](int n)
36+
{
37+
return 32 + n;
38+
};
3739
38-
constexpr int response = answer(10);
40+
constexpr int response = answer(10);
3941
```
42+
4043
If a lambda is implicitly or explicitly **constexpr**, and you convert it to a function pointer, the resulting function is also **constexpr**:
4144

4245
```cpp
43-
auto Increment = [](int n)
44-
{
45-
return n + 1;
46-
};
46+
auto Increment = [](int n)
47+
{
48+
return n + 1;
49+
};
4750

48-
constexpr int(*inc)(int) = Increment;
51+
constexpr int(*inc)(int) = Increment;
4952
```
5053
5154
## See also

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

+19-16
Original file line numberDiff line numberDiff line change
@@ -326,35 +326,38 @@ For more information, see [generate_n](../standard-library/algorithm-functions.m
326326

327327
```cpp
328328
int y = 32;
329-
auto answer = [y]() constexpr
330-
{
331-
int x = 10;
332-
return y + x;
333-
};
329+
auto answer = [y]() constexpr
330+
{
331+
int x = 10;
332+
return y + x;
333+
};
334334

335335
constexpr int Increment(int n)
336336
{
337-
return [n] { return n + 1; }();
337+
return [n] { return n + 1; }();
338338
}
339339
```
340+
340341
A lambda is implicitly `constexpr` if its result satisfies the requirements of a `constexpr` function:
342+
341343
```cpp
342-
auto answer = [](int n)
343-
{
344-
return 32 + n;
345-
};
344+
auto answer = [](int n)
345+
{
346+
return 32 + n;
347+
};
346348
347-
constexpr int response = answer(10);
349+
constexpr int response = answer(10);
348350
```
351+
349352
If a lambda is implicitly or explicitly `constexpr`, conversion to a function pointer produces a `constexpr` function:
350353

351354
```cpp
352-
auto Increment = [](int n)
353-
{
354-
return n + 1;
355-
};
355+
auto Increment = [](int n)
356+
{
357+
return n + 1;
358+
};
356359

357-
constexpr int(*inc)(int) = Increment;
360+
constexpr int(*inc)(int) = Increment;
358361
```
359362
360363
## Microsoft-Specific

docs/cpp/member-access-control-cpp.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected: // Declare protected function for derived classes only.
3535

3636
The default access is **private** in a class, and **public** in a struct or union. Access specifiers in a class can be used any number of times in any order. The allocation of storage for objects of class types is implementation dependent, but members are guaranteed to be assigned successively higher memory addresses between access specifiers.
3737

38-
### Member-Access Control
38+
## Member-Access Control
3939

4040
|Type of Access|Meaning|
4141
|--------------------|-------------|
@@ -73,40 +73,40 @@ The following example illustrates this:
7373
class BaseClass
7474
{
7575
public:
76-
int PublicFunc(); // Declare a public member.
76+
int PublicFunc(); // Declare a public member.
7777
protected:
78-
int ProtectedFunc(); // Declare a protected member.
78+
int ProtectedFunc(); // Declare a protected member.
7979
private:
80-
int PrivateFunc(); // Declare a private member.
80+
int PrivateFunc(); // Declare a private member.
8181
};
8282

8383
// Declare two classes derived from BaseClass.
8484
class DerivedClass1 : public BaseClass
8585
{
86-
void foo()
87-
{
88-
PublicFunc();
89-
ProtectedFunc();
90-
PrivateFunc(); // function is inaccessible
91-
}
86+
void foo()
87+
{
88+
PublicFunc();
89+
ProtectedFunc();
90+
PrivateFunc(); // function is inaccessible
91+
}
9292
};
9393

9494
class DerivedClass2 : private BaseClass
9595
{
96-
void foo()
97-
{
98-
PublicFunc();
99-
ProtectedFunc();
100-
PrivateFunc(); // function is inaccessible
101-
}
96+
void foo()
97+
{
98+
PublicFunc();
99+
ProtectedFunc();
100+
PrivateFunc(); // function is inaccessible
101+
}
102102
};
103103

104104
int main()
105105
{
106-
DerivedClass1 derived_class1;
107-
DerivedClass2 derived_class2;
108-
derived_class1.PublicFunc();
109-
derived_class2.PublicFunc(); // function is inaccessible
106+
DerivedClass1 derived_class1;
107+
DerivedClass2 derived_class2;
108+
derived_class1.PublicFunc();
109+
derived_class2.PublicFunc(); // function is inaccessible
110110
}
111111
```
112112

0 commit comments

Comments
 (0)