mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
fix Travis CI issues caused by recent direct commits
This commit is contained in:
parent
141356db52
commit
7890037c8d
|
@ -2768,13 +2768,14 @@ It complicates checking and tool support.
|
|||
|
||||
##### Example
|
||||
|
||||
void use(int* p, int nchar* s, int* q)
|
||||
void use(int* p, int n, char* s, int* q)
|
||||
{
|
||||
p[n-1] = 666; // Bad: we don't know if p points to n elements; assume it does not or use span<int>
|
||||
|
||||
cout << s; // Bad: we don't know if that s points to a zero-terminated array of char; // assume it does not or use zstring
|
||||
|
||||
delete q; // Bad: we don't know if *q is allocated on the free store; assume it does not or use owner
|
||||
p[n-1] = 666; // Bad: we don't know if p points to n elements;
|
||||
// assume it does not or use span<int>
|
||||
cout << s; // Bad: we don't know if that s points to a zero-terminated array of char;
|
||||
// assume it does not or use zstring
|
||||
delete q; // Bad: we don't know if *q is allocated on the free store;
|
||||
//assume it does not or use owner
|
||||
}
|
||||
|
||||
better
|
||||
|
@ -2782,9 +2783,7 @@ better
|
|||
void use2(span<int> p, zstring s, owner<int*> q)
|
||||
{
|
||||
p[p.size()-1] = 666; // OK, a range error can be caught
|
||||
|
||||
cout << s; // OK
|
||||
|
||||
delete q; // OK
|
||||
}
|
||||
|
||||
|
@ -7479,9 +7478,12 @@ The default is the easiest to read and write.
|
|||
|
||||
##### Example
|
||||
|
||||
enum class Direction : char { n, s, e, w, ne, nw, se, sw }; // underlying type saves space
|
||||
enum class Direction : char { n, s, e, w,
|
||||
ne, nw, se, sw }; // underlying type saves space
|
||||
|
||||
enum class Webcolor : int { red = 0xFF0000, green = 0x00FF00, blue = 0x0000FF }; // underlying type is redundant
|
||||
enum class Webcolor : int { red = 0xFF0000,
|
||||
green = 0x00FF00,
|
||||
blue = 0x0000FF }; // underlying type is redundant
|
||||
|
||||
##### Note
|
||||
|
||||
|
@ -7513,7 +7515,8 @@ The default gives a consequtive set of values that is good for `switch`-statemen
|
|||
|
||||
enum class Col1 { red, yellow, blue };
|
||||
enum class Col2 { red = 1, red = 2, blue = 2 }; // typo
|
||||
enum class Month { jan=1, feb, mar, apr, mar, jun, jul, august, sep, oct, nov, dec }; // starting with 1 is conventional
|
||||
enum class Month { jan = 1, feb, mar, apr, mar, jun,
|
||||
jul, august, sep, oct, nov, dec }; // starting with 1 is conventional
|
||||
enum class Base_flag { dec = 1, oct = dec << 1, hex = dec << 2 }; // set of bits
|
||||
|
||||
Specifying values are neccessary to match conventional values (e.g., `Month`)
|
||||
|
@ -9427,7 +9430,7 @@ Requires messy cast-and-macro-laden code to get working right.
|
|||
|
||||
va_end(ap); // arg cleanup (don't forget this)
|
||||
|
||||
cerr << '\en';
|
||||
cerr << '\n';
|
||||
if (severity) exit(severity);
|
||||
}
|
||||
|
||||
|
@ -9438,7 +9441,7 @@ Requires messy cast-and-macro-laden code to get working right.
|
|||
error(7, "this", "is", "an", "error"); // crash
|
||||
const char* is = "is";
|
||||
string an = "an";
|
||||
error(7,"this","is,an,"error"); // crash
|
||||
error(7, "this", "is", an, "error"); // crash
|
||||
}
|
||||
|
||||
**Alternative**: Overloading. Templates. Variadic templates.
|
||||
|
@ -13448,10 +13451,10 @@ To say "`T` is `Sortable`":
|
|||
// requires Sortable<T> // of type T which is the name of a type
|
||||
void sort(T&); // that is Sortable"
|
||||
|
||||
template<Sortable T> // Better (assuming language support for concepts): "The parameter is of type T
|
||||
template<Sortable T> // Better (assuming support for concepts): "The parameter is of type T
|
||||
void sort(T&); // which is Sortable"
|
||||
|
||||
void sort(Sortable&); // Best (assuming language support for concepts): "The parameter is Sortable"
|
||||
void sort(Sortable&); // Best (assuming support for concepts): "The parameter is Sortable"
|
||||
|
||||
The shorter versions better match the way we speak. Note that many templates don't need to use the `template` keyword.
|
||||
|
||||
|
@ -14221,7 +14224,8 @@ Eases tool creation.
|
|||
Iter algo(Iter first, Iter last) {
|
||||
for (; first != last; ++first) {
|
||||
auto x = sqrt(*first); // potentially surprising dependency: which sqrt()?
|
||||
helper(first,x); // potentially surprising dependency: heper is chosen based on first and x
|
||||
helper(first, x); // potentially surprising dependency:
|
||||
// helper is chosen based on first and x
|
||||
TT var = 7; // potentially surprising dependency: which TT?
|
||||
}
|
||||
}
|
||||
|
@ -14388,7 +14392,7 @@ This is a simplified version of `std::copy` (ignoring the possibility of non-con
|
|||
template<> struct copy_trait<int> { using tab = pod_tag; }; // int is "plain old data"
|
||||
|
||||
template<class Iter>
|
||||
Out copy_helper(Iter first, Iter last, Iter out, pog_tag)
|
||||
Out copy_helper(Iter first, Iter last, Iter out, pod_tag)
|
||||
{
|
||||
// use memmove
|
||||
}
|
||||
|
@ -14465,7 +14469,7 @@ When `concept`s become widely available such alternatives can be distinguished d
|
|||
auto x = T(u); // construction or cast?
|
||||
}
|
||||
|
||||
f(1,"asdf); // bad: cast from const char* to int
|
||||
f(1, "asdf"); // bad: cast from const char* to int
|
||||
|
||||
##### Enforcement
|
||||
|
||||
|
@ -14501,9 +14505,9 @@ There are three major ways to let calling code customize a template.
|
|||
template<class T>
|
||||
void test3(T t)
|
||||
// Invoke a "trait"
|
||||
|
||||
{
|
||||
test_traits<T>::f(t); // require customizing test_traits<> to get non-default functions/types
|
||||
test_traits<T>::f(t); // require customizing test_traits<>
|
||||
// to get non-default functions/types
|
||||
}
|
||||
|
||||
A trait is usually a type alias to compute a type,
|
||||
|
@ -14938,7 +14942,8 @@ Documentation, readability, opportunity for reuse.
|
|||
auto x = find_if(vr.begin(), vr.end(),
|
||||
[&](Rec& r) {
|
||||
if (r.name.size() != n.size()) return false; // name to compare to is in n
|
||||
for (int i=0; i<r.name.size(); ++i) if (tolower(r.name[i])!=tolower(n[i])) return false;
|
||||
for (int i=0; i < r.name.size(); ++i)
|
||||
if (tolower(r.name[i]) != tolower(n[i])) return false;
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue
Block a user