Mention suppression in stylecheck error + document in style guide

This commit is contained in:
Robert Schulze 2022-05-06 09:04:04 +02:00
parent 1789fb4b98
commit ef0d9ca468
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A
2 changed files with 48 additions and 2 deletions

View File

@ -694,6 +694,51 @@ auto s = std::string{"Hello"};
**2.** Exception specifiers from C++03 are not used.
**3.** Constructs which have convenient syntactic sugar in modern C++, e.g.
```
// "Traditional" C++
template <typename G, typename = std::enable_if_t<std::is_same<G, F>::value, void>> // SFINAE via std::enable_if, usage of ::value
std::pair<int, int> func(const E<G> & e) // explicitly specified return type
{
if (elements.count(e)) // .count() membership test
{
// ...
}
elements.erase(
std::remove_if(
elements.begin(), elements.end(),
[&](const auto x){
return x == 1;
}),
elements.end()); // remove-erase idiom
return std::make_pair(1, 2); // create pair via make_pair()
}
// C++14/17/20
template <typename G>
requires std::same_v<G, F> // SFINAE via C++20 concept, usage of C++14 template alias
auto func(const E<G> & e) // auto return type (C++14)
{
if (elements.contains(e)) // C++20 .contains membership test
{
// ...
}
elements.erase_if(
elements,
[&](const auto x){
return x == 1;
}); // C++20 std::erase_if
return {1, 2}; // or: return std::pair(1, 2); // create pair via initialization list or value initialization (C++17)
}
```
## Platform {#platform}
**1.** We write code for a specific platform.

View File

@ -228,8 +228,9 @@ find $ROOT_PATH -name '.gitmodules' | while read i; do grep -F 'url = ' $i | gre
# There shouldn't be any code snippets under GPL or LGPL
find $ROOT_PATH/{src,base,programs} -name '*.h' -or -name '*.cpp' 2>/dev/null | xargs grep -i -F 'General Public License' && echo "There shouldn't be any code snippets under GPL or LGPL"
# std::make_tuple/pair was superseded by std::pair/tuple, use "// NOLINT(style-check-make-pair-tuple)" to suppress the check
find $ROOT_PATH/{src,base,programs} -name '*.h' -or -name '*.cpp' 2>/dev/null | xargs grep -P 'std::make_(pair|tuple).*(?<!NOLINT\(style-check-make-pair-tuple\))$' && echo "std::make_pair/make_tuple should be replaced by std::pair/tuple"
# std::make_tuple/pair was superseded by std::pair/tuple
find $ROOT_PATH/{src,base,programs} -name '*.h' -or -name '*.cpp' 2>/dev/null | xargs grep -P
'std::make_(pair|tuple).*(?<!NOLINT\(style-check-make-pair-tuple\))$' && echo "std::make_pair/make_tuple should be replaced by std::pair/tuple, use // NOLINT(style-check-make-pair-tuple) to suppress the check"
# There shouldn't be any docker containers outside docker directory
find $ROOT_PATH -not -path $ROOT_PATH'/tests/ci*' -not -path $ROOT_PATH'/docker*' -not -path $ROOT_PATH'/contrib*' -name Dockerfile -type f 2>/dev/null | xargs --no-run-if-empty -n1 echo "Please move Dockerfile to docker directory:"