1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <istream>
11
12// template <class charT, class traits>
13//   basic_istream<charT,traits>&
14//   ws(basic_istream<charT,traits>& is);
15
16#include <istream>
17#include <cassert>
18
19template <class CharT>
20struct testbuf
21    : public std::basic_streambuf<CharT>
22{
23    typedef std::basic_string<CharT> string_type;
24    typedef std::basic_streambuf<CharT> base;
25private:
26    string_type str_;
27public:
28
29    testbuf() {}
30    testbuf(const string_type& str)
31        : str_(str)
32    {
33        base::setg(const_cast<CharT*>(str_.data()),
34                   const_cast<CharT*>(str_.data()),
35                   const_cast<CharT*>(str_.data()) + str_.size());
36    }
37
38    CharT* eback() const {return base::eback();}
39    CharT* gptr() const {return base::gptr();}
40    CharT* egptr() const {return base::egptr();}
41};
42
43int main()
44{
45    {
46        testbuf<char> sb("   123");
47        std::istream is(&sb);
48        ws(is);
49        assert(is.good());
50        assert(is.peek() == '1');
51    }
52    {
53        testbuf<wchar_t> sb(L"   123");
54        std::wistream is(&sb);
55        ws(is);
56        assert(is.good());
57        assert(is.peek() == L'1');
58    }
59}
60