diff options
| author | Marshall Clow <mclow.lists@gmail.com> | 2014-03-11 04:32:12 +0000 |
|---|---|---|
| committer | Marshall Clow <mclow.lists@gmail.com> | 2014-03-11 04:32:12 +0000 |
| commit | b33d838bcfb92fa85d7d9084131c3c5267021fee (patch) | |
| tree | 945a6f193b3baaf0a72e8e1b849f0187130094bb /libcxx/test/utilities/allocator.adaptor | |
| parent | e6f17d0cac2b746fa1a63bf209f37368e5f7f993 (diff) | |
| download | bcm5719-llvm-b33d838bcfb92fa85d7d9084131c3c5267021fee.tar.gz bcm5719-llvm-b33d838bcfb92fa85d7d9084131c3c5267021fee.zip | |
Final bit for LWG #2263; test different allocator pointer types. Note that libc++ already does the right thing here; I've just added tests to ensure that it stays this way.
llvm-svn: 203539
Diffstat (limited to 'libcxx/test/utilities/allocator.adaptor')
| -rw-r--r-- | libcxx/test/utilities/allocator.adaptor/allocator.adaptor.types/allocator_pointers.pass.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/libcxx/test/utilities/allocator.adaptor/allocator.adaptor.types/allocator_pointers.pass.cpp b/libcxx/test/utilities/allocator.adaptor/allocator.adaptor.types/allocator_pointers.pass.cpp new file mode 100644 index 00000000000..537fb90158b --- /dev/null +++ b/libcxx/test/utilities/allocator.adaptor/allocator.adaptor.types/allocator_pointers.pass.cpp @@ -0,0 +1,116 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <scoped_allocator> +#include <cassert> + +#if __cplusplus >= 201103L +// #include <memory> +// +// template <class Alloc> +// struct allocator_traits +// { +// typedef Alloc allocator_type; +// typedef typename allocator_type::value_type +// value_type; +// +// typedef Alloc::pointer | value_type* pointer; +// typedef Alloc::const_pointer +// | pointer_traits<pointer>::rebind<const value_type> +// const_pointer; +// typedef Alloc::void_pointer +// | pointer_traits<pointer>::rebind<void> +// void_pointer; +// typedef Alloc::const_void_pointer +// | pointer_traits<pointer>::rebind<const void> +// const_void_pointer; + +template <typename Alloc> +void test_pointer() +{ + typename std::allocator_traits<Alloc>::pointer vp; + typename std::allocator_traits<Alloc>::const_pointer cvp; + + static_assert(std::is_same<bool, decltype( vp == vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp != vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp > vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp >= vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp < vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp <= vp)>::value, ""); + + static_assert(std::is_same<bool, decltype( vp == cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp == vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp != cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp != vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp > cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp > vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp < cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp < vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, ""); + + static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp > cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp < cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, ""); +} + +template <typename Alloc> +void test_void_pointer() +{ + typename std::allocator_traits<Alloc>::void_pointer vp; + typename std::allocator_traits<Alloc>::const_void_pointer cvp; + + static_assert(std::is_same<bool, decltype( vp == vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp != vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp > vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp >= vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp < vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp <= vp)>::value, ""); + + static_assert(std::is_same<bool, decltype( vp == cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp == vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp != cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp != vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp > cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp > vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp < cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp < vp)>::value, ""); + static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, ""); + + static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp > cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp < cvp)>::value, ""); + static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, ""); +} + +struct Foo { int x; }; + +int main() +{ + test_pointer<std::scoped_allocator_adaptor<std::allocator<char>>> (); + test_pointer<std::scoped_allocator_adaptor<std::allocator<int>>> (); + test_pointer<std::scoped_allocator_adaptor<std::allocator<Foo>>> (); + + test_void_pointer<std::scoped_allocator_adaptor<std::allocator<char>>> (); + test_void_pointer<std::scoped_allocator_adaptor<std::allocator<int>>> (); + test_void_pointer<std::scoped_allocator_adaptor<std::allocator<Foo>>> (); +} +#else +int main() {} +#endif |

