2010-05-11 19:42:16 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
//
|
2019-01-19 10:56:40 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-05-11 19:42:16 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
// <string>
|
|
|
|
|
|
|
|
|
|
// explicit basic_string(const Allocator& a = Allocator());
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
2015-06-03 19:56:43 +00:00
|
|
|
#include "test_macros.h"
|
2013-12-03 00:18:10 +00:00
|
|
|
#include "test_allocator.h"
|
2013-11-26 20:58:02 +00:00
|
|
|
#include "min_allocator.h"
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
|
template <class S>
|
|
|
|
|
void
|
|
|
|
|
test()
|
|
|
|
|
{
|
|
|
|
|
{
|
2015-06-03 19:56:43 +00:00
|
|
|
#if TEST_STD_VER > 14
|
2017-07-29 00:55:10 +00:00
|
|
|
static_assert((noexcept(S{})), "" );
|
2015-06-03 19:56:43 +00:00
|
|
|
#elif TEST_STD_VER >= 11
|
2017-07-29 00:55:10 +00:00
|
|
|
static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
|
2015-06-03 19:56:43 +00:00
|
|
|
#endif
|
2010-05-11 19:42:16 +00:00
|
|
|
S s;
|
2016-04-28 22:28:23 +00:00
|
|
|
LIBCPP_ASSERT(s.__invariants());
|
2010-05-11 19:42:16 +00:00
|
|
|
assert(s.data());
|
|
|
|
|
assert(s.size() == 0);
|
|
|
|
|
assert(s.capacity() >= s.size());
|
|
|
|
|
assert(s.get_allocator() == typename S::allocator_type());
|
|
|
|
|
}
|
|
|
|
|
{
|
2015-06-03 19:56:43 +00:00
|
|
|
#if TEST_STD_VER > 14
|
2017-07-29 00:55:10 +00:00
|
|
|
static_assert((noexcept(S{typename S::allocator_type{}})), "" );
|
2015-06-03 19:56:43 +00:00
|
|
|
#elif TEST_STD_VER >= 11
|
2017-07-29 00:55:10 +00:00
|
|
|
static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
|
2015-06-03 19:56:43 +00:00
|
|
|
#endif
|
2010-05-11 19:42:16 +00:00
|
|
|
S s(typename S::allocator_type(5));
|
2016-04-28 22:28:23 +00:00
|
|
|
LIBCPP_ASSERT(s.__invariants());
|
2010-05-11 19:42:16 +00:00
|
|
|
assert(s.data());
|
|
|
|
|
assert(s.size() == 0);
|
|
|
|
|
assert(s.capacity() >= s.size());
|
|
|
|
|
assert(s.get_allocator() == typename S::allocator_type(5));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-03 19:56:43 +00:00
|
|
|
#if TEST_STD_VER >= 11
|
2013-06-28 16:59:19 +00:00
|
|
|
|
|
|
|
|
template <class S>
|
|
|
|
|
void
|
|
|
|
|
test2()
|
|
|
|
|
{
|
|
|
|
|
{
|
2015-06-03 19:56:43 +00:00
|
|
|
#if TEST_STD_VER > 14
|
2017-07-29 00:55:10 +00:00
|
|
|
static_assert((noexcept(S{})), "" );
|
2015-06-03 19:56:43 +00:00
|
|
|
#elif TEST_STD_VER >= 11
|
2017-07-29 00:55:10 +00:00
|
|
|
static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
|
2015-06-03 19:56:43 +00:00
|
|
|
#endif
|
2013-06-28 16:59:19 +00:00
|
|
|
S s;
|
2016-04-28 22:28:23 +00:00
|
|
|
LIBCPP_ASSERT(s.__invariants());
|
2013-06-28 16:59:19 +00:00
|
|
|
assert(s.data());
|
|
|
|
|
assert(s.size() == 0);
|
|
|
|
|
assert(s.capacity() >= s.size());
|
|
|
|
|
assert(s.get_allocator() == typename S::allocator_type());
|
|
|
|
|
}
|
|
|
|
|
{
|
2015-06-03 19:56:43 +00:00
|
|
|
#if TEST_STD_VER > 14
|
2017-07-29 00:55:10 +00:00
|
|
|
static_assert((noexcept(S{typename S::allocator_type{}})), "" );
|
2015-06-03 19:56:43 +00:00
|
|
|
#elif TEST_STD_VER >= 11
|
2017-07-29 00:55:10 +00:00
|
|
|
static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
|
2015-06-03 19:56:43 +00:00
|
|
|
#endif
|
2013-06-28 16:59:19 +00:00
|
|
|
S s(typename S::allocator_type{});
|
2016-04-28 22:28:23 +00:00
|
|
|
LIBCPP_ASSERT(s.__invariants());
|
2013-06-28 16:59:19 +00:00
|
|
|
assert(s.data());
|
|
|
|
|
assert(s.size() == 0);
|
|
|
|
|
assert(s.capacity() >= s.size());
|
|
|
|
|
assert(s.get_allocator() == typename S::allocator_type());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-02-04 20:31:13 +00:00
|
|
|
int main(int, char**)
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
|
test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >();
|
2015-06-03 19:56:43 +00:00
|
|
|
#if TEST_STD_VER >= 11
|
2013-06-28 16:59:19 +00:00
|
|
|
test2<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
|
2016-08-17 05:58:40 +00:00
|
|
|
test2<std::basic_string<char, std::char_traits<char>, explicit_allocator<char> > >();
|
2013-06-28 16:59:19 +00:00
|
|
|
#endif
|
2019-02-04 20:31:13 +00:00
|
|
|
|
|
|
|
|
return 0;
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|