15a83710eSEric Fiselier //===----------------------------------------------------------------------===// 25a83710eSEric Fiselier // 35a83710eSEric Fiselier // The LLVM Compiler Infrastructure 45a83710eSEric Fiselier // 55a83710eSEric Fiselier // This file is dual licensed under the MIT and the University of Illinois Open 65a83710eSEric Fiselier // Source Licenses. See LICENSE.TXT for details. 75a83710eSEric Fiselier // 85a83710eSEric Fiselier //===----------------------------------------------------------------------===// 95a83710eSEric Fiselier 105a83710eSEric Fiselier // <sstream> 115a83710eSEric Fiselier 125a83710eSEric Fiselier // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > 135a83710eSEric Fiselier // class basic_stringstream 145a83710eSEric Fiselier 155a83710eSEric Fiselier // explicit basic_stringstream(const basic_string<charT,traits,Allocator>& str, 165a83710eSEric Fiselier // ios_base::openmode which = ios_base::out|ios_base::in); 175a83710eSEric Fiselier 185a83710eSEric Fiselier #include <sstream> 195a83710eSEric Fiselier #include <cassert> 205a83710eSEric Fiselier 21a054f828SMarshall Clow template<typename T> 22a054f828SMarshall Clow struct NoDefaultAllocator : std::allocator<T> 23a054f828SMarshall Clow { 24a054f828SMarshall Clow template<typename U> struct rebind { using other = NoDefaultAllocator<U>; }; 25*4f4fc2eaSMarshall Clow NoDefaultAllocator(int id_) : id(id_) { } 26a054f828SMarshall Clow template<typename U> NoDefaultAllocator(const NoDefaultAllocator<U>& a) : id(a.id) { } 27a054f828SMarshall Clow int id; 28a054f828SMarshall Clow }; 29a054f828SMarshall Clow 30a054f828SMarshall Clow 315a83710eSEric Fiselier int main() 325a83710eSEric Fiselier { 335a83710eSEric Fiselier { 345a83710eSEric Fiselier std::stringstream ss(" 123 456 "); 355a83710eSEric Fiselier assert(ss.rdbuf() != 0); 365a83710eSEric Fiselier assert(ss.good()); 375a83710eSEric Fiselier assert(ss.str() == " 123 456 "); 385a83710eSEric Fiselier int i = 0; 395a83710eSEric Fiselier ss >> i; 405a83710eSEric Fiselier assert(i == 123); 415a83710eSEric Fiselier ss >> i; 425a83710eSEric Fiselier assert(i == 456); 435a83710eSEric Fiselier ss << i << ' ' << 123; 445a83710eSEric Fiselier assert(ss.str() == "456 1236 "); 455a83710eSEric Fiselier } 465a83710eSEric Fiselier { 475a83710eSEric Fiselier std::wstringstream ss(L" 123 456 "); 485a83710eSEric Fiselier assert(ss.rdbuf() != 0); 495a83710eSEric Fiselier assert(ss.good()); 505a83710eSEric Fiselier assert(ss.str() == L" 123 456 "); 515a83710eSEric Fiselier int i = 0; 525a83710eSEric Fiselier ss >> i; 535a83710eSEric Fiselier assert(i == 123); 545a83710eSEric Fiselier ss >> i; 555a83710eSEric Fiselier assert(i == 456); 565a83710eSEric Fiselier ss << i << ' ' << 123; 575a83710eSEric Fiselier assert(ss.str() == L"456 1236 "); 585a83710eSEric Fiselier } 59a054f828SMarshall Clow { // This is https://bugs.llvm.org/show_bug.cgi?id=33727 60a054f828SMarshall Clow typedef std::basic_string <char, std::char_traits<char>, NoDefaultAllocator<char> > S; 61a054f828SMarshall Clow typedef std::basic_stringbuf<char, std::char_traits<char>, NoDefaultAllocator<char> > SB; 62a054f828SMarshall Clow 63a054f828SMarshall Clow S s(NoDefaultAllocator<char>(1)); 64a054f828SMarshall Clow SB sb(s); 65a054f828SMarshall Clow // This test is not required by the standard, but *where else* could it get the allocator? 66a054f828SMarshall Clow assert(sb.str().get_allocator() == s.get_allocator()); 67a054f828SMarshall Clow } 685a83710eSEric Fiselier } 69