boost_has_part_alloc.ipp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 most recent version.
  6. // MACRO: BOOST_HAS_PARTIAL_STD_ALLOCATOR
  7. // TITLE: limited std::allocator support
  8. // DESCRIPTION: The std lib has at least some kind of stanfard allocator
  9. // with allocate/deallocate members and probably not much more.
  10. #include <memory>
  11. #if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
  12. # define BOOST_UNUSED_ATTRIBUTE __attribute__((unused))
  13. #else
  14. # define BOOST_UNUSED_ATTRIBUTE
  15. #endif
  16. namespace boost_has_partial_std_allocator{
  17. //
  18. // test everything except rebind template members:
  19. //
  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. typedef typename alloc1_t::size_type size_type;
  26. typedef typename alloc1_t::difference_type difference_type BOOST_UNUSED_ATTRIBUTE;
  27. typedef typename alloc1_t::pointer pointer;
  28. typedef typename alloc1_t::const_pointer const_pointer;
  29. typedef typename alloc1_t::reference reference;
  30. typedef typename alloc1_t::const_reference const_reference;
  31. typedef typename alloc1_t::value_type value_type BOOST_UNUSED_ATTRIBUTE;
  32. #endif
  33. alloc1_t a1;
  34. (void)i;
  35. #if !((__cplusplus > 201700) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201700)))
  36. pointer p = a1.allocate(1);
  37. const_pointer cp = p;
  38. a1.construct(p,i);
  39. size_type s = a1.max_size();
  40. (void)s;
  41. reference r = *p;
  42. const_reference cr = *cp;
  43. if(p != a1.address(r)) return -1;
  44. if(cp != a1.address(cr)) return -1;
  45. a1.destroy(p);
  46. a1.deallocate(p,1);
  47. #endif
  48. return 0;
  49. }
  50. int test()
  51. {
  52. return test_allocator(0);
  53. }
  54. }
  55. #undef BOOST_UNUSED_ATTRIBUTE