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// pos_type tellg();
13
14#include <istream>
15#include <cassert>
16
17template <class CharT>
18struct testbuf
19    : public std::basic_streambuf<CharT>
20{
21    typedef std::basic_string<CharT> string_type;
22    typedef std::basic_streambuf<CharT> base;
23private:
24    string_type str_;
25public:
26
27    testbuf() {}
28    testbuf(const string_type& str)
29        : str_(str)
30    {
31        base::setg(const_cast<CharT*>(str_.data()),
32                   const_cast<CharT*>(str_.data()),
33                   const_cast<CharT*>(str_.data()) + str_.size());
34    }
35
36    CharT* eback() const {return base::eback();}
37    CharT* gptr() const {return base::gptr();}
38    CharT* egptr() const {return base::egptr();}
39protected:
40    typename base::pos_type seekoff(typename base::off_type off,
41                                    std::ios_base::seekdir way,
42                                    std::ios_base::openmode which)
43    {
44        assert(off == 0);
45        assert(way == std::ios_base::cur);
46        assert(which == std::ios_base::in);
47        return 5;
48    }
49};
50
51int main()
52{
53    {
54        testbuf<char> sb(" 123456789");
55        std::istream is(&sb);
56        assert(is.tellg() == 5);
57    }
58    {
59        testbuf<wchar_t> sb(L" 123456789");
60        std::wistream is(&sb);
61        assert(is.tellg() == 5);
62    }
63}
64