Advertisement
Guest User

Untitled

a guest
Feb 16th, 2015
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. $ cat q.cc                                                                                                                                                                                                          
  2. #include <algorithm>
  3. #include <set>
  4.  
  5. struct Value { int value; };
  6. struct Ordering {
  7.   bool operator()(const Value& lhs, const Value& rhs) const {
  8.     return lhs.value < rhs.value;
  9.   }
  10.   bool operator()(int lhs, const Value& rhs) const {
  11.     return lhs < rhs.value;
  12.   }
  13. };
  14.  
  15. void f(std::set<Value, Ordering> container, int value) {
  16.   std::upper_bound(container.begin(), container.end(), value, Ordering());
  17. }
  18. $ clang-tidy q.cc -fix --
  19. 1093 warnings generated.
  20. q.cc:15:3: warning: this STL algorithm call should be replaced with a container method [misc-inefficient-algorithm]
  21.   std::upper_bound(container.begin(), container.end(), value, Ordering());
  22.   ^
  23.   container.upper_bound(value)
  24. q.cc:15:3: note: FIX-IT applied suggested code changes
  25.   std::upper_bound(container.begin(), container.end(), value, Ordering());
  26.   ^
  27. clang-tidy applied 1 of 1 suggested fixes.
  28. Suppressed 1092 warnings (1092 in non-user code).
  29. Use -header-filter='.*' to display errors from all non-system headers.
  30. $ cat q.cc
  31. #include <algorithm>
  32. #include <set>
  33.  
  34. struct Value { int value; };
  35. struct Ordering {
  36.   bool operator()(const Value& lhs, const Value& rhs) const {
  37.     return lhs.value < rhs.value;
  38.   }
  39.   bool operator()(int lhs, const Value& rhs) const {
  40.     return lhs < rhs.value;
  41.   }
  42. };
  43.  
  44. void f(std::set<Value, Ordering> container, int value) {
  45.   container.upper_bound(value);
  46. }
  47. $ clang-tidy q.cc --
  48. 1079 warnings and 1 error generated.
  49. Error while processing q.cc.
  50. q.cc:15:13: error: no matching member function for call to 'upper_bound' [clang-diagnostic-error]
  51.   container.upper_bound(value);
  52.             ^
  53. /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
  54.       upper_bound(const key_type& __x)
  55.       ^
  56. /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
  57.       upper_bound(const key_type& __x) const
  58.       ^
  59. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement