15a83710eSEric Fiselier //===----------------------------------------------------------------------===// 25a83710eSEric Fiselier // 357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 65a83710eSEric Fiselier // 75a83710eSEric Fiselier //===----------------------------------------------------------------------===// 85a83710eSEric Fiselier 95a83710eSEric Fiselier // <sstream> 105a83710eSEric Fiselier 115a83710eSEric Fiselier // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 125a83710eSEric Fiselier // class basic_stringstream 135a83710eSEric Fiselier 145a83710eSEric Fiselier // explicit basic_stringstream(const basic_string<charT,traits,Allocator>& str, 155a83710eSEric Fiselier // ios_base::openmode which = ios_base::out|ios_base::in); 165a83710eSEric Fiselier 175a83710eSEric Fiselier #include <sstream> 185a83710eSEric Fiselier #include <cassert> 195a83710eSEric Fiselier 20a054f828SMarshall Clow template<typename T> 21a054f828SMarshall Clow struct NoDefaultAllocator : std::allocator<T> 22a054f828SMarshall Clow { 23a054f828SMarshall Clow template<typename U> struct rebind { using other = NoDefaultAllocator<U>; }; 244f4fc2eaSMarshall Clow NoDefaultAllocator(int id_) : id(id_) { } 25a054f828SMarshall Clow template<typename U> NoDefaultAllocator(const NoDefaultAllocator<U>& a) : id(a.id) { } 26a054f828SMarshall Clow int id; 27a054f828SMarshall Clow }; 28a054f828SMarshall Clow 29a054f828SMarshall Clow 30*2df59c50SJF Bastien int main(int, char**) 315a83710eSEric Fiselier { 325a83710eSEric Fiselier { 335a83710eSEric Fiselier std::stringstream ss(" 123 456 "); 345a83710eSEric Fiselier assert(ss.rdbuf() != 0); 355a83710eSEric Fiselier assert(ss.good()); 365a83710eSEric Fiselier assert(ss.str() == " 123 456 "); 375a83710eSEric Fiselier int i = 0; 385a83710eSEric Fiselier ss >> i; 395a83710eSEric Fiselier assert(i == 123); 405a83710eSEric Fiselier ss >> i; 415a83710eSEric Fiselier assert(i == 456); 425a83710eSEric Fiselier ss << i << ' ' << 123; 435a83710eSEric Fiselier assert(ss.str() == "456 1236 "); 445a83710eSEric Fiselier } 455a83710eSEric Fiselier { 465a83710eSEric Fiselier std::wstringstream ss(L" 123 456 "); 475a83710eSEric Fiselier assert(ss.rdbuf() != 0); 485a83710eSEric Fiselier assert(ss.good()); 495a83710eSEric Fiselier assert(ss.str() == L" 123 456 "); 505a83710eSEric Fiselier int i = 0; 515a83710eSEric Fiselier ss >> i; 525a83710eSEric Fiselier assert(i == 123); 535a83710eSEric Fiselier ss >> i; 545a83710eSEric Fiselier assert(i == 456); 555a83710eSEric Fiselier ss << i << ' ' << 123; 565a83710eSEric Fiselier assert(ss.str() == L"456 1236 "); 575a83710eSEric Fiselier } 58a054f828SMarshall Clow { // This is https://bugs.llvm.org/show_bug.cgi?id=33727 59a054f828SMarshall Clow typedef std::basic_string <char, std::char_traits<char>, NoDefaultAllocator<char> > S; 60a054f828SMarshall Clow typedef std::basic_stringbuf<char, std::char_traits<char>, NoDefaultAllocator<char> > SB; 61a054f828SMarshall Clow 62a054f828SMarshall Clow S s(NoDefaultAllocator<char>(1)); 63a054f828SMarshall Clow SB sb(s); 64a054f828SMarshall Clow // This test is not required by the standard, but *where else* could it get the allocator? 65a054f828SMarshall Clow assert(sb.str().get_allocator() == s.get_allocator()); 66a054f828SMarshall Clow } 67*2df59c50SJF Bastien 68*2df59c50SJF Bastien return 0; 695a83710eSEric Fiselier } 70