Implement LWG#2583: There is no way to supply an allocator for basic_string(str, pos)

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@263036 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2016-03-09 17:51:43 +00:00
parent d7d1bda0f4
commit ff0b9f5749
3 changed files with 46 additions and 5 deletions

View File

@@ -11,14 +11,21 @@
// <string>
// basic_string(const basic_string<charT,traits,Allocator>& str,
// size_type pos, size_type n = npos,
// size_type pos, size_type n,
// const Allocator& a = Allocator());
//
// basic_string(const basic_string<charT,traits,Allocator>& str,
// size_type pos,
// const Allocator& a = Allocator());
#include <string>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <scoped_allocator>
#include <cassert>
#include "test_macros.h"
#include "test_allocator.h"
#include "min_allocator.h"
@@ -91,6 +98,20 @@ test(S str, unsigned pos, unsigned n, const typename S::allocator_type& a)
}
}
#if TEST_STD_VER >= 11
void test2583()
{ // LWG #2583
typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > StringA;
std::vector<StringA, std::scoped_allocator_adaptor<test_allocator<StringA>>> vs;
StringA s{"1234"};
vs.emplace_back(s, 2);
try { vs.emplace_back(s, 5); }
catch (const std::out_of_range&) { return; }
assert(false);
}
#endif
int main()
{
{
@@ -131,7 +152,7 @@ int main()
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 10, A(8));
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)), 50, 100, A(8));
}
#if __cplusplus >= 201103L
#if TEST_STD_VER >= 11
{
typedef min_allocator<char> A;
typedef std::basic_string<char, std::char_traits<char>, A> S;
@@ -170,5 +191,7 @@ int main()
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 10, A());
test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()), 50, 100, A());
}
test2583();
#endif
}