diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-09-06 18:46:46 +0000 |
commit | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (patch) | |
tree | ec41ed70ffca97240e76f9a78bb2dedba28f310c /test/std/strings/basic.string/string.cons/alloc.pass.cpp | |
parent | f857581820d15e410e9945d2fcd5f7163be25a96 (diff) |
Notes
Diffstat (limited to 'test/std/strings/basic.string/string.cons/alloc.pass.cpp')
-rw-r--r-- | test/std/strings/basic.string/string.cons/alloc.pass.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/test/std/strings/basic.string/string.cons/alloc.pass.cpp b/test/std/strings/basic.string/string.cons/alloc.pass.cpp new file mode 100644 index 0000000000000..1c4f2044834e5 --- /dev/null +++ b/test/std/strings/basic.string/string.cons/alloc.pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// <string> + +// explicit basic_string(const Allocator& a = Allocator()); + +#include <string> +#include <cassert> + +#include "test_macros.h" +#include "test_allocator.h" +#include "min_allocator.h" + +template <class S> +void +test() +{ + { +#if TEST_STD_VER > 14 + static_assert((noexcept(S{})), "" ); +#elif TEST_STD_VER >= 11 + static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" ); +#endif + S s; + assert(s.__invariants()); + assert(s.data()); + assert(s.size() == 0); + assert(s.capacity() >= s.size()); + assert(s.get_allocator() == typename S::allocator_type()); + } + { +#if TEST_STD_VER > 14 + static_assert((noexcept(S{typename S::allocator_type{}})), "" ); +#elif TEST_STD_VER >= 11 + static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" ); +#endif + S s(typename S::allocator_type(5)); + assert(s.__invariants()); + assert(s.data()); + assert(s.size() == 0); + assert(s.capacity() >= s.size()); + assert(s.get_allocator() == typename S::allocator_type(5)); + } +} + +#if TEST_STD_VER >= 11 + +template <class S> +void +test2() +{ + { +#if TEST_STD_VER > 14 + static_assert((noexcept(S{})), "" ); +#elif TEST_STD_VER >= 11 + static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" ); +#endif + S s; + assert(s.__invariants()); + assert(s.data()); + assert(s.size() == 0); + assert(s.capacity() >= s.size()); + assert(s.get_allocator() == typename S::allocator_type()); + } + { +#if TEST_STD_VER > 14 + static_assert((noexcept(S{typename S::allocator_type{}})), "" ); +#elif TEST_STD_VER >= 11 + static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" ); +#endif + S s(typename S::allocator_type{}); + assert(s.__invariants()); + assert(s.data()); + assert(s.size() == 0); + assert(s.capacity() >= s.size()); + assert(s.get_allocator() == typename S::allocator_type()); + } +} + +#endif + +int main() +{ + test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >(); +#if TEST_STD_VER >= 11 + test2<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >(); +#endif +} |