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, unsigned long long& v) const;
16
17 #include <locale>
18 #include <ios>
19 #include <cassert>
20 #include <streambuf>
21 #include "test_iterators.h"
22
23 typedef std::num_get<char, input_iterator<const char*> > F;
24
25 class my_facet
26 : public F
27 {
28 public:
my_facet(std::size_t refs=0)29 explicit my_facet(std::size_t refs = 0)
30 : F(refs) {}
31 };
32
33 class my_numpunct
34 : public std::numpunct<char>
35 {
36 public:
my_numpunct()37 my_numpunct() : std::numpunct<char>() {}
38
39 protected:
do_thousands_sep() const40 virtual char_type do_thousands_sep() const {return '_';}
do_grouping() const41 virtual std::string do_grouping() const {return std::string("\1\2\3");}
42 };
43
main()44 int main()
45 {
46 const my_facet f(1);
47 std::ios ios(0);
48 unsigned long long v = -1;
49 {
50 const char str[] = "0";
51 std::ios_base::iostate err = ios.goodbit;
52 input_iterator<const char*> iter =
53 f.get(input_iterator<const char*>(str),
54 input_iterator<const char*>(str+sizeof(str)),
55 ios, err, v);
56 assert(iter.base() == str+sizeof(str)-1);
57 assert(err == ios.goodbit);
58 assert(v == 0);
59 }
60 {
61 const char str[] = "1";
62 std::ios_base::iostate err = ios.goodbit;
63 input_iterator<const char*> iter =
64 f.get(input_iterator<const char*>(str),
65 input_iterator<const char*>(str+sizeof(str)),
66 ios, err, v);
67 assert(iter.base() == str+sizeof(str)-1);
68 assert(err == ios.goodbit);
69 assert(v == 1);
70 }
71 hex(ios);
72 {
73 const char str[] = "0xFFFFFFFFFFFFFFFF";
74 std::ios_base::iostate err = ios.goodbit;
75 input_iterator<const char*> iter =
76 f.get(input_iterator<const char*>(str),
77 input_iterator<const char*>(str+sizeof(str)),
78 ios, err, v);
79 assert(iter.base() == str+sizeof(str)-1);
80 assert(err == ios.goodbit);
81 assert(v == 0xFFFFFFFFFFFFFFFFULL);
82 }
83 }
84