本文整理汇总了C++中my_facet::get方法的典型用法代码示例。如果您正苦于以下问题:C++ my_facet::get方法的具体用法?C++ my_facet::get怎么用?C++ my_facet::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类my_facet
的用法示例。
在下文中一共展示了my_facet::get方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_neg_one
void test_neg_one() {
const my_facet f(1);
std::ios ios(0);
T v = static_cast<T>(42);
{
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 == T(-1));
}
v = 42;
{
const char str[] = "-";
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.failbit);
assert(v == 0);
}
}
示例2: main
int main()
{
const my_facet f(1);
std::ios ios(0);
{
const char str[] = "0x0";
std::ios_base::iostate err = ios.goodbit;
void* p;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+sizeof(str)),
ios, err, p);
assert(iter.base() == str+sizeof(str)-1);
assert(err == ios.goodbit);
assert(p == 0);
}
{
const char str[] = "0x73";
std::ios_base::iostate err = ios.goodbit;
void* p;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+sizeof(str)),
ios, err, p);
assert(iter.base() == str+sizeof(str)-1);
assert(err == ios.goodbit);
assert(p == (void*)0x73);
}
}
示例3: main
int main(int, char**)
{
const my_facet f(1);
std::ios ios(0);
unsigned long v = static_cast<unsigned long>(-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);
}
return 0;
}
示例4: main
int main(int, char**)
{
const my_facet f(1);
std::ios ios(0);
std::ios_base::iostate err;
std::tm t;
{
const char in[] = "2009 May 9, 10:27pm";
const char fmt[] = "%Y %b %d, %I:%M%p";
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)-1), ios, err, &t, fmt, fmt+sizeof(fmt)-1);
assert(i.base() == in+sizeof(in)-1);
assert(t.tm_year == 109);
assert(t.tm_mon == 4);
assert(t.tm_mday == 9);
assert(t.tm_hour == 22);
assert(t.tm_min == 27);
assert(err == std::ios_base::eofbit);
}
{
const char in[] = "10:27PM May 9, 2009";
const char fmt[] = "%I:%M%p %b %d, %Y";
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)-1), ios, err, &t, fmt, fmt+sizeof(fmt)-1);
assert(i.base() == in+sizeof(in)-1);
assert(t.tm_year == 109);
assert(t.tm_mon == 4);
assert(t.tm_mday == 9);
assert(t.tm_hour == 22);
assert(t.tm_min == 27);
assert(err == std::ios_base::eofbit);
}
return 0;
}
示例5: main
int main()
{
const my_facet f(1);
std::ios ios(0);
double v = -1;
{
const char str[] = "123";
assert((ios.flags() & ios.basefield) == ios.dec);
assert(ios.getloc().name() == "C");
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 == 123);
}
{
const char str[] = "-123";
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 == -123);
}
{
const char str[] = "123.5";
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 == 123.5);
}
{
const char str[] = "125e-1";
hex(ios);
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 == 125e-1);
}
{
const char str[] = "0x125p-1";
hex(ios);
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 == hexfloat<double>(0x125, 0, -1));
}
{
const char str[] = "inf";
hex(ios);
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 == INFINITY);
}
{
const char str[] = "INF";
hex(ios);
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 == INFINITY);
}
{
const char str[] = "-inf";
hex(ios);
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 == -INFINITY);
}
//.........这里部分代码省略.........
示例6: main
int main()
{
const my_facet f(1);
std::ios ios(0);
{
const char str[] = "1";
std::ios_base::iostate err = ios.goodbit;
bool b;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+sizeof(str)),
ios, err, b);
assert(iter.base() == str+sizeof(str)-1);
assert(err == ios.goodbit);
assert(b == true);
}
{
const char str[] = "0";
std::ios_base::iostate err = ios.goodbit;
bool b;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+sizeof(str)),
ios, err, b);
assert(iter.base() == str+sizeof(str)-1);
assert(err == ios.goodbit);
assert(b == false);
}
{
const char str[] = "12";
std::ios_base::iostate err = ios.goodbit;
bool b;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+sizeof(str)),
ios, err, b);
assert(iter.base() == str+sizeof(str)-1);
assert(err == ios.failbit);
assert(b == true);
}
{
const char str[] = "*12";
std::ios_base::iostate err = ios.goodbit;
bool b;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+sizeof(str)),
ios, err, b);
assert(iter.base() == str+0);
assert(err == ios.failbit);
assert(b == false);
}
boolalpha(ios);
{
const char str[] = "1";
std::ios_base::iostate err = ios.goodbit;
bool b;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+sizeof(str)),
ios, err, b);
assert(iter.base() == str+0);
assert(err == ios.failbit);
assert(b == false);
}
{
const char str[] = "true";
std::ios_base::iostate err = ios.goodbit;
bool b;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+sizeof(str)),
ios, err, b);
assert(iter.base() == str+sizeof(str)-1);
assert(err == ios.goodbit);
assert(b == true);
}
{
const char str[] = "false";
std::ios_base::iostate err = ios.goodbit;
bool b;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+sizeof(str)),
ios, err, b);
assert(iter.base() == str+sizeof(str)-1);
assert(err == ios.goodbit);
assert(b == false);
}
ios.imbue(std::locale(ios.getloc(), new p1));
{
const char str[] = "a";
std::ios_base::iostate err = ios.goodbit;
bool b;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+1),
ios, err, b);
assert(iter.base() == str+1);
assert(err == ios.eofbit);
//.........这里部分代码省略.........
示例7: main
int main()
{
std::ios ios(0);
std::ios_base::iostate err;
std::tm t;
{
const my_facet f(LOCALE_en_US_UTF_8, 1);
const wchar_t in[] = L"Sat Dec 31 23:55:59 2061";
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
assert(t.tm_sec == 59);
assert(t.tm_min == 55);
assert(t.tm_hour == 23);
assert(t.tm_mday == 31);
assert(t.tm_mon == 11);
assert(t.tm_year == 161);
assert(t.tm_wday == 6);
assert(err == std::ios_base::eofbit);
}
{
const my_facet f(LOCALE_en_US_UTF_8, 1);
const wchar_t in[] = L"23:55:59";
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'X');
assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
assert(t.tm_sec == 59);
assert(t.tm_min == 55);
assert(t.tm_hour == 23);
assert(err == std::ios_base::eofbit);
}
{
const my_facet f(LOCALE_fr_FR_UTF_8, 1);
const wchar_t in[] = L"Sam 31 d" L"\xE9" L"c 23:55:59 2061";
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
assert(t.tm_sec == 59);
assert(t.tm_min == 55);
assert(t.tm_hour == 23);
assert(t.tm_mday == 31);
assert(t.tm_mon == 11);
assert(t.tm_year == 161);
assert(t.tm_wday == 6);
assert(err == std::ios_base::eofbit);
}
{
const my_facet f(LOCALE_fr_FR_UTF_8, 1);
const wchar_t in[] = L"23:55:59";
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'X');
assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
assert(t.tm_sec == 59);
assert(t.tm_min == 55);
assert(t.tm_hour == 23);
assert(err == std::ios_base::eofbit);
}
#ifdef __APPLE__
{
const my_facet f("ru_RU", 1);
const wchar_t in[] = L"\x441\x443\x431\x431\x43E\x442\x430"
L", 31 "
L"\x434\x435\x43A\x430\x431\x440\x44F"
L" 2061 "
L"\x433"
L". 23:55:59";
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'c');
assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
assert(t.tm_sec == 59);
assert(t.tm_min == 55);
assert(t.tm_hour == 23);
assert(t.tm_mday == 31);
assert(t.tm_mon == 11);
assert(t.tm_year == 161);
assert(t.tm_wday == 6);
assert(err == std::ios_base::eofbit);
}
#endif
{
const my_facet f(LOCALE_ru_RU_UTF_8, 1);
const wchar_t in[] = L"23:55:59";
err = std::ios_base::goodbit;
t = std::tm();
I i = f.get(I(in), I(in+sizeof(in)/sizeof(in[0])-1), ios, err, &t, 'X');
assert(i.base() == in+sizeof(in)/sizeof(in[0])-1);
assert(t.tm_sec == 59);
assert(t.tm_min == 55);
assert(t.tm_hour == 23);
assert(err == std::ios_base::eofbit);
}
#ifdef __APPLE__
{
const my_facet f("zh_CN", 1);
const wchar_t in[] = L"\x516D"
//.........这里部分代码省略.........
示例8: main
int main()
{
const my_facet f(1);
std::ios ios(0);
long v = -1;
{
const char str[] = "123";
assert((ios.flags() & ios.basefield) == ios.dec);
assert(ios.getloc().name() == "C");
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+3);
assert(err == ios.goodbit);
assert(v == 123);
}
{
const char str[] = "-123";
assert((ios.flags() & ios.basefield) == ios.dec);
assert(ios.getloc().name() == "C");
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+4);
assert(err == ios.goodbit);
assert(v == -123);
}
{
const char str[] = "123";
oct(ios);
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+3);
assert(err == ios.goodbit);
assert(v == 83);
}
{
const char str[] = "123";
hex(ios);
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+3);
assert(err == ios.goodbit);
assert(v == 291);
}
{
const char str[] = "0x123";
hex(ios);
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 == 291);
}
{
const char str[] = "123";
ios.setf(0, ios.basefield);
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 == 123);
}
{
const char str[] = "0x123";
ios.setf(0, ios.basefield);
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 == 291);
}
{
const char str[] = "0123";
ios.setf(0, ios.basefield);
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);
//.........这里部分代码省略.........
示例9: main
int main()
{
std::ios ios(0);
std::string loc_name(LOCALE_zh_CN_UTF_8);
ios.imbue(std::locale(ios.getloc(),
new std::moneypunct_byname<char, false>(loc_name)));
ios.imbue(std::locale(ios.getloc(),
new std::moneypunct_byname<char, true>(loc_name)));
ios.imbue(std::locale(ios.getloc(),
new std::moneypunct_byname<wchar_t, false>(loc_name)));
ios.imbue(std::locale(ios.getloc(),
new std::moneypunct_byname<wchar_t, true>(loc_name)));
{
const my_facet f(1);
// char, national
{ // zero
std::string v = "0.00";
typedef input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
I iter = f.get(I(v.data()), I(v.data() + v.size()),
false, ios, err, ex);
assert(iter.base() == v.data() + v.size());
assert(err == std::ios_base::eofbit);
assert(ex == 0);
}
{ // negative one
std::string v = "-0.01";
typedef input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
I iter = f.get(I(v.data()), I(v.data() + v.size()),
false, ios, err, ex);
assert(iter.base() == v.data() + v.size());
assert(err == std::ios_base::eofbit);
assert(ex == -1);
}
{ // positive
std::string v = "1,234,567.89";
typedef input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
I iter = f.get(I(v.data()), I(v.data() + v.size()),
false, ios, err, ex);
assert(iter.base() == v.data() + v.size());
assert(err == std::ios_base::eofbit);
assert(ex == 123456789);
}
{ // negative
std::string v = "-1,234,567.89";
typedef input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
I iter = f.get(I(v.data()), I(v.data() + v.size()),
false, ios, err, ex);
assert(iter.base() == v.data() + v.size());
assert(err == std::ios_base::eofbit);
assert(ex == -123456789);
}
{ // negative
std::string v = "-1234567.89";
typedef input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
I iter = f.get(I(v.data()), I(v.data() + v.size()),
false, ios, err, ex);
assert(iter.base() == v.data() + v.size());
assert(err == std::ios_base::eofbit);
assert(ex == -123456789);
}
{ // zero, showbase
std::string v = "\xEF\xBF\xA5""0.00";
typedef input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
I iter = f.get(I(v.data()), I(v.data() + v.size()),
false, ios, err, ex);
assert(iter.base() == v.data() + v.size());
assert(err == std::ios_base::eofbit);
assert(ex == 0);
}
{ // zero, showbase
std::string v = "\xEF\xBF\xA5""0.00";
showbase(ios);
typedef input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
I iter = f.get(I(v.data()), I(v.data() + v.size()),
false, ios, err, ex);
assert(iter.base() == v.data() + v.size());
assert(err == std::ios_base::eofbit);
assert(ex == 0);
noshowbase(ios);
}
{ // negative one, showbase
std::string v = "\xEF\xBF\xA5""-0.01";
typedef input_iterator<const char*> I;
long double ex;
std::ios_base::iostate err = std::ios_base::goodbit;
I iter = f.get(I(v.data()), I(v.data() + v.size()),
//.........这里部分代码省略.........
示例10: main
int main()
{
const my_facet f(1);
std::ios ios(0);
float v = -1;
{
const char str[] = "123";
assert((ios.flags() & ios.basefield) == ios.dec);
assert(ios.getloc().name() == "C");
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 == 123);
}
{
const char str[] = "-123";
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 == -123);
}
{
const char str[] = "123.5";
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 == 123.5);
}
{
const char str[] = "125e-1";
hex(ios);
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 == 125e-1);
}
{
const char str[] = "0x125p-1";
hex(ios);
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 == hexfloat<float>(0x125, 0, -1));
}
{
const char str[] = "inf";
hex(ios);
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 == INFINITY);
}
{
const char str[] = "INF";
hex(ios);
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 == INFINITY);
}
{
const char str[] = "-inf";
hex(ios);
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 == -INFINITY);
}
//.........这里部分代码省略.........
示例11: test_negate
void test_negate() {
typedef typename std::make_signed<T>::type SignedT;
const my_facet f(1);
std::ios ios(0);
T v = 42;
{
T value = std::numeric_limits<SignedT>::max();
++value;
std::string std_str = make_neg_string(value);
const char* str = std_str.data();
size_t size = std_str.size();
std::ios_base::iostate err = ios.goodbit;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+size+1),
ios, err, v);
assert(iter.base() == str+size);
assert(err == ios.goodbit);
T expected = -value;
assert(v == expected);
}
v = 42;
{
T value = std::numeric_limits<SignedT>::max();
++value;
++value;
std::string std_str = make_neg_string(value);
const char* str = std_str.data();
size_t size = std_str.size();
std::ios_base::iostate err = ios.goodbit;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+size+1),
ios, err, v);
assert(iter.base() == str+size);
assert(err == ios.goodbit);
T expected = -value;
assert(v == expected);
}
v = 42;
{
T value = std::numeric_limits<T>::max();
std::string std_str = make_neg_string(value);
const char* str = std_str.data();
size_t size = std_str.size();
std::ios_base::iostate err = ios.goodbit;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+size+1),
ios, err, v);
assert(iter.base() == str+size);
assert(err == ios.goodbit);
T expected = -value;
assert(v == expected);
}
v = 42;
{
std::string std_str = make_neg_string(std::numeric_limits<T>::max());
std_str.back()++;
const char* str = std_str.data();
size_t size = std_str.size();
std::ios_base::iostate err = ios.goodbit;
input_iterator<const char*> iter =
f.get(input_iterator<const char*>(str),
input_iterator<const char*>(str+size+1),
ios, err, v);
assert(iter.base() == str+size);
assert(err == ios.failbit);
assert(v == T(-1));
}
}