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>
|
|
|
|
|
|
2010-08-22 00:47:54 +00:00
|
|
|
// template<class InputIterator>
|
|
|
|
|
// basic_string(InputIterator begin, InputIterator end,
|
2010-05-11 19:42:16 +00:00
|
|
|
// const Allocator& a = Allocator());
|
|
|
|
|
|
2018-02-08 06:34:03 +00:00
|
|
|
|
2010-05-11 19:42:16 +00:00
|
|
|
#include <string>
|
|
|
|
|
#include <iterator>
|
|
|
|
|
#include <cassert>
|
2016-12-06 01:12:34 +00:00
|
|
|
#include <cstddef>
|
2010-05-11 19:42:16 +00:00
|
|
|
|
2016-04-28 22:28:23 +00:00
|
|
|
#include "test_macros.h"
|
2013-12-03 00:18:10 +00:00
|
|
|
#include "test_allocator.h"
|
2010-05-11 19:42:16 +00:00
|
|
|
#include "../input_iterator.h"
|
2013-11-26 20:58:02 +00:00
|
|
|
#include "min_allocator.h"
|
2010-05-11 19:42:16 +00:00
|
|
|
|
|
|
|
|
template <class It>
|
|
|
|
|
void
|
|
|
|
|
test(It first, It last)
|
|
|
|
|
{
|
|
|
|
|
typedef typename std::iterator_traits<It>::value_type charT;
|
|
|
|
|
typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
|
|
|
|
|
typedef typename S::allocator_type A;
|
|
|
|
|
S s2(first, last);
|
2016-04-28 22:28:23 +00:00
|
|
|
LIBCPP_ASSERT(s2.__invariants());
|
2016-12-06 01:12:34 +00:00
|
|
|
assert(s2.size() == static_cast<std::size_t>(std::distance(first, last)));
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned i = 0;
|
|
|
|
|
for (It it = first; it != last; ++it, ++i)
|
|
|
|
|
assert(s2[i] == *it);
|
|
|
|
|
assert(s2.get_allocator() == A());
|
|
|
|
|
assert(s2.capacity() >= s2.size());
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 16:59:19 +00:00
|
|
|
template <class It, class A>
|
2010-05-11 19:42:16 +00:00
|
|
|
void
|
2013-06-28 16:59:19 +00:00
|
|
|
test(It first, It last, const A& a)
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
|
|
|
|
typedef typename std::iterator_traits<It>::value_type charT;
|
2013-06-28 16:59:19 +00:00
|
|
|
typedef std::basic_string<charT, std::char_traits<charT>, A> S;
|
2010-05-11 19:42:16 +00:00
|
|
|
S s2(first, last, a);
|
2016-04-28 22:28:23 +00:00
|
|
|
LIBCPP_ASSERT(s2.__invariants());
|
2016-12-06 01:12:34 +00:00
|
|
|
assert(s2.size() == static_cast<std::size_t>(std::distance(first, last)));
|
2010-05-11 19:42:16 +00:00
|
|
|
unsigned i = 0;
|
|
|
|
|
for (It it = first; it != last; ++it, ++i)
|
|
|
|
|
assert(s2[i] == *it);
|
|
|
|
|
assert(s2.get_allocator() == a);
|
|
|
|
|
assert(s2.capacity() >= s2.size());
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-04 20:31:13 +00:00
|
|
|
int main(int, char**)
|
2010-05-11 19:42:16 +00:00
|
|
|
{
|
2013-06-28 16:59:19 +00:00
|
|
|
{
|
2010-05-11 19:42:16 +00:00
|
|
|
typedef test_allocator<char> A;
|
|
|
|
|
const char* s = "12345678901234567890123456789012345678901234567890";
|
|
|
|
|
|
|
|
|
|
test(s, s);
|
|
|
|
|
test(s, s, A(2));
|
|
|
|
|
|
|
|
|
|
test(s, s+1);
|
|
|
|
|
test(s, s+1, A(2));
|
|
|
|
|
|
|
|
|
|
test(s, s+10);
|
|
|
|
|
test(s, s+10, A(2));
|
|
|
|
|
|
|
|
|
|
test(s, s+50);
|
|
|
|
|
test(s, s+50, A(2));
|
|
|
|
|
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s));
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s), A(2));
|
|
|
|
|
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s+1));
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s+1), A(2));
|
|
|
|
|
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s+10));
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s+10), A(2));
|
|
|
|
|
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s+50));
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s+50), A(2));
|
2013-06-28 16:59:19 +00:00
|
|
|
}
|
2016-04-28 22:28:23 +00:00
|
|
|
#if TEST_STD_VER >= 11
|
2013-06-28 16:59:19 +00:00
|
|
|
{
|
|
|
|
|
typedef min_allocator<char> A;
|
|
|
|
|
const char* s = "12345678901234567890123456789012345678901234567890";
|
|
|
|
|
|
|
|
|
|
test(s, s);
|
|
|
|
|
test(s, s, A());
|
|
|
|
|
|
|
|
|
|
test(s, s+1);
|
|
|
|
|
test(s, s+1, A());
|
|
|
|
|
|
|
|
|
|
test(s, s+10);
|
|
|
|
|
test(s, s+10, A());
|
|
|
|
|
|
|
|
|
|
test(s, s+50);
|
|
|
|
|
test(s, s+50, A());
|
|
|
|
|
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s));
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s), A());
|
|
|
|
|
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s+1));
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s+1), A());
|
|
|
|
|
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s+10));
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s+10), A());
|
|
|
|
|
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s+50));
|
|
|
|
|
test(input_iterator<const char*>(s), input_iterator<const char*>(s+50), A());
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2019-03-14 12:31:10 +00:00
|
|
|
{
|
|
|
|
|
static_assert((!std::is_constructible<std::string, std::string,
|
|
|
|
|
std::string>::value),
|
|
|
|
|
"");
|
|
|
|
|
static_assert(
|
|
|
|
|
(!std::is_constructible<std::string, std::string, std::string,
|
|
|
|
|
std::allocator<char> >::value),
|
|
|
|
|
"");
|
|
|
|
|
}
|
2019-02-04 20:31:13 +00:00
|
|
|
|
|
|
|
|
return 0;
|
2010-05-11 19:42:16 +00:00
|
|
|
}
|