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