| //===----------------------------------------------------------------------===// |
| // |
| // The LLVM Compiler Infrastructure |
| // |
| // This file is dual licensed under the MIT and the University of Illinois Open |
| // Source Licenses. See LICENSE.TXT for details. |
| // |
| //===----------------------------------------------------------------------===// |
| |
| // <locale> |
| |
| // class num_get<charT, InputIterator> |
| |
| // iter_type get(iter_type in, iter_type end, ios_base&, |
| // ios_base::iostate& err, unsigned short& v) const; |
| |
| #include <locale> |
| #include <ios> |
| #include <cassert> |
| #include <streambuf> |
| #include "test_iterators.h" |
| |
| typedef std::num_get<char, input_iterator<const char*> > F; |
| |
| class my_facet |
| : public F |
| { |
| public: |
| explicit my_facet(std::size_t refs = 0) |
| : F(refs) {} |
| }; |
| |
| class my_numpunct |
| : public std::numpunct<char> |
| { |
| public: |
| my_numpunct() : std::numpunct<char>() {} |
| |
| protected: |
| virtual char_type do_thousands_sep() const {return '_';} |
| virtual std::string do_grouping() const {return std::string("\1\2\3");} |
| }; |
| |
| int main() |
| { |
| const my_facet f(1); |
| std::ios ios(0); |
| unsigned short v = -1; |
| { |
| const char str[] = "0"; |
| std::ios_base::iostate err = ios.goodbit; |
| input_iterator<const char*> iter = |
| f.get(input_iterator<const char*>(str), |
| input_iterator<const char*>(str+sizeof(str)), |
| ios, err, v); |
| assert(iter.base() == str+sizeof(str)-1); |
| assert(err == ios.goodbit); |
| assert(v == 0); |
| } |
| { |
| const char str[] = "1"; |
| std::ios_base::iostate err = ios.goodbit; |
| input_iterator<const char*> iter = |
| f.get(input_iterator<const char*>(str), |
| input_iterator<const char*>(str+sizeof(str)), |
| ios, err, v); |
| assert(iter.base() == str+sizeof(str)-1); |
| assert(err == ios.goodbit); |
| assert(v == 1); |
| } |
| hex(ios); |
| { |
| const char str[] = "0xFFFF"; |
| std::ios_base::iostate err = ios.goodbit; |
| input_iterator<const char*> iter = |
| f.get(input_iterator<const char*>(str), |
| input_iterator<const char*>(str+sizeof(str)), |
| ios, err, v); |
| assert(iter.base() == str+sizeof(str)-1); |
| assert(err == ios.goodbit); |
| assert(v == 0xFFFF); |
| } |
| } |