blob: b3f74a9ce578c06eefa5d907aa7feccbfde20e9e [file] [log] [blame]
//===----------------------------------------------------------------------===//
//
// 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 long& v) const;
#include <locale>
#include <ios>
#include <cassert>
#include <streambuf>
#include "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 long 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[] = "0xFFFFFFFF";
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 == 0xFFFFFFFF);
}
}