uses_allocator_test.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2011-2013. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/container for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #include <boost/container/detail/config_begin.hpp>
  11. #include <boost/container/uses_allocator_fwd.hpp>
  12. #include <boost/container/uses_allocator.hpp>
  13. #include "propagation_test_allocator.hpp"
  14. struct not_uses_allocator
  15. {};
  16. struct uses_allocator_and_not_convertible_to_int
  17. {
  18. typedef uses_allocator_and_not_convertible_to_int allocator_type;
  19. };
  20. struct uses_allocator_and_convertible_to_int
  21. {
  22. typedef char allocator_type;
  23. };
  24. struct uses_erased_type_allocator
  25. {
  26. typedef boost::container::erased_type allocator_type;
  27. };
  28. int main()
  29. {
  30. using namespace boost::container;
  31. //Using dummy classes
  32. BOOST_STATIC_ASSERT(( false == uses_allocator
  33. < not_uses_allocator, int>::value ));
  34. BOOST_STATIC_ASSERT(( false == uses_allocator
  35. < uses_allocator_and_not_convertible_to_int, int>::value ));
  36. BOOST_STATIC_ASSERT(( true == uses_allocator
  37. < uses_allocator_and_convertible_to_int, int>::value ));
  38. BOOST_STATIC_ASSERT(( true == uses_allocator
  39. < uses_erased_type_allocator, int>::value ));
  40. //Using an allocator-like class
  41. BOOST_STATIC_ASSERT(( false == uses_allocator
  42. < allocator_argument_tester<NotUsesAllocator, 0>
  43. , propagation_test_allocator<float, 0>
  44. >::value ));
  45. BOOST_STATIC_ASSERT(( true == uses_allocator
  46. < allocator_argument_tester<ConstructiblePrefix, 0>
  47. , propagation_test_allocator<float, 0>
  48. >::value ));
  49. BOOST_STATIC_ASSERT(( true == uses_allocator
  50. < allocator_argument_tester<ConstructibleSuffix, 0>
  51. , propagation_test_allocator<float, 0>
  52. >::value ));
  53. BOOST_STATIC_ASSERT(( true == uses_allocator
  54. < allocator_argument_tester<ErasedTypeSuffix, 0>
  55. , propagation_test_allocator<float, 0>
  56. >::value ));
  57. BOOST_STATIC_ASSERT(( true == uses_allocator
  58. < allocator_argument_tester<ErasedTypePrefix, 0>
  59. , propagation_test_allocator<float, 0>
  60. >::value ));
  61. BOOST_STATIC_ASSERT(( true == constructible_with_allocator_prefix
  62. < allocator_argument_tester<ConstructiblePrefix, 0> >::value ));
  63. BOOST_STATIC_ASSERT(( true == constructible_with_allocator_suffix
  64. < allocator_argument_tester<ConstructibleSuffix, 0> >::value ));
  65. BOOST_STATIC_ASSERT(( true == constructible_with_allocator_prefix
  66. < allocator_argument_tester<ErasedTypePrefix, 0> >::value ));
  67. BOOST_STATIC_ASSERT(( true == constructible_with_allocator_suffix
  68. < allocator_argument_tester<ErasedTypeSuffix, 0> >::value ));
  69. return 0;
  70. }