stl_concept_check.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // (C) Copyright Jeremy Siek 2000.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. // This file checks to see if various standard container
  7. // implementations live up to requirements specified in the C++
  8. // standard. As many implementations do not live to the requirements,
  9. // it is not uncommon for this file to fail to compile. The
  10. // BOOST_HIDE_EXPECTED_ERRORS macro is provided here if you want to
  11. // see as much of this file compile as possible.
  12. //
  13. #include <boost/concept_check.hpp>
  14. #include <iterator>
  15. #include <set>
  16. #include <map>
  17. #include <vector>
  18. #include <list>
  19. #include <deque>
  20. #if 0
  21. #include <slist>
  22. #endif
  23. // Define this macro if you want to hide the expected error, that is,
  24. // error in the various C++ standard library implementations.
  25. //
  26. //#define BOOST_HIDE_EXPECTED_ERRORS
  27. int
  28. main()
  29. {
  30. using namespace boost;
  31. #if defined(_ITERATOR_) && defined(BOOST_HIDE_EXPECTED_ERRORS)
  32. // VC++ STL implementation is not standard conformant and
  33. // fails to pass these concept checks
  34. #else
  35. typedef std::vector<int> Vector;
  36. typedef std::deque<int> Deque;
  37. typedef std::list<int> List;
  38. // VC++ missing pointer and const_pointer typedefs
  39. function_requires< Mutable_RandomAccessContainer<Vector> >();
  40. function_requires< BackInsertionSequence<Vector> >();
  41. #if !(defined(__GNUC__) && defined(BOOST_HIDE_EXPECTED_ERRORS))
  42. #if !((defined(__sgi) || (defined(__DECCXX) && defined(_RWSTD_VER) && _RWSTD_VER <= 0x0203)) \
  43. && defined(BOOST_HIDE_EXPECTED_ERRORS))
  44. // old deque iterator missing n + iter operation
  45. function_requires< Mutable_RandomAccessContainer<Deque> >();
  46. #endif
  47. // warnings about signed and unsigned in old deque version
  48. function_requires< FrontInsertionSequence<Deque> >();
  49. function_requires< BackInsertionSequence<Deque> >();
  50. #endif
  51. // VC++ missing pointer and const_pointer typedefs
  52. function_requires< Mutable_ReversibleContainer<List> >();
  53. function_requires< FrontInsertionSequence<List> >();
  54. function_requires< BackInsertionSequence<List> >();
  55. #if 0
  56. typedef BOOST_STD_EXTENSION_NAMESPACE::slist<int> SList;
  57. function_requires< FrontInsertionSequence<SList> >();
  58. #endif
  59. typedef std::set<int> Set;
  60. typedef std::multiset<int> MultiSet;
  61. typedef std::map<int,int> Map;
  62. typedef std::multimap<int,int> MultiMap;
  63. function_requires< SortedAssociativeContainer<Set> >();
  64. function_requires< SimpleAssociativeContainer<Set> >();
  65. function_requires< UniqueAssociativeContainer<Set> >();
  66. function_requires< SortedAssociativeContainer<MultiSet> >();
  67. function_requires< SimpleAssociativeContainer<MultiSet> >();
  68. function_requires< MultipleAssociativeContainer<MultiSet> >();
  69. function_requires< SortedAssociativeContainer<Map> >();
  70. function_requires< UniqueAssociativeContainer<Map> >();
  71. function_requires< PairAssociativeContainer<Map> >();
  72. function_requires< SortedAssociativeContainer<MultiMap> >();
  73. function_requires< MultipleAssociativeContainer<MultiMap> >();
  74. function_requires< PairAssociativeContainer<MultiMap> >();
  75. #endif
  76. return 0;
  77. }