Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ cat q.cc
- #include <algorithm>
- #include <set>
- struct Value { int value; };
- struct Ordering {
- bool operator()(const Value& lhs, const Value& rhs) const {
- return lhs.value < rhs.value;
- }
- bool operator()(int lhs, const Value& rhs) const {
- return lhs < rhs.value;
- }
- };
- void f(std::set<Value, Ordering> container, int value) {
- std::upper_bound(container.begin(), container.end(), value, Ordering());
- }
- $ clang-tidy q.cc -fix --
- 1093 warnings generated.
- q.cc:15:3: warning: this STL algorithm call should be replaced with a container method [misc-inefficient-algorithm]
- std::upper_bound(container.begin(), container.end(), value, Ordering());
- ^
- container.upper_bound(value)
- q.cc:15:3: note: FIX-IT applied suggested code changes
- std::upper_bound(container.begin(), container.end(), value, Ordering());
- ^
- clang-tidy applied 1 of 1 suggested fixes.
- Suppressed 1092 warnings (1092 in non-user code).
- Use -header-filter='.*' to display errors from all non-system headers.
- $ cat q.cc
- #include <algorithm>
- #include <set>
- struct Value { int value; };
- struct Ordering {
- bool operator()(const Value& lhs, const Value& rhs) const {
- return lhs.value < rhs.value;
- }
- bool operator()(int lhs, const Value& rhs) const {
- return lhs < rhs.value;
- }
- };
- void f(std::set<Value, Ordering> container, int value) {
- container.upper_bound(value);
- }
- $ clang-tidy q.cc --
- 1079 warnings and 1 error generated.
- Error while processing q.cc.
- q.cc:15:13: error: no matching member function for call to 'upper_bound' [clang-diagnostic-error]
- container.upper_bound(value);
- ^
- /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_set.h:699:7: note: candidate function not viable: no known conversion from 'int' to 'const key_type' (aka 'const Value') for 1st argument
- upper_bound(const key_type& __x)
- ^
- /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_set.h:703:7: note: candidate function not viable: no known conversion from 'int' to 'const key_type' (aka 'const Value') for 1st argument
- upper_bound(const key_type& __x) const
- ^
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement