boost_no_std_allocator.ipp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // (C) Copyright John Maddock 2001.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/config for the most recent version.
  6. // MACRO: BOOST_NO_STD_ALLOCATOR
  7. // TITLE: std::allocator
  8. // DESCRIPTION: The C++ standard library does not provide
  9. // a standards conforming std::allocator.
  10. #ifndef BOOST_NESTED_TEMPLATE
  11. #define BOOST_NESTED_TEMPLATE template
  12. #endif
  13. #include <memory>
  14. namespace boost_no_std_allocator{
  15. #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
  16. # define BOOST_UNUSED_ATTRIBUTE __attribute__((unused))
  17. #else
  18. # define BOOST_UNUSED_ATTRIBUTE
  19. #endif
  20. template <class T>
  21. int test_allocator(const T& i)
  22. {
  23. typedef std::allocator<int> alloc1_t;
  24. #if !((__cplusplus > 201700) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201700)))
  25. // stuff deprecated in C++17:
  26. typedef typename alloc1_t::size_type size_type;
  27. typedef typename alloc1_t::difference_type difference_type BOOST_UNUSED_ATTRIBUTE;
  28. typedef typename alloc1_t::pointer pointer;
  29. typedef typename alloc1_t::const_pointer const_pointer;
  30. typedef typename alloc1_t::reference reference;
  31. typedef typename alloc1_t::const_reference const_reference;
  32. #endif
  33. typedef typename alloc1_t::value_type value_type BOOST_UNUSED_ATTRIBUTE;
  34. alloc1_t a1;
  35. alloc1_t a2(a1);
  36. (void)i;
  37. #if !((__cplusplus > 201700) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201700)))
  38. // stuff deprecated in C++17:
  39. typedef typename alloc1_t::BOOST_NESTED_TEMPLATE rebind<double> binder_t;
  40. typedef typename binder_t::other alloc2_t;
  41. alloc2_t a3(a1);
  42. // this chokes early versions of the MSL library
  43. // and isn't currently required by anything in boost
  44. // so don't test for now...
  45. // a3 = a2;
  46. (void)a2;
  47. #endif
  48. #if !((__cplusplus > 201700) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201700)))
  49. pointer p = a1.allocate(1);
  50. const_pointer cp = p;
  51. a1.construct(p,i);
  52. size_type s = a1.max_size();
  53. (void)s;
  54. reference r = *p;
  55. const_reference cr = *cp;
  56. if(p != a1.address(r)) return -1;
  57. if(cp != a1.address(cr)) return -1;
  58. a1.destroy(p);
  59. #else
  60. auto p = a1.allocate(1);
  61. #endif
  62. a1.deallocate(p,1);
  63. return 0;
  64. }
  65. int test()
  66. {
  67. return test_allocator(0);
  68. }
  69. }
  70. #undef BOOST_UNUSED_ATTRIBUTE