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 most recent version. 7 8// MACRO: BOOST_HAS_PARTIAL_STD_ALLOCATOR 9// TITLE: limited std::allocator support 10// DESCRIPTION: The std lib has at least some kind of stanfard allocator 11// with allocate/deallocate members and probably not much more. 12 13#include <memory> 14 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 21namespace boost_has_partial_std_allocator{ 22 23// 24// test everything except rebind template members: 25// 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 typedef typename alloc1_t::size_type size_type; 33 typedef typename alloc1_t::difference_type difference_type BOOST_UNUSED_ATTRIBUTE; 34 typedef typename alloc1_t::pointer pointer; 35 typedef typename alloc1_t::const_pointer const_pointer; 36 typedef typename alloc1_t::reference reference; 37 typedef typename alloc1_t::const_reference const_reference; 38 typedef typename alloc1_t::value_type value_type BOOST_UNUSED_ATTRIBUTE; 39#endif 40 alloc1_t a1; 41 (void)i; 42#if !((__cplusplus > 201700) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201700))) 43 pointer p = a1.allocate(1); 44 const_pointer cp = p; 45 a1.construct(p,i); 46 size_type s = a1.max_size(); 47 (void)s; 48 reference r = *p; 49 const_reference cr = *cp; 50 if(p != a1.address(r)) return -1; 51 if(cp != a1.address(cr)) return -1; 52 a1.destroy(p); 53 a1.deallocate(p,1); 54#endif 55 return 0; 56} 57 58 59int test() 60{ 61 return test_allocator(0); 62} 63 64} 65 66#undef BOOST_UNUSED_ATTRIBUTE 67 68