mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 12:44:42 +03:00
Const-qualify operator()s. NFC. (#1638)
As a general rule, `operator()` should be const-qualified. The exceptions are few and far between. I was actually looking for a Guideline on that subject; I grepped for `operator()` and found that not only is there no such Guideline yet, the doc actually contained these places that (needlessly) violated the general rule.
This commit is contained in:
@@ -6550,7 +6550,7 @@ It's a standard-library requirement.
|
|||||||
using result_type = size_t;
|
using result_type = size_t;
|
||||||
using argument_type = My_type;
|
using argument_type = My_type;
|
||||||
|
|
||||||
size_t operator() (const My_type & x) const
|
size_t operator()(const My_type & x) const
|
||||||
{
|
{
|
||||||
size_t xs = x.s.size();
|
size_t xs = x.s.size();
|
||||||
if (xs < 4) throw Bad_My_type{}; // "Nobody expects the Spanish inquisition!"
|
if (xs < 4) throw Bad_My_type{}; // "Nobody expects the Spanish inquisition!"
|
||||||
@@ -14523,7 +14523,7 @@ It is harder to ensure absence of errors in detached threads (and potentially de
|
|||||||
void f() { std::cout << "Hello "; }
|
void f() { std::cout << "Hello "; }
|
||||||
|
|
||||||
struct F {
|
struct F {
|
||||||
void operator()() { std::cout << "parallel world "; }
|
void operator()() const { std::cout << "parallel world "; }
|
||||||
};
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@@ -14537,7 +14537,7 @@ It is harder to ensure absence of errors in detached threads (and potentially de
|
|||||||
void f() { std::cout << "Hello "; }
|
void f() { std::cout << "Hello "; }
|
||||||
|
|
||||||
struct F {
|
struct F {
|
||||||
void operator()() { std::cout << "parallel world "; }
|
void operator()() const { std::cout << "parallel world "; }
|
||||||
};
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|||||||
Reference in New Issue
Block a user