get_pointer.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
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// <locale>
11
12// class num_get<charT, InputIterator>
13
14// iter_type get(iter_type in, iter_type end, ios_base&,
15//               ios_base::iostate& err, void*& v) const;
16
17#include <locale>
18#include <ios>
19#include <cassert>
20#include <streambuf>
21#include "iterators.h"
22
23typedef std::num_get<char, input_iterator<const char*> > F;
24
25class my_facet
26    : public F
27{
28public:
29    explicit my_facet(std::size_t refs = 0)
30        : F(refs) {}
31};
32
33int main()
34{
35    const my_facet f(1);
36    std::ios ios(0);
37    {
38        const char str[] = "0x0";
39        std::ios_base::iostate err = ios.goodbit;
40        void* p;
41        input_iterator<const char*> iter =
42            f.get(input_iterator<const char*>(str),
43                  input_iterator<const char*>(str+sizeof(str)),
44                  ios, err, p);
45        assert(iter.base() == str+sizeof(str)-1);
46        assert(err == ios.goodbit);
47        assert(p == 0);
48    }
49    {
50        const char str[] = "0x73";
51        std::ios_base::iostate err = ios.goodbit;
52        void* p;
53        input_iterator<const char*> iter =
54            f.get(input_iterator<const char*>(str),
55                  input_iterator<const char*>(str+sizeof(str)),
56                  ios, err, p);
57        assert(iter.base() == str+sizeof(str)-1);
58        assert(err == ios.goodbit);
59        assert(p == (void*)0x73);
60    }
61}
62