Skip to content

Commit 567331a

Browse files
authored
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.
1 parent c379d3f commit 567331a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

CppCoreGuidelines.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6550,7 +6550,7 @@ It's a standard-library requirement.
65506550
using result_type = size_t;
65516551
using argument_type = My_type;
65526552

6553-
size_t operator() (const My_type & x) const
6553+
size_t operator()(const My_type & x) const
65546554
{
65556555
size_t xs = x.s.size();
65566556
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
1452314523
void f() { std::cout << "Hello "; }
1452414524

1452514525
struct F {
14526-
void operator()() { std::cout << "parallel world "; }
14526+
void operator()() const { std::cout << "parallel world "; }
1452714527
};
1452814528

1452914529
int main()
@@ -14537,7 +14537,7 @@ It is harder to ensure absence of errors in detached threads (and potentially de
1453714537
void f() { std::cout << "Hello "; }
1453814538

1453914539
struct F {
14540-
void operator()() { std::cout << "parallel world "; }
14540+
void operator()() const { std::cout << "parallel world "; }
1454114541
};
1454214542

1454314543
int main()

0 commit comments

Comments
 (0)