concept_checks.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // 2001-12-28 Phil Edwards <pme@gcc.gnu.org>
  2. //
  3. // Copyright (C) 2001-2022 Free Software Foundation, Inc.
  4. //
  5. // This file is part of the GNU ISO C++ Library. This library is free
  6. // software; you can redistribute it and/or modify it under the
  7. // terms of the GNU General Public License as published by the
  8. // Free Software Foundation; either version 3, or (at your option)
  9. // any later version.
  10. //
  11. // This library is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License along
  17. // with this library; see the file COPYING3. If not see
  18. // <http://www.gnu.org/licenses/>.
  19. // Concept checking must remain sane.
  20. // { dg-options "-D_GLIBCXX_CONCEPT_CHECKS" }
  21. #include <vector>
  22. #include <string>
  23. #include <algorithm>
  24. #include <testsuite_hooks.h>
  25. using namespace std;
  26. // PR libstdc++/2054 and follow-up discussion
  27. struct indirectCompare
  28. {
  29. indirectCompare(const vector<string>& v) : V(v) {}
  30. bool operator()( int x, int y) const
  31. {
  32. return V[x] < V[y];
  33. }
  34. bool operator()( int x, const string& a) const
  35. {
  36. return V[x] < a;
  37. }
  38. bool operator()( const string& a, int x) const
  39. {
  40. return V[x] < a;
  41. }
  42. const vector<string>& V;
  43. };
  44. void
  45. test2054( )
  46. {
  47. const int Maxi = 1022;
  48. vector<string> Words(Maxi);
  49. vector<int> Index(Maxi);
  50. for(size_t i = 0; i < Index.size(); i++)
  51. Index[i] = i;
  52. indirectCompare aComparison(Words);
  53. sort(Index.begin(), Index.end(), aComparison);
  54. string SearchTerm;
  55. lower_bound(Index.begin(), Index.end(), SearchTerm, aComparison);
  56. upper_bound(Index.begin(), Index.end(), SearchTerm, aComparison);
  57. equal_range(Index.begin(), Index.end(), SearchTerm, aComparison);
  58. binary_search(Index.begin(), Index.end(), SearchTerm, aComparison);
  59. }
  60. int main()
  61. {
  62. test2054();
  63. return 0;
  64. }