libcxx initial import

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103490 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant
2010-05-11 19:42:16 +00:00
commit bc8d3f97eb
3893 changed files with 1209942 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <iomanip>
// template <class moneyT> T7 get_money(moneyT& mon, bool intl = false);
#include <iomanip>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
};
int main()
{
{
testbuf<char> sb(" -$1,234,567.89");
std::istream is(&sb);
is.imbue(std::locale("en_US"));
long double x = 0;
is >> std::get_money(x, false);
assert(x == -123456789);
}
{
testbuf<char> sb(" -USD 1,234,567.89");
std::istream is(&sb);
is.imbue(std::locale("en_US"));
long double x = 0;
is >> std::get_money(x, true);
assert(x == -123456789);
}
{
testbuf<wchar_t> sb(L" -$1,234,567.89");
std::wistream is(&sb);
is.imbue(std::locale("en_US"));
long double x = 0;
is >> std::get_money(x, false);
assert(x == -123456789);
}
{
testbuf<wchar_t> sb(L" -USD 1,234,567.89");
std::wistream is(&sb);
is.imbue(std::locale("en_US"));
long double x = 0;
is >> std::get_money(x, true);
assert(x == -123456789);
}
}

View File

@@ -0,0 +1,71 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <iomanip>
// template <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
#include <iomanip>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
};
int main()
{
{
testbuf<char> sb(" Sat Dec 31 23:55:59 2061");
std::istream is(&sb);
is.imbue(std::locale("en_US"));
std::tm t = {0};
is >> std::get_time(&t, "%c");
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(is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" Sat Dec 31 23:55:59 2061");
std::wistream is(&sb);
is.imbue(std::locale("en_US"));
std::tm t = {0};
is >> std::get_time(&t, L"%c");
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(is.eof());
assert(!is.fail());
}
}

View File

@@ -0,0 +1,87 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <iomanip>
// template <class charT, class moneyT> T8 put_money(const moneyT& mon, bool intl = false);
#include <iomanip>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
testbuf<char> sb;
std::ostream os(&sb);
os.imbue(std::locale("en_US"));
showbase(os);
long double x = -123456789;
os << std::put_money(x, false);
assert(sb.str() == "-$1,234,567.89");
}
{
testbuf<char> sb;
std::ostream os(&sb);
os.imbue(std::locale("en_US"));
showbase(os);
long double x = -123456789;
os << std::put_money(x, true);
assert(sb.str() == "-USD 1,234,567.89");
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
os.imbue(std::locale("en_US"));
showbase(os);
long double x = -123456789;
os << std::put_money(x, false);
assert(sb.str() == L"-$1,234,567.89");
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
os.imbue(std::locale("en_US"));
showbase(os);
long double x = -123456789;
os << std::put_money(x, true);
assert(sb.str() == L"-USD 1,234,567.89");
}
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <iomanip>
// template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt);
#include <iomanip>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
testbuf<char> sb;
std::ostream os(&sb);
os.imbue(std::locale("en_US"));
std::tm t = {0};
t.tm_sec = 59;
t.tm_min = 55;
t.tm_hour = 23;
t.tm_mday = 31;
t.tm_mon = 11;
t.tm_year = 161;
t.tm_wday = 6;
os << std::put_time(&t, "%c");
assert(sb.str() == "Sat Dec 31 23:55:59 2061");
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
os.imbue(std::locale("en_US"));
std::tm t = {0};
t.tm_sec = 59;
t.tm_min = 55;
t.tm_hour = 23;
t.tm_mday = 31;
t.tm_mon = 11;
t.tm_year = 161;
t.tm_wday = 6;
os << std::put_time(&t, L"%c");
assert(sb.str() == L"Sat Dec 31 23:55:59 2061");
}
}

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_iostream;
// void swap(basic_iostream& rhs);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
testbuf() {}
};
template <class CharT>
struct test_iostream
: public std::basic_iostream<CharT>
{
typedef std::basic_iostream<CharT> base;
test_iostream(testbuf<CharT>* sb) : base(sb) {}
void swap(test_iostream& s) {base::swap(s);}
};
int main()
{
{
testbuf<char> sb1;
testbuf<char> sb2;
test_iostream<char> is1(&sb1);
test_iostream<char> is2(&sb2);
is1.swap(is2);
assert(is1.rdbuf() == &sb1);
assert(is1.tie() == 0);
assert(is1.fill() == ' ');
assert(is1.rdstate() == is1.goodbit);
assert(is1.exceptions() == is1.goodbit);
assert(is1.flags() == (is1.skipws | is1.dec));
assert(is1.precision() == 6);
assert(is1.getloc().name() == "C");
assert(is2.rdbuf() == &sb2);
assert(is2.tie() == 0);
assert(is2.fill() == ' ');
assert(is2.rdstate() == is2.goodbit);
assert(is2.exceptions() == is2.goodbit);
assert(is2.flags() == (is2.skipws | is2.dec));
assert(is2.precision() == 6);
assert(is2.getloc().name() == "C");
}
{
testbuf<wchar_t> sb1;
testbuf<wchar_t> sb2;
test_iostream<wchar_t> is1(&sb1);
test_iostream<wchar_t> is2(&sb2);
is1.swap(is2);
assert(is1.rdbuf() == &sb1);
assert(is1.tie() == 0);
assert(is1.fill() == ' ');
assert(is1.rdstate() == is1.goodbit);
assert(is1.exceptions() == is1.goodbit);
assert(is1.flags() == (is1.skipws | is1.dec));
assert(is1.precision() == 6);
assert(is1.getloc().name() == "C");
assert(is2.rdbuf() == &sb2);
assert(is2.tie() == 0);
assert(is2.fill() == ' ');
assert(is2.rdstate() == is2.goodbit);
assert(is2.exceptions() == is2.goodbit);
assert(is2.flags() == (is2.skipws | is2.dec));
assert(is2.precision() == 6);
assert(is2.getloc().name() == "C");
}
}

View File

@@ -0,0 +1,92 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_iostream;
// basic_iostream& operator=(basic_iostream&& rhs);
#include <istream>
#include <cassert>
#ifdef _LIBCPP_MOVE
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
testbuf() {}
};
template <class CharT>
struct test_iostream
: public std::basic_iostream<CharT>
{
typedef std::basic_iostream<CharT> base;
test_iostream(testbuf<CharT>* sb) : base(sb) {}
test_iostream& operator=(test_iostream&& s)
{base::operator=(std::move(s)); return *this;}
};
#endif
int main()
{
#ifdef _LIBCPP_MOVE
{
testbuf<char> sb1;
testbuf<char> sb2;
test_iostream<char> is1(&sb1);
test_iostream<char> is2(&sb2);
is2 = (std::move(is1));
assert(is1.rdbuf() == &sb1);
assert(is1.tie() == 0);
assert(is1.fill() == ' ');
assert(is1.rdstate() == is1.goodbit);
assert(is1.exceptions() == is1.goodbit);
assert(is1.flags() == (is1.skipws | is1.dec));
assert(is1.precision() == 6);
assert(is1.getloc().name() == "C");
assert(is2.rdbuf() == &sb2);
assert(is2.tie() == 0);
assert(is2.fill() == ' ');
assert(is2.rdstate() == is2.goodbit);
assert(is2.exceptions() == is2.goodbit);
assert(is2.flags() == (is2.skipws | is2.dec));
assert(is2.precision() == 6);
assert(is2.getloc().name() == "C");
}
{
testbuf<wchar_t> sb1;
testbuf<wchar_t> sb2;
test_iostream<wchar_t> is1(&sb1);
test_iostream<wchar_t> is2(&sb2);
is2 = (std::move(is1));
assert(is1.rdbuf() == &sb1);
assert(is1.tie() == 0);
assert(is1.fill() == ' ');
assert(is1.rdstate() == is1.goodbit);
assert(is1.exceptions() == is1.goodbit);
assert(is1.flags() == (is1.skipws | is1.dec));
assert(is1.precision() == 6);
assert(is1.getloc().name() == "C");
assert(is2.rdbuf() == &sb2);
assert(is2.tie() == 0);
assert(is2.fill() == ' ');
assert(is2.rdstate() == is2.goodbit);
assert(is2.exceptions() == is2.goodbit);
assert(is2.flags() == (is2.skipws | is2.dec));
assert(is2.precision() == 6);
assert(is2.getloc().name() == "C");
}
#endif
}

View File

@@ -0,0 +1,78 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_iostream;
// basic_iostream(basic_iostream&& rhs);
#include <istream>
#include <cassert>
#ifdef _LIBCPP_MOVE
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
testbuf() {}
};
template <class CharT>
struct test_iostream
: public std::basic_iostream<CharT>
{
typedef std::basic_iostream<CharT> base;
test_iostream(testbuf<CharT>* sb) : base(sb) {}
test_iostream(test_iostream&& s)
: base(std::move(s)) {}
};
#endif
int main()
{
#ifdef _LIBCPP_MOVE
{
testbuf<char> sb;
test_iostream<char> is1(&sb);
test_iostream<char> is(std::move(is1));
assert(is1.rdbuf() == &sb);
assert(is1.gcount() == 0);
assert(is.gcount() == 0);
assert(is.rdbuf() == 0);
assert(is.tie() == 0);
assert(is.fill() == ' ');
assert(is.rdstate() == is.goodbit);
assert(is.exceptions() == is.goodbit);
assert(is.flags() == (is.skipws | is.dec));
assert(is.precision() == 6);
assert(is.getloc().name() == "C");
}
{
testbuf<wchar_t> sb;
test_iostream<wchar_t> is1(&sb);
test_iostream<wchar_t> is(std::move(is1));
assert(is1.gcount() == 0);
assert(is.gcount() == 0);
assert(is1.rdbuf() == &sb);
assert(is.rdbuf() == 0);
assert(is.tie() == 0);
assert(is.fill() == L' ');
assert(is.rdstate() == is.goodbit);
assert(is.exceptions() == is.goodbit);
assert(is.flags() == (is.skipws | is.dec));
assert(is.precision() == 6);
assert(is.getloc().name() == "C");
}
#endif
}

View File

@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_iostream;
// explicit basic_iostream(basic_streambuf<charT,traits>* sb);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
testbuf() {}
};
int main()
{
{
testbuf<char> sb;
std::basic_iostream<char> is(&sb);
assert(is.rdbuf() == &sb);
assert(is.tie() == 0);
assert(is.fill() == ' ');
assert(is.rdstate() == is.goodbit);
assert(is.exceptions() == is.goodbit);
assert(is.flags() == (is.skipws | is.dec));
assert(is.precision() == 6);
assert(is.getloc().name() == "C");
assert(is.gcount() == 0);
}
{
testbuf<wchar_t> sb;
std::basic_iostream<wchar_t> is(&sb);
assert(is.rdbuf() == &sb);
assert(is.tie() == 0);
assert(is.fill() == L' ');
assert(is.rdstate() == is.goodbit);
assert(is.exceptions() == is.goodbit);
assert(is.flags() == (is.skipws | is.dec));
assert(is.precision() == 6);
assert(is.getloc().name() == "C");
assert(is.gcount() == 0);
}
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_iostream :
// public basic_istream<charT,traits>,
// public basic_ostream<charT,traits>
// {
// public:
// // types:
// typedef charT char_type;
// typedef traits traits_type;
// typedef typename traits_type::int_type int_type;
// typedef typename traits_type::pos_type pos_type;
// typedef typename traits_type::off_type off_type;
#include <istream>
#include <type_traits>
int main()
{
static_assert((std::is_base_of<std::basic_istream<char>, std::basic_iostream<char> >::value), "");
static_assert((std::is_base_of<std::basic_ostream<char>, std::basic_iostream<char> >::value), "");
static_assert((std::is_same<std::basic_iostream<char>::char_type, char>::value), "");
static_assert((std::is_same<std::basic_iostream<char>::traits_type, std::char_traits<char> >::value), "");
static_assert((std::is_same<std::basic_iostream<char>::int_type, std::char_traits<char>::int_type>::value), "");
static_assert((std::is_same<std::basic_iostream<char>::pos_type, std::char_traits<char>::pos_type>::value), "");
static_assert((std::is_same<std::basic_iostream<char>::off_type, std::char_traits<char>::off_type>::value), "");
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// operator>>(bool& val);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
std::istream is((std::streambuf*)0);
bool n = 0;
is >> n;
assert(is.fail());
}
{
testbuf<char> sb("0");
std::istream is(&sb);
bool n = true;
is >> n;
assert(n == false);
assert( is.eof());
assert(!is.fail());
}
{
testbuf<char> sb(" 1 ");
std::istream is(&sb);
bool n = 0;
is >> n;
assert(n == true);
assert(!is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" 1 ");
std::wistream is(&sb);
bool n = 0;
is >> n;
assert(n == true);
assert(!is.eof());
assert(!is.fail());
}
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// operator>>(double& val);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
std::istream is((std::streambuf*)0);
double n = 0;
is >> n;
assert(is.fail());
}
{
testbuf<char> sb("0");
std::istream is(&sb);
double n = 10;
is >> n;
assert(n == 0);
assert( is.eof());
assert(!is.fail());
}
{
testbuf<char> sb(" 123 ");
std::istream is(&sb);
double n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" -123.5 ");
std::wistream is(&sb);
double n = 10;
is >> n;
assert(n == -123.5);
assert(!is.eof());
assert(!is.fail());
}
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// operator>>(float& val);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
std::istream is((std::streambuf*)0);
float n = 0;
is >> n;
assert(is.fail());
}
{
testbuf<char> sb("0");
std::istream is(&sb);
float n = 10;
is >> n;
assert(n == 0);
assert( is.eof());
assert(!is.fail());
}
{
testbuf<char> sb(" 123 ");
std::istream is(&sb);
float n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" -123.5 ");
std::wistream is(&sb);
float n = 10;
is >> n;
assert(n == -123.5);
assert(!is.eof());
assert(!is.fail());
}
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// operator>>(int& val);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
std::istream is((std::streambuf*)0);
int n = 0;
is >> n;
assert(is.fail());
}
{
testbuf<char> sb("0");
std::istream is(&sb);
int n = 10;
is >> n;
assert(n == 0);
assert( is.eof());
assert(!is.fail());
}
{
testbuf<char> sb(" 123 ");
std::istream is(&sb);
int n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" -1234567890123456 ");
std::wistream is(&sb);
int n = 10;
is >> n;
assert(n == std::numeric_limits<int>::min());
assert(!is.eof());
assert( is.fail());
}
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// operator>>(long& val);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
std::istream is((std::streambuf*)0);
long n = 0;
is >> n;
assert(is.fail());
}
{
testbuf<char> sb("0");
std::istream is(&sb);
long n = 10;
is >> n;
assert(n == 0);
assert( is.eof());
assert(!is.fail());
}
{
testbuf<char> sb(" 123 ");
std::istream is(&sb);
long n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" -123 ");
std::wistream is(&sb);
long n = 10;
is >> n;
assert(n == -123);
assert(!is.eof());
assert(!is.fail());
}
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// operator>>(long double& val);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
std::istream is((std::streambuf*)0);
long double n = 0;
is >> n;
assert(is.fail());
}
{
testbuf<char> sb("0");
std::istream is(&sb);
long double n = 10;
is >> n;
assert(n == 0);
assert( is.eof());
assert(!is.fail());
}
{
testbuf<char> sb(" 123 ");
std::istream is(&sb);
long double n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" -123.5 ");
std::wistream is(&sb);
long double n = 10;
is >> n;
assert(n == -123.5);
assert(!is.eof());
assert(!is.fail());
}
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// operator>>(long long& val);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
std::istream is((std::streambuf*)0);
long long n = 0;
is >> n;
assert(is.fail());
}
{
testbuf<char> sb("0");
std::istream is(&sb);
long long n = 10;
is >> n;
assert(n == 0);
assert( is.eof());
assert(!is.fail());
}
{
testbuf<char> sb(" 123 ");
std::istream is(&sb);
long long n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" -123 ");
std::wistream is(&sb);
long long n = 10;
is >> n;
assert(n == -123);
assert(!is.eof());
assert(!is.fail());
}
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// operator>>(void*& val);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
std::istream is((std::streambuf*)0);
void* n = 0;
is >> n;
assert(is.fail());
}
{
testbuf<char> sb("0");
std::istream is(&sb);
void* n = (void*)1;
is >> n;
assert(n == 0);
assert( is.eof());
assert(!is.fail());
}
{
testbuf<char> sb(" 1 ");
std::istream is(&sb);
void* n = 0;
is >> n;
assert(n == (void*)1);
assert(!is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" 1 ");
std::wistream is(&sb);
void* n = 0;
is >> n;
assert(n == (void*)1);
assert(!is.eof());
assert(!is.fail());
}
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// operator>>(short& val);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
std::istream is((std::streambuf*)0);
short n = 0;
is >> n;
assert(is.fail());
}
{
testbuf<char> sb("0");
std::istream is(&sb);
short n = 10;
is >> n;
assert(n == 0);
assert( is.eof());
assert(!is.fail());
}
{
testbuf<char> sb(" 123 ");
std::istream is(&sb);
short n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" -1234567890 ");
std::wistream is(&sb);
short n = 10;
is >> n;
assert(n == std::numeric_limits<short>::min());
assert(!is.eof());
assert( is.fail());
}
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// operator>>(unsigned int& val);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
std::istream is((std::streambuf*)0);
unsigned int n = 0;
is >> n;
assert(is.fail());
}
{
testbuf<char> sb("0");
std::istream is(&sb);
unsigned int n = 10;
is >> n;
assert(n == 0);
assert( is.eof());
assert(!is.fail());
}
{
testbuf<char> sb(" 123 ");
std::istream is(&sb);
unsigned int n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" 123 ");
std::wistream is(&sb);
unsigned int n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// operator>>(unsigned long& val);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
std::istream is((std::streambuf*)0);
unsigned long n = 0;
is >> n;
assert(is.fail());
}
{
testbuf<char> sb("0");
std::istream is(&sb);
unsigned long n = 10;
is >> n;
assert(n == 0);
assert( is.eof());
assert(!is.fail());
}
{
testbuf<char> sb(" 123 ");
std::istream is(&sb);
unsigned long n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" 123 ");
std::wistream is(&sb);
unsigned long n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// operator>>(unsigned long long& val);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
std::istream is((std::streambuf*)0);
unsigned long long n = 0;
is >> n;
assert(is.fail());
}
{
testbuf<char> sb("0");
std::istream is(&sb);
unsigned long long n = 10;
is >> n;
assert(n == 0);
assert( is.eof());
assert(!is.fail());
}
{
testbuf<char> sb(" 123 ");
std::istream is(&sb);
unsigned long long n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" 123 ");
std::wistream is(&sb);
unsigned long long n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// operator>>(unsigned short& val);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
std::istream is((std::streambuf*)0);
unsigned short n = 0;
is >> n;
assert(is.fail());
}
{
testbuf<char> sb("0");
std::istream is(&sb);
unsigned short n = 10;
is >> n;
assert(n == 0);
assert( is.eof());
assert(!is.fail());
}
{
testbuf<char> sb(" 123 ");
std::istream is(&sb);
unsigned short n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
{
testbuf<wchar_t> sb(L" 123 ");
std::wistream is(&sb);
unsigned short n = 10;
is >> n;
assert(n == 123);
assert(!is.eof());
assert(!is.fail());
}
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// basic_istream<charT,traits>& operator>>(basic_ios<charT,traits>&
// (*pf)(basic_ios<charT,traits>&));
#include <istream>
#include <cassert>
int f_called = 0;
template <class CharT>
std::basic_ios<CharT>&
f(std::basic_ios<CharT>& is)
{
++f_called;
return is;
}
int main()
{
{
std::istream is((std::streambuf*)0);
is >> f;
assert(f_called == 1);
}
}

View File

@@ -0,0 +1,87 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template<class charT, class traits>
// basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&& in, charT& c);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" ");
std::istream is(&sb);
char c = 'z';
is >> c;
assert( is.eof());
assert( is.fail());
assert(c == 'z');
}
{
testbuf<char> sb(" abcdefghijk ");
std::istream is(&sb);
char c;
is >> c;
assert(!is.eof());
assert(!is.fail());
assert(c == 'a');
is >> c;
assert(!is.eof());
assert(!is.fail());
assert(c == 'b');
is >> c;
assert(!is.eof());
assert(!is.fail());
assert(c == 'c');
}
{
testbuf<wchar_t> sb(L" abc");
std::wistream is(&sb);
wchar_t c;
is >> c;
assert(!is.eof());
assert(!is.fail());
assert(c == L'a');
is >> c;
assert(!is.eof());
assert(!is.fail());
assert(c == L'b');
is >> c;
assert( is.eof());
assert(!is.fail());
assert(c == L'c');
}
}

View File

@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// basic_istream<charT,traits>& operator>>(ios_base& (*pf)(ios_base&));
#include <istream>
#include <cassert>
int f_called = 0;
std::ios_base&
f(std::ios_base& is)
{
++f_called;
return is;
}
int main()
{
{
std::istream is((std::streambuf*)0);
is >> f;
assert(f_called == 1);
}
}

View File

@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&
// (*pf)(basic_istream<charT,traits>&));
#include <istream>
#include <cassert>
int f_called = 0;
template <class CharT>
std::basic_istream<CharT>&
f(std::basic_istream<CharT>& is)
{
++f_called;
return is;
}
int main()
{
{
std::istream is((std::streambuf*)0);
is >> f;
assert(f_called == 1);
}
}

View File

@@ -0,0 +1,70 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template<class traits>
// basic_istream<char,traits>& operator>>(basic_istream<char,traits>&& in, signed char& c);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" ");
std::istream is(&sb);
signed char c = 'z';
is >> c;
assert( is.eof());
assert( is.fail());
assert(c == 'z');
}
{
testbuf<char> sb(" abcdefghijk ");
std::istream is(&sb);
signed char c;
is >> c;
assert(!is.eof());
assert(!is.fail());
assert(c == 'a');
is >> c;
assert(!is.eof());
assert(!is.fail());
assert(c == 'b');
is >> c;
assert(!is.eof());
assert(!is.fail());
assert(c == 'c');
}
}

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template<class traits>
// basic_istream<char,traits>& operator>>(basic_istream<char,traits>&& in, signed char* s);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" abcdefghijk ");
std::istream is(&sb);
signed char s[20];
is >> s;
assert(!is.eof());
assert(!is.fail());
assert(std::string((char*)s) == "abcdefghijk");
}
{
testbuf<char> sb(" abcdefghijk ");
std::istream is(&sb);
is.width(4);
signed char s[20];
is >> s;
assert(!is.eof());
assert(!is.fail());
assert(std::string((char*)s) == "abc");
assert(is.width() == 0);
}
{
testbuf<char> sb(" abcdefghijk");
std::istream is(&sb);
signed char s[20];
is >> s;
assert( is.eof());
assert(!is.fail());
assert(std::string((char*)s) == "abcdefghijk");
assert(is.width() == 0);
}
{
testbuf<char> sb(" abcdefghijk");
std::istream is(&sb);
signed char s[20];
is.width(1);
is >> s;
assert(!is.eof());
assert( is.fail());
assert(std::string((char*)s) == "");
assert(is.width() == 0);
}
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// basic_istream<charT,traits>& operator<<(basic_streambuf<charT,traits>* sb);
#include <istream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
testbuf(const std::basic_string<CharT>& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
testbuf<char> sb("testing...");
std::istream is(&sb);
testbuf<char> sb2;
is >> &sb2;
assert(sb2.str() == "testing...");
assert(is.gcount() == 10);
}
}

View File

@@ -0,0 +1,70 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template<class traits>
// basic_istream<char,traits>& operator>>(basic_istream<char,traits>&& in, unsigned char& c);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" ");
std::istream is(&sb);
unsigned char c = 'z';
is >> c;
assert( is.eof());
assert( is.fail());
assert(c == 'z');
}
{
testbuf<char> sb(" abcdefghijk ");
std::istream is(&sb);
unsigned char c;
is >> c;
assert(!is.eof());
assert(!is.fail());
assert(c == 'a');
is >> c;
assert(!is.eof());
assert(!is.fail());
assert(c == 'b');
is >> c;
assert(!is.eof());
assert(!is.fail());
assert(c == 'c');
}
}

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template<class traits>
// basic_istream<char,traits>& operator>>(basic_istream<char,traits>&& in, unsigned char* s);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" abcdefghijk ");
std::istream is(&sb);
unsigned char s[20];
is >> s;
assert(!is.eof());
assert(!is.fail());
assert(std::string((char*)s) == "abcdefghijk");
}
{
testbuf<char> sb(" abcdefghijk ");
std::istream is(&sb);
is.width(4);
unsigned char s[20];
is >> s;
assert(!is.eof());
assert(!is.fail());
assert(std::string((char*)s) == "abc");
assert(is.width() == 0);
}
{
testbuf<char> sb(" abcdefghijk");
std::istream is(&sb);
unsigned char s[20];
is >> s;
assert( is.eof());
assert(!is.fail());
assert(std::string((char*)s) == "abcdefghijk");
assert(is.width() == 0);
}
{
testbuf<char> sb(" abcdefghijk");
std::istream is(&sb);
unsigned char s[20];
is.width(1);
is >> s;
assert(!is.eof());
assert( is.fail());
assert(std::string((char*)s) == "");
assert(is.width() == 0);
}
}

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template<class charT, class traits>
// basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&& in, charT* s);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" abcdefghijk ");
std::istream is(&sb);
char s[20];
is >> s;
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == "abcdefghijk");
}
{
testbuf<wchar_t> sb(L" abcdefghijk ");
std::wistream is(&sb);
is.width(4);
wchar_t s[20];
is >> s;
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L"abc");
assert(is.width() == 0);
}
{
testbuf<wchar_t> sb(L" abcdefghijk");
std::wistream is(&sb);
wchar_t s[20];
is >> s;
assert( is.eof());
assert(!is.fail());
assert(std::wstring(s) == L"abcdefghijk");
assert(is.width() == 0);
}
{
testbuf<char> sb(" abcdefghijk");
std::istream is(&sb);
char s[20];
is.width(1);
is >> s;
assert(!is.eof());
assert( is.fail());
assert(std::string(s) == "");
assert(is.width() == 0);
}
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits>
// basic_istream<charT,traits>&
// ws(basic_istream<charT,traits>& is);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" 123");
std::istream is(&sb);
ws(is);
assert(is.good());
assert(is.peek() == '1');
}
{
testbuf<wchar_t> sb(L" 123");
std::wistream is(&sb);
ws(is);
assert(is.good());
assert(is.peek() == L'1');
}
}

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits, class T>
// basic_istream<charT, traits>&
// operator>>(basic_istream<charT, traits>&& is, T& x);
#include <istream>
#include <cassert>
#ifdef _LIBCPP_MOVE
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
#endif
int main()
{
#ifdef _LIBCPP_MOVE
{
testbuf<char> sb(" 123");
int i = 0;
std::istream(&sb) >> i;
assert(i == 123);
}
{
testbuf<wchar_t> sb(L" 123");
int i = 0;
std::wistream(&sb) >> i;
assert(i == 123);
}
#endif
}

View File

@@ -0,0 +1,100 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// int_type get();
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" ");
std::istream is(&sb);
char c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == ' ');
assert(is.gcount() == 1);
}
{
testbuf<char> sb(" abc");
std::istream is(&sb);
char c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == ' ');
assert(is.gcount() == 1);
c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == 'a');
assert(is.gcount() == 1);
c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == 'b');
assert(is.gcount() == 1);
c = is.get();
assert( is.eof());
assert(!is.fail());
assert(c == 'c');
assert(is.gcount() == 1);
}
{
testbuf<wchar_t> sb(L" abc");
std::wistream is(&sb);
wchar_t c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == L' ');
assert(is.gcount() == 1);
c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == L'a');
assert(is.gcount() == 1);
c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == L'b');
assert(is.gcount() == 1);
c = is.get();
assert( is.eof());
assert(!is.fail());
assert(c == L'c');
assert(is.gcount() == 1);
}
}

View File

@@ -0,0 +1,103 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& get(char_type& c);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" ");
std::istream is(&sb);
char c;
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == ' ');
assert(is.gcount() == 1);
}
{
testbuf<char> sb(" abc");
std::istream is(&sb);
char c;
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == ' ');
assert(is.gcount() == 1);
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == 'a');
assert(is.gcount() == 1);
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == 'b');
assert(is.gcount() == 1);
is.get(c);
assert( is.eof());
assert(!is.fail());
assert(c == 'c');
assert(is.gcount() == 1);
}
{
testbuf<wchar_t> sb(L" abc");
std::wistream is(&sb);
wchar_t c;
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == L' ');
assert(is.gcount() == 1);
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == L'a');
assert(is.gcount() == 1);
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == L'b');
assert(is.gcount() == 1);
is.get(c);
assert( is.eof());
assert(!is.fail());
assert(c == L'c');
assert(is.gcount() == 1);
}
}

View File

@@ -0,0 +1,99 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& get(char_type* s, streamsize n);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" \n \n ");
std::istream is(&sb);
char s[5];
is.get(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 2);
is.get(s, 5);
assert(!is.eof());
assert( is.fail());
assert(std::string(s) == "");
assert(is.gcount() == 0);
is.clear();
assert(is.get() == '\n');
is.get(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 4);
assert(is.get() == '\n');
is.get(s, 5);
assert( is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 1);
}
{
testbuf<wchar_t> sb(L" \n \n ");
std::wistream is(&sb);
wchar_t s[5];
is.get(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 2);
is.get(s, 5);
assert(!is.eof());
assert( is.fail());
assert(std::wstring(s) == L"");
assert(is.gcount() == 0);
is.clear();
assert(is.get() == L'\n');
is.get(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 4);
assert(is.get() == L'\n');
is.get(s, 5);
assert( is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 1);
}
}

View File

@@ -0,0 +1,99 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& get(char_type* s, streamsize n, char_type delim);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" * * ");
std::istream is(&sb);
char s[5];
is.get(s, 5, '*');
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 2);
is.get(s, 5, '*');
assert(!is.eof());
assert( is.fail());
assert(std::string(s) == "");
assert(is.gcount() == 0);
is.clear();
assert(is.get() == '*');
is.get(s, 5, '*');
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 4);
assert(is.get() == '*');
is.get(s, 5, '*');
assert( is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 1);
}
{
testbuf<wchar_t> sb(L" * * ");
std::wistream is(&sb);
wchar_t s[5];
is.get(s, 5, L'*');
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 2);
is.get(s, 5, L'*');
assert(!is.eof());
assert( is.fail());
assert(std::wstring(s) == L"");
assert(is.gcount() == 0);
is.clear();
assert(is.get() == L'*');
is.get(s, 5, L'*');
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 4);
assert(is.get() == L'*');
is.get(s, 5, L'*');
assert( is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 1);
}
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb);
#include <istream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
testbuf(const std::basic_string<CharT>& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
testbuf<char> sb("testing\n...");
std::istream is(&sb);
testbuf<char> sb2;
is.get(sb2);
assert(sb2.str() == "testing");
assert(is.good());
assert(is.gcount() == 7);
assert(is.get() == '\n');
is.get(sb2);
assert(sb2.str() == "testing...");
assert(is.eof());
assert(!is.fail());
assert(is.gcount() == 3);
}
{
testbuf<wchar_t> sb(L"testing\n...");
std::wistream is(&sb);
testbuf<wchar_t> sb2;
is.get(sb2);
assert(sb2.str() == L"testing");
assert(is.good());
assert(is.gcount() == 7);
assert(is.get() == L'\n');
is.get(sb2);
assert(sb2.str() == L"testing...");
assert(is.eof());
assert(!is.fail());
assert(is.gcount() == 3);
}
}

View File

@@ -0,0 +1,89 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb,
// char_type delim);
#include <istream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
testbuf(const std::basic_string<CharT>& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
testbuf<char> sb("testing*...");
std::istream is(&sb);
testbuf<char> sb2;
is.get(sb2, '*');
assert(sb2.str() == "testing");
assert(is.good());
assert(is.gcount() == 7);
assert(is.get() == '*');
is.get(sb2, '*');
assert(sb2.str() == "testing...");
assert(is.eof());
assert(!is.fail());
assert(is.gcount() == 3);
}
{
testbuf<wchar_t> sb(L"testing*...");
std::wistream is(&sb);
testbuf<wchar_t> sb2;
is.get(sb2, L'*');
assert(sb2.str() == L"testing");
assert(is.good());
assert(is.gcount() == 7);
assert(is.get() == L'*');
is.get(sb2, L'*');
assert(sb2.str() == L"testing...");
assert(is.eof());
assert(!is.fail());
assert(is.gcount() == 3);
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& getline(char_type* s, streamsize n);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" \n \n ");
std::istream is(&sb);
char s[5];
is.getline(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 3);
is.getline(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 5);
is.getline(s, 5);
assert( is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 1);
}
{
testbuf<wchar_t> sb(L" \n \n ");
std::wistream is(&sb);
wchar_t s[5];
is.getline(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 3);
is.getline(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 5);
is.getline(s, 5);
assert( is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 1);
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& getline(char_type* s, streamsize n, char_type delim);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" * * ");
std::istream is(&sb);
char s[5];
is.getline(s, 5, '*');
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 3);
is.getline(s, 5, '*');
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 5);
is.getline(s, 5, '*');
assert( is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 1);
}
{
testbuf<wchar_t> sb(L" * * ");
std::wistream is(&sb);
wchar_t s[5];
is.getline(s, 5, L'*');
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 3);
is.getline(s, 5, L'*');
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 5);
is.getline(s, 5, L'*');
assert( is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 1);
}
}

View File

@@ -0,0 +1,76 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>&
// ignore(streamsize n = 1, int_type delim = traits::eof());
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" 1\n2345\n6");
std::istream is(&sb);
is.ignore();
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 1);
is.ignore(5, '\n');
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 2);
is.ignore(15);
assert( is.eof());
assert(!is.fail());
assert(is.gcount() == 6);
}
{
testbuf<wchar_t> sb(L" 1\n2345\n6");
std::wistream is(&sb);
is.ignore();
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 1);
is.ignore(5, '\n');
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 2);
is.ignore(15);
assert( is.eof());
assert(!is.fail());
assert(is.gcount() == 6);
}
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// int_type peek();
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" 1\n2345\n6");
std::istream is(&sb);
assert(is.peek() == ' ');
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 0);
is.get();
assert(is.peek() == '1');
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 0);
}
{
testbuf<wchar_t> sb(L" 1\n2345\n6");
std::wistream is(&sb);
assert(is.peek() == L' ');
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 0);
is.get();
assert(is.peek() == L'1');
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 0);
}
}

View File

@@ -0,0 +1,89 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& putback(char_type c);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
is.get();
is.get();
is.get();
is.putback('a');
assert(is.bad());
assert(is.gcount() == 0);
is.clear();
is.putback('2');
assert(is.good());
assert(is.gcount() == 0);
is.putback('1');
assert(is.good());
assert(is.gcount() == 0);
is.putback(' ');
assert(is.good());
assert(is.gcount() == 0);
is.putback(' ');
assert(is.bad());
assert(is.gcount() == 0);
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
is.get();
is.get();
is.get();
is.putback(L'a');
assert(is.bad());
assert(is.gcount() == 0);
is.clear();
is.putback(L'2');
assert(is.good());
assert(is.gcount() == 0);
is.putback(L'1');
assert(is.good());
assert(is.gcount() == 0);
is.putback(L' ');
assert(is.good());
assert(is.gcount() == 0);
is.putback(L' ');
assert(is.bad());
assert(is.gcount() == 0);
}
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& read(char_type* s, streamsize n);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
char s[5];
is.read(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s, 5) == " 1234");
assert(is.gcount() == 5);
is.read(s, 5);
assert( is.eof());
assert(!is.fail());
assert(std::string(s, 5) == "56789");
assert(is.gcount() == 5);
is.read(s, 5);
assert( is.eof());
assert( is.fail());
assert(is.gcount() == 0);
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
wchar_t s[5];
is.read(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s, 5) == L" 1234");
assert(is.gcount() == 5);
is.read(s, 5);
assert( is.eof());
assert(!is.fail());
assert(std::wstring(s, 5) == L"56789");
assert(is.gcount() == 5);
is.read(s, 5);
assert( is.eof());
assert( is.fail());
assert(is.gcount() == 0);
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// streamsize readsome(char_type* s, streamsize n);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" 1234567890");
std::istream is(&sb);
char s[5];
assert(is.readsome(s, 5) == 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s, 5) == " 1234");
assert(is.gcount() == 5);
is.readsome(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s, 5) == "56789");
assert(is.gcount() == 5);
is.readsome(s, 5);
assert( is.eof());
assert(!is.fail());
assert(is.gcount() == 1);
assert(std::string(s, 1) == "0");
}
{
testbuf<wchar_t> sb(L" 1234567890");
std::wistream is(&sb);
wchar_t s[5];
assert(is.readsome(s, 5) == 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s, 5) == L" 1234");
assert(is.gcount() == 5);
is.readsome(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s, 5) == L"56789");
assert(is.gcount() == 5);
is.readsome(s, 5);
assert( is.eof());
assert(!is.fail());
assert(is.gcount() == 1);
assert(std::wstring(s, 1) == L"0");
}
}

View File

@@ -0,0 +1,66 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& seekg(pos_type pos);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
protected:
typename base::pos_type seekpos(typename base::pos_type sp,
std::ios_base::openmode which)
{
assert(which == std::ios_base::in);
return sp;
}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
is.seekg(5);
assert(is.good());
is.seekg(-1);
assert(is.fail());
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
is.seekg(5);
assert(is.good());
is.seekg(-1);
assert(is.fail());
}
}

View File

@@ -0,0 +1,68 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& seekg(off_type off, ios_base::seekdir dir);
#include <istream>
#include <cassert>
int seekoff_called = 0;
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
protected:
typename base::pos_type seekoff(typename base::off_type off,
std::ios_base::seekdir way,
std::ios_base::openmode which)
{
assert(which == std::ios_base::in);
++seekoff_called;
return off;
}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
is.seekg(5, std::ios_base::cur);
assert(is.good());
assert(seekoff_called == 1);
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
is.seekg(5, std::ios_base::cur);
assert(is.good());
assert(seekoff_called == 2);
}
}

View File

@@ -0,0 +1,64 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// int sync();
#include <istream>
#include <cassert>
int sync_called = 0;
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
protected:
int sync()
{
++sync_called;
return 5;
}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
assert(is.sync() == 0);
assert(sync_called = 1);
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
assert(is.sync() == 0);
assert(sync_called = 2);
}
}

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// pos_type tellg();
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
protected:
typename base::pos_type seekoff(typename base::off_type off,
std::ios_base::seekdir way,
std::ios_base::openmode which)
{
assert(off == 0);
assert(way == std::ios_base::cur);
assert(which == std::ios_base::in);
return 5;
}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
assert(is.tellg() == 5);
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
assert(is.tellg() == 5);
}
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& unget();
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
is.get();
is.get();
is.get();
is.unget();
assert(is.good());
assert(is.gcount() == 0);
is.unget();
assert(is.good());
assert(is.gcount() == 0);
is.unget();
assert(is.good());
assert(is.gcount() == 0);
is.unget();
assert(is.bad());
assert(is.gcount() == 0);
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
is.get();
is.get();
is.get();
is.unget();
assert(is.good());
assert(is.gcount() == 0);
is.unget();
assert(is.good());
assert(is.gcount() == 0);
is.unget();
assert(is.good());
assert(is.gcount() == 0);
is.unget();
assert(is.bad());
assert(is.gcount() == 0);
}
}

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// void swap(basic_istream& rhs);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
testbuf() {}
};
template <class CharT>
struct test_istream
: public std::basic_istream<CharT>
{
typedef std::basic_istream<CharT> base;
test_istream(testbuf<CharT>* sb) : base(sb) {}
void swap(test_istream& s) {base::swap(s);}
};
int main()
{
{
testbuf<char> sb1;
testbuf<char> sb2;
test_istream<char> is1(&sb1);
test_istream<char> is2(&sb2);
is1.swap(is2);
assert(is1.rdbuf() == &sb1);
assert(is1.tie() == 0);
assert(is1.fill() == ' ');
assert(is1.rdstate() == is1.goodbit);
assert(is1.exceptions() == is1.goodbit);
assert(is1.flags() == (is1.skipws | is1.dec));
assert(is1.precision() == 6);
assert(is1.getloc().name() == "C");
assert(is2.rdbuf() == &sb2);
assert(is2.tie() == 0);
assert(is2.fill() == ' ');
assert(is2.rdstate() == is2.goodbit);
assert(is2.exceptions() == is2.goodbit);
assert(is2.flags() == (is2.skipws | is2.dec));
assert(is2.precision() == 6);
assert(is2.getloc().name() == "C");
}
{
testbuf<wchar_t> sb1;
testbuf<wchar_t> sb2;
test_istream<wchar_t> is1(&sb1);
test_istream<wchar_t> is2(&sb2);
is1.swap(is2);
assert(is1.rdbuf() == &sb1);
assert(is1.tie() == 0);
assert(is1.fill() == ' ');
assert(is1.rdstate() == is1.goodbit);
assert(is1.exceptions() == is1.goodbit);
assert(is1.flags() == (is1.skipws | is1.dec));
assert(is1.precision() == 6);
assert(is1.getloc().name() == "C");
assert(is2.rdbuf() == &sb2);
assert(is2.tie() == 0);
assert(is2.fill() == ' ');
assert(is2.rdstate() == is2.goodbit);
assert(is2.exceptions() == is2.goodbit);
assert(is2.flags() == (is2.skipws | is2.dec));
assert(is2.precision() == 6);
assert(is2.getloc().name() == "C");
}
}

View File

@@ -0,0 +1,92 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// basic_istream& operator=(basic_istream&& rhs);
#include <istream>
#include <cassert>
#ifdef _LIBCPP_MOVE
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
testbuf() {}
};
template <class CharT>
struct test_istream
: public std::basic_istream<CharT>
{
typedef std::basic_istream<CharT> base;
test_istream(testbuf<CharT>* sb) : base(sb) {}
test_istream& operator=(test_istream&& s)
{base::operator=(std::move(s)); return *this;}
};
#endif
int main()
{
#ifdef _LIBCPP_MOVE
{
testbuf<char> sb1;
testbuf<char> sb2;
test_istream<char> is1(&sb1);
test_istream<char> is2(&sb2);
is2 = (std::move(is1));
assert(is1.rdbuf() == &sb1);
assert(is1.tie() == 0);
assert(is1.fill() == ' ');
assert(is1.rdstate() == is1.goodbit);
assert(is1.exceptions() == is1.goodbit);
assert(is1.flags() == (is1.skipws | is1.dec));
assert(is1.precision() == 6);
assert(is1.getloc().name() == "C");
assert(is2.rdbuf() == &sb2);
assert(is2.tie() == 0);
assert(is2.fill() == ' ');
assert(is2.rdstate() == is2.goodbit);
assert(is2.exceptions() == is2.goodbit);
assert(is2.flags() == (is2.skipws | is2.dec));
assert(is2.precision() == 6);
assert(is2.getloc().name() == "C");
}
{
testbuf<wchar_t> sb1;
testbuf<wchar_t> sb2;
test_istream<wchar_t> is1(&sb1);
test_istream<wchar_t> is2(&sb2);
is2 = (std::move(is1));
assert(is1.rdbuf() == &sb1);
assert(is1.tie() == 0);
assert(is1.fill() == ' ');
assert(is1.rdstate() == is1.goodbit);
assert(is1.exceptions() == is1.goodbit);
assert(is1.flags() == (is1.skipws | is1.dec));
assert(is1.precision() == 6);
assert(is1.getloc().name() == "C");
assert(is2.rdbuf() == &sb2);
assert(is2.tie() == 0);
assert(is2.fill() == ' ');
assert(is2.rdstate() == is2.goodbit);
assert(is2.exceptions() == is2.goodbit);
assert(is2.flags() == (is2.skipws | is2.dec));
assert(is2.precision() == 6);
assert(is2.getloc().name() == "C");
}
#endif
}

View File

@@ -0,0 +1,78 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// basic_istream(basic_istream&& rhs);
#include <istream>
#include <cassert>
#ifdef _LIBCPP_MOVE
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
testbuf() {}
};
template <class CharT>
struct test_istream
: public std::basic_istream<CharT>
{
typedef std::basic_istream<CharT> base;
test_istream(testbuf<CharT>* sb) : base(sb) {}
test_istream(test_istream&& s)
: base(std::move(s)) {}
};
#endif
int main()
{
#ifdef _LIBCPP_MOVE
{
testbuf<char> sb;
test_istream<char> is1(&sb);
test_istream<char> is(std::move(is1));
assert(is1.rdbuf() == &sb);
assert(is1.gcount() == 0);
assert(is.gcount() == 0);
assert(is.rdbuf() == 0);
assert(is.tie() == 0);
assert(is.fill() == ' ');
assert(is.rdstate() == is.goodbit);
assert(is.exceptions() == is.goodbit);
assert(is.flags() == (is.skipws | is.dec));
assert(is.precision() == 6);
assert(is.getloc().name() == "C");
}
{
testbuf<wchar_t> sb;
test_istream<wchar_t> is1(&sb);
test_istream<wchar_t> is(std::move(is1));
assert(is1.gcount() == 0);
assert(is.gcount() == 0);
assert(is1.rdbuf() == &sb);
assert(is.rdbuf() == 0);
assert(is.tie() == 0);
assert(is.fill() == L' ');
assert(is.rdstate() == is.goodbit);
assert(is.exceptions() == is.goodbit);
assert(is.flags() == (is.skipws | is.dec));
assert(is.precision() == 6);
assert(is.getloc().name() == "C");
}
#endif
}

View File

@@ -0,0 +1,55 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream;
// explicit basic_istream(basic_streambuf<charT,traits>* sb);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
testbuf() {}
};
int main()
{
{
testbuf<char> sb;
std::basic_istream<char> is(&sb);
assert(is.rdbuf() == &sb);
assert(is.tie() == 0);
assert(is.fill() == ' ');
assert(is.rdstate() == is.goodbit);
assert(is.exceptions() == is.goodbit);
assert(is.flags() == (is.skipws | is.dec));
assert(is.precision() == 6);
assert(is.getloc().name() == "C");
assert(is.gcount() == 0);
}
{
testbuf<wchar_t> sb;
std::basic_istream<wchar_t> is(&sb);
assert(is.rdbuf() == &sb);
assert(is.tie() == 0);
assert(is.fill() == L' ');
assert(is.rdstate() == is.goodbit);
assert(is.exceptions() == is.goodbit);
assert(is.flags() == (is.skipws | is.dec));
assert(is.precision() == 6);
assert(is.getloc().name() == "C");
assert(is.gcount() == 0);
}
}

View File

@@ -0,0 +1,128 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream::sentry;
// explicit sentry(basic_istream<charT,traits>& is, bool noskipws = false);
#include <istream>
#include <cassert>
int sync_called = 0;
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
protected:
int virtual sync()
{
++sync_called;
return 1;
}
};
int main()
{
{
std::istream is((testbuf<char>*)0);
std::istream::sentry sen(is, true);
assert(!(bool)sen);
assert(!is.good());
assert(is.gcount() == 0);
assert(sync_called == 0);
}
{
std::wistream is((testbuf<wchar_t>*)0);
std::wistream::sentry sen(is, true);
assert(!(bool)sen);
assert(!is.good());
assert(is.gcount() == 0);
assert(sync_called == 0);
}
{
testbuf<char> sb(" 123");
std::istream is(&sb);
std::istream::sentry sen(is, true);
assert((bool)sen);
assert(is.good());
assert(is.gcount() == 0);
assert(sync_called == 0);
assert(sb.gptr() == sb.eback());
}
{
testbuf<wchar_t> sb(L" 123");
std::wistream is(&sb);
std::wistream::sentry sen(is, true);
assert((bool)sen);
assert(is.good());
assert(is.gcount() == 0);
assert(sync_called == 0);
assert(sb.gptr() == sb.eback());
}
{
testbuf<char> sb(" 123");
std::istream is(&sb);
std::istream::sentry sen(is);
assert((bool)sen);
assert(is.good());
assert(sync_called == 0);
assert(sb.gptr() == sb.eback() + 3);
}
{
testbuf<wchar_t> sb(L" 123");
std::wistream is(&sb);
std::wistream::sentry sen(is);
assert((bool)sen);
assert(is.good());
assert(sync_called == 0);
assert(sb.gptr() == sb.eback() + 3);
}
{
testbuf<char> sb(" ");
std::istream is(&sb);
std::istream::sentry sen(is);
assert(!(bool)sen);
assert(is.fail());
assert(is.eof());
assert(sync_called == 0);
assert(sb.gptr() == sb.eback() + 6);
}
{
testbuf<char> sb(" ");
std::istream is(&sb);
std::istream::sentry sen(is, true);
assert((bool)sen);
assert(is.good());
assert(sync_called == 0);
assert(sb.gptr() == sb.eback());
}
}

View File

@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
// template <class charT, class traits = char_traits<charT> >
// class basic_istream
// : virtual public basic_ios<charT,traits>
// {
// public:
// // types (inherited from basic_ios (27.5.4)):
// typedef charT char_type;
// typedef traits traits_type;
// typedef typename traits_type::int_type int_type;
// typedef typename traits_type::pos_type pos_type;
// typedef typename traits_type::off_type off_type;
#include <istream>
#include <type_traits>
int main()
{
static_assert((std::is_base_of<std::basic_ios<char>, std::basic_istream<char> >::value), "");
static_assert((std::is_same<std::basic_istream<char>::char_type, char>::value), "");
static_assert((std::is_same<std::basic_istream<char>::traits_type, std::char_traits<char> >::value), "");
static_assert((std::is_same<std::basic_istream<char>::int_type, std::char_traits<char>::int_type>::value), "");
static_assert((std::is_same<std::basic_istream<char>::pos_type, std::char_traits<char>::pos_type>::value), "");
static_assert((std::is_same<std::basic_istream<char>::off_type, std::char_traits<char>::off_type>::value), "");
}

View File

@@ -0,0 +1,20 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <istream>
#include <istream>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// void swap(basic_ostream& rhs);
#include <ostream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
testbuf() {}
};
template <class CharT>
struct test_ostream
: public std::basic_ostream<CharT>
{
typedef std::basic_ostream<CharT> base;
test_ostream(testbuf<CharT>* sb) : base(sb) {}
void swap(test_ostream& s) {base::swap(s);}
};
int main()
{
{
testbuf<char> sb1;
testbuf<char> sb2;
test_ostream<char> os1(&sb1);
test_ostream<char> os2(&sb2);
os1.swap(os2);
assert(os1.rdbuf() == &sb1);
assert(os1.tie() == 0);
assert(os1.fill() == ' ');
assert(os1.rdstate() == os1.goodbit);
assert(os1.exceptions() == os1.goodbit);
assert(os1.flags() == (os1.skipws | os1.dec));
assert(os1.precision() == 6);
assert(os1.getloc().name() == "C");
assert(os2.rdbuf() == &sb2);
assert(os2.tie() == 0);
assert(os2.fill() == ' ');
assert(os2.rdstate() == os2.goodbit);
assert(os2.exceptions() == os2.goodbit);
assert(os2.flags() == (os2.skipws | os2.dec));
assert(os2.precision() == 6);
assert(os2.getloc().name() == "C");
}
{
testbuf<wchar_t> sb1;
testbuf<wchar_t> sb2;
test_ostream<wchar_t> os1(&sb1);
test_ostream<wchar_t> os2(&sb2);
os1.swap(os2);
assert(os1.rdbuf() == &sb1);
assert(os1.tie() == 0);
assert(os1.fill() == ' ');
assert(os1.rdstate() == os1.goodbit);
assert(os1.exceptions() == os1.goodbit);
assert(os1.flags() == (os1.skipws | os1.dec));
assert(os1.precision() == 6);
assert(os1.getloc().name() == "C");
assert(os2.rdbuf() == &sb2);
assert(os2.tie() == 0);
assert(os2.fill() == ' ');
assert(os2.rdstate() == os2.goodbit);
assert(os2.exceptions() == os2.goodbit);
assert(os2.flags() == (os2.skipws | os2.dec));
assert(os2.precision() == 6);
assert(os2.getloc().name() == "C");
}
}

View File

@@ -0,0 +1,92 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// basic_ostream& operator=(basic_ostream&& rhs);
#include <ostream>
#include <cassert>
#ifdef _LIBCPP_MOVE
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
testbuf() {}
};
template <class CharT>
struct test_ostream
: public std::basic_ostream<CharT>
{
typedef std::basic_ostream<CharT> base;
test_ostream(testbuf<CharT>* sb) : base(sb) {}
test_ostream& operator=(test_ostream&& s)
{base::operator=(std::move(s)); return *this;}
};
#endif
int main()
{
#ifdef _LIBCPP_MOVE
{
testbuf<char> sb1;
testbuf<char> sb2;
test_ostream<char> os1(&sb1);
test_ostream<char> os2(&sb2);
os2 = (std::move(os1));
assert(os1.rdbuf() == &sb1);
assert(os1.tie() == 0);
assert(os1.fill() == ' ');
assert(os1.rdstate() == os1.goodbit);
assert(os1.exceptions() == os1.goodbit);
assert(os1.flags() == (os1.skipws | os1.dec));
assert(os1.precision() == 6);
assert(os1.getloc().name() == "C");
assert(os2.rdbuf() == &sb2);
assert(os2.tie() == 0);
assert(os2.fill() == ' ');
assert(os2.rdstate() == os2.goodbit);
assert(os2.exceptions() == os2.goodbit);
assert(os2.flags() == (os2.skipws | os2.dec));
assert(os2.precision() == 6);
assert(os2.getloc().name() == "C");
}
{
testbuf<wchar_t> sb1;
testbuf<wchar_t> sb2;
test_ostream<wchar_t> os1(&sb1);
test_ostream<wchar_t> os2(&sb2);
os2 = (std::move(os1));
assert(os1.rdbuf() == &sb1);
assert(os1.tie() == 0);
assert(os1.fill() == ' ');
assert(os1.rdstate() == os1.goodbit);
assert(os1.exceptions() == os1.goodbit);
assert(os1.flags() == (os1.skipws | os1.dec));
assert(os1.precision() == 6);
assert(os1.getloc().name() == "C");
assert(os2.rdbuf() == &sb2);
assert(os2.tie() == 0);
assert(os2.fill() == ' ');
assert(os2.rdstate() == os2.goodbit);
assert(os2.exceptions() == os2.goodbit);
assert(os2.flags() == (os2.skipws | os2.dec));
assert(os2.precision() == 6);
assert(os2.getloc().name() == "C");
}
#endif
}

View File

@@ -0,0 +1,74 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// basic_ostream(basic_ostream&& rhs);
#include <ostream>
#include <cassert>
#ifdef _LIBCPP_MOVE
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
testbuf() {}
};
template <class CharT>
struct test_ostream
: public std::basic_ostream<CharT>
{
typedef std::basic_ostream<CharT> base;
test_ostream(testbuf<CharT>* sb) : base(sb) {}
test_ostream(test_ostream&& s)
: base(std::move(s)) {}
};
#endif
int main()
{
#ifdef _LIBCPP_MOVE
{
testbuf<char> sb;
test_ostream<char> os1(&sb);
test_ostream<char> os(std::move(os1));
assert(os1.rdbuf() == &sb);
assert(os.rdbuf() == 0);
assert(os.tie() == 0);
assert(os.fill() == ' ');
assert(os.rdstate() == os.goodbit);
assert(os.exceptions() == os.goodbit);
assert(os.flags() == (os.skipws | os.dec));
assert(os.precision() == 6);
assert(os.getloc().name() == "C");
}
{
testbuf<wchar_t> sb;
test_ostream<wchar_t> os1(&sb);
test_ostream<wchar_t> os(std::move(os1));
assert(os1.rdbuf() == &sb);
assert(os.rdbuf() == 0);
assert(os.tie() == 0);
assert(os.fill() == L' ');
assert(os.rdstate() == os.goodbit);
assert(os.exceptions() == os.goodbit);
assert(os.flags() == (os.skipws | os.dec));
assert(os.precision() == 6);
assert(os.getloc().name() == "C");
}
#endif
}

View File

@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// explicit basic_ostream(basic_streambuf<charT,traits>* sb);
#include <ostream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
testbuf() {}
};
int main()
{
{
testbuf<char> sb;
std::basic_ostream<char> os(&sb);
assert(os.rdbuf() == &sb);
assert(os.tie() == 0);
assert(os.fill() == ' ');
assert(os.rdstate() == os.goodbit);
assert(os.exceptions() == os.goodbit);
assert(os.flags() == (os.skipws | os.dec));
assert(os.precision() == 6);
assert(os.getloc().name() == "C");
}
{
testbuf<wchar_t> sb;
std::basic_ostream<wchar_t> os(&sb);
assert(os.rdbuf() == &sb);
assert(os.tie() == 0);
assert(os.fill() == L' ');
assert(os.rdstate() == os.goodbit);
assert(os.exceptions() == os.goodbit);
assert(os.flags() == (os.skipws | os.dec));
assert(os.precision() == 6);
assert(os.getloc().name() == "C");
}
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,91 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// operator<<(bool val);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
bool b = false;
os << b;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
bool b = false;
os << b;
assert(sb.str() == "0");
}
{
testbuf<char> sb;
std::ostream os(&sb);
bool b = true;
os << b;
assert(sb.str() == "1");
}
{
testbuf<char> sb;
std::ostream os(&sb);
boolalpha(os);
bool b = true;
os << b;
assert(sb.str() == "true");
}
{
testbuf<char> sb;
std::ostream os(&sb);
boolalpha(os);
bool b = false;
os << b;
assert(sb.str() == "false");
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// operator<<(double val);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
double n = 0;
os << n;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
double n = 0;
os << n;
assert(sb.str() == "0");
}
{
testbuf<char> sb;
std::ostream os(&sb);
double n = -10;
os << n;
assert(sb.str() == "-10");
}
{
testbuf<char> sb;
std::ostream os(&sb);
hex(os);
double n = -10.5;
os << n;
assert(sb.str() == "-10.5");
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// operator<<(float val);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
float n = 0;
os << n;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
float n = 0;
os << n;
assert(sb.str() == "0");
}
{
testbuf<char> sb;
std::ostream os(&sb);
float n = -10;
os << n;
assert(sb.str() == "-10");
}
{
testbuf<char> sb;
std::ostream os(&sb);
hex(os);
float n = -10.5;
os << n;
assert(sb.str() == "-10.5");
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// operator<<(int val);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
int n = 0;
os << n;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
int n = 0;
os << n;
assert(sb.str() == "0");
}
{
testbuf<char> sb;
std::ostream os(&sb);
int n = -10;
os << n;
assert(sb.str() == "-10");
}
{
testbuf<char> sb;
std::ostream os(&sb);
hex(os);
int n = -10;
os << n;
assert(sb.str() == "fffffff6");
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// operator<<(long val);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
long n = 0;
os << n;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
long n = 0;
os << n;
assert(sb.str() == "0");
}
{
testbuf<char> sb;
std::ostream os(&sb);
long n = -10;
os << n;
assert(sb.str() == "-10");
}
{
testbuf<char> sb;
std::ostream os(&sb);
hex(os);
long n = 0xfffffff6;
os << n;
assert(sb.str() == "fffffff6");
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// operator<<(long double val);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
long double n = 0;
os << n;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
long double n = 0;
os << n;
assert(sb.str() == "0");
}
{
testbuf<char> sb;
std::ostream os(&sb);
long double n = -10;
os << n;
assert(sb.str() == "-10");
}
{
testbuf<char> sb;
std::ostream os(&sb);
hex(os);
long double n = -10.5;
os << n;
assert(sb.str() == "-10.5");
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// operator<<(long long val);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
long long n = 0;
os << n;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
long long n = 0;
os << n;
assert(sb.str() == "0");
}
{
testbuf<char> sb;
std::ostream os(&sb);
long long n = -10;
os << n;
assert(sb.str() == "-10");
}
{
testbuf<char> sb;
std::ostream os(&sb);
hex(os);
long long n = -10;
os << n;
assert(sb.str() == "fffffffffffffff6");
}
}

View File

@@ -0,0 +1,76 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// operator<<(const void* val);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
const void* n = 0;
os << n;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
const void* n = 0;
os << n;
assert(sb.str() == "0x0");
assert(os.good());
}
{
testbuf<char> sb;
std::ostream os(&sb);
const void* n = &sb;
os << n;
assert(os.good());
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// operator<<(short val);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
short n = 0;
os << n;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
short n = 0;
os << n;
assert(sb.str() == "0");
}
{
testbuf<char> sb;
std::ostream os(&sb);
short n = -10;
os << n;
assert(sb.str() == "-10");
}
{
testbuf<char> sb;
std::ostream os(&sb);
hex(os);
short n = -10;
os << n;
assert(sb.str() == "fff6");
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// operator<<(unsigned int val);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
unsigned int n = 0;
os << n;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
unsigned int n = 0;
os << n;
assert(sb.str() == "0");
}
{
testbuf<char> sb;
std::ostream os(&sb);
unsigned int n = 10;
os << n;
assert(sb.str() == "10");
}
{
testbuf<char> sb;
std::ostream os(&sb);
hex(os);
unsigned int n = 0xFFF6;
os << n;
assert(sb.str() == "fff6");
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// operator<<(unsigned long val);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
unsigned long n = 0;
os << n;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
unsigned long n = 0;
os << n;
assert(sb.str() == "0");
}
{
testbuf<char> sb;
std::ostream os(&sb);
unsigned long n = 10;
os << n;
assert(sb.str() == "10");
}
{
testbuf<char> sb;
std::ostream os(&sb);
hex(os);
unsigned long n = 0xfffffff6;
os << n;
assert(sb.str() == "fffffff6");
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// operator<<(unsigned long long val);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
unsigned long long n = 0;
os << n;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
unsigned long long n = 0;
os << n;
assert(sb.str() == "0");
}
{
testbuf<char> sb;
std::ostream os(&sb);
unsigned long long n = 10;
os << n;
assert(sb.str() == "10");
}
{
testbuf<char> sb;
std::ostream os(&sb);
hex(os);
unsigned long long n = -10;
os << n;
assert(sb.str() == "fffffffffffffff6");
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// operator<<(unsigned short val);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
unsigned short n = 0;
os << n;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
unsigned short n = 0;
os << n;
assert(sb.str() == "0");
}
{
testbuf<char> sb;
std::ostream os(&sb);
unsigned short n = 10;
os << n;
assert(sb.str() == "10");
}
{
testbuf<char> sb;
std::ostream os(&sb);
hex(os);
unsigned short n = 0xFFF6;
os << n;
assert(sb.str() == "fff6");
}
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template<class charT, class traits>
// basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out, charT c);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::wostream os((std::wstreambuf*)0);
wchar_t c = L'a';
os << c;
assert(os.bad());
assert(os.fail());
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
wchar_t c = L'a';
os << c;
assert(sb.str() == L"a");
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
os.width(5);
wchar_t c = L'a';
os << c;
assert(sb.str() == L" a");
assert(os.width() == 0);
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
os.width(5);
left(os);
wchar_t c = L'a';
os << c;
assert(sb.str() == L"a ");
assert(os.width() == 0);
}
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template<class charT, class traits>
// basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out, const charT* s);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::wostream os((std::wstreambuf*)0);
const wchar_t* c = L"123";
os << c;
assert(os.bad());
assert(os.fail());
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
const wchar_t* c = L"123";
os << c;
assert(sb.str() == L"123");
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
os.width(5);
const wchar_t* c = L"123";
os << c;
assert(sb.str() == L" 123");
assert(os.width() == 0);
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
os.width(5);
left(os);
const wchar_t* c = L"123";
os << c;
assert(sb.str() == L"123 ");
assert(os.width() == 0);
}
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template<class char, class traits>
// basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out, char c);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
char c = 'a';
os << c;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
char c = 'a';
os << c;
assert(sb.str() == "a");
}
{
testbuf<char> sb;
std::ostream os(&sb);
os.width(5);
char c = 'a';
os << c;
assert(sb.str() == " a");
assert(os.width() == 0);
}
{
testbuf<char> sb;
std::ostream os(&sb);
os.width(5);
left(os);
char c = 'a';
os << c;
assert(sb.str() == "a ");
assert(os.width() == 0);
}
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template<class traits>
// basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out, const char* s);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
const char* c = "123";
os << c;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
const char* c = "123";
os << c;
assert(sb.str() == "123");
}
{
testbuf<char> sb;
std::ostream os(&sb);
os.width(5);
const char* c = "123";
os << c;
assert(sb.str() == " 123");
assert(os.width() == 0);
}
{
testbuf<char> sb;
std::ostream os(&sb);
os.width(5);
left(os);
const char* c = "123";
os << c;
assert(sb.str() == "123 ");
assert(os.width() == 0);
}
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template<class charT, class traits>
// basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out, char c);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::wostream os((std::wstreambuf*)0);
char c = 'a';
os << c;
assert(os.bad());
assert(os.fail());
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
char c = 'a';
os << c;
assert(sb.str() == L"a");
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
os.width(5);
char c = 'a';
os << c;
assert(sb.str() == L" a");
assert(os.width() == 0);
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
os.width(5);
left(os);
char c = 'a';
os << c;
assert(sb.str() == L"a ");
assert(os.width() == 0);
}
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template<class charT, class traits>
// basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out, const char* s);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::wostream os((std::wstreambuf*)0);
const char* c = "123";
os << c;
assert(os.bad());
assert(os.fail());
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
const char* c = "123";
os << c;
assert(sb.str() == L"123");
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
os.width(5);
const char* c = "123";
os << c;
assert(sb.str() == L" 123");
assert(os.width() == 0);
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
os.width(5);
left(os);
const char* c = "123";
os << c;
assert(sb.str() == L"123 ");
assert(os.width() == 0);
}
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template<class char, class traits>
// basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out, signed char c);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
signed char c = 'a';
os << c;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
signed char c = 'a';
os << c;
assert(sb.str() == "a");
}
{
testbuf<char> sb;
std::ostream os(&sb);
os.width(5);
signed char c = 'a';
os << c;
assert(sb.str() == " a");
assert(os.width() == 0);
}
{
testbuf<char> sb;
std::ostream os(&sb);
os.width(5);
left(os);
signed char c = 'a';
os << c;
assert(sb.str() == "a ");
assert(os.width() == 0);
}
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template<class traits>
// basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out, const signed char* s);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
const signed char* c = (const signed char*)"123";
os << c;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
const signed char* c = (const signed char*)"123";
os << c;
assert(sb.str() == "123");
}
{
testbuf<char> sb;
std::ostream os(&sb);
os.width(5);
const signed char* c = (const signed char*)"123";
os << c;
assert(sb.str() == " 123");
assert(os.width() == 0);
}
{
testbuf<char> sb;
std::ostream os(&sb);
os.width(5);
left(os);
const signed char* c = (const signed char*)"123";
os << c;
assert(sb.str() == "123 ");
assert(os.width() == 0);
}
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template<class char, class traits>
// basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out, unsigned char c);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
unsigned char c = 'a';
os << c;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
unsigned char c = 'a';
os << c;
assert(sb.str() == "a");
}
{
testbuf<char> sb;
std::ostream os(&sb);
os.width(5);
unsigned char c = 'a';
os << c;
assert(sb.str() == " a");
assert(os.width() == 0);
}
{
testbuf<char> sb;
std::ostream os(&sb);
os.width(5);
left(os);
unsigned char c = 'a';
os << c;
assert(sb.str() == "a ");
assert(os.width() == 0);
}
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template<class traits>
// basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>& out, const unsigned char* s);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
std::ostream os((std::streambuf*)0);
const unsigned char* c = (const unsigned char*)"123";
os << c;
assert(os.bad());
assert(os.fail());
}
{
testbuf<char> sb;
std::ostream os(&sb);
const unsigned char* c = (const unsigned char*)"123";
os << c;
assert(sb.str() == "123");
}
{
testbuf<char> sb;
std::ostream os(&sb);
os.width(5);
const unsigned char* c = (const unsigned char*)"123";
os << c;
assert(sb.str() == " 123");
assert(os.width() == 0);
}
{
testbuf<char> sb;
std::ostream os(&sb);
os.width(5);
left(os);
const unsigned char* c = (const unsigned char*)"123";
os << c;
assert(sb.str() == "123 ");
assert(os.width() == 0);
}
}

View File

@@ -0,0 +1,70 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// basic_ostream<charT,traits>& operator<<(basic_ios<charT,traits>&
// (*pf)(basic_ios<charT,traits>&));
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
template <class CharT>
std::basic_ios<CharT>&
f(std::basic_ios<CharT>& os)
{
std::uppercase(os);
return os;
}
int main()
{
{
testbuf<char> sb;
std::ostream os(&sb);
assert(!(os.flags() & std::ios_base::uppercase));
os << f;
assert( (os.flags() & std::ios_base::uppercase));
}
}

View File

@@ -0,0 +1,61 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// basic_ostream<charT,traits>& operator<<(ios_base& (*pf)(ios_base&));
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
testbuf<char> sb;
std::ostream os(&sb);
assert(!(os.flags() & std::ios_base::uppercase));
os << std::uppercase;
assert( (os.flags() & std::ios_base::uppercase));
}
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// basic_ostream<charT,traits>& operator<<
// (basic_ostream<charT,traits>& (*pf)(basic_ostream<charT,traits>&))
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
template <class CharT>
std::basic_ostream<CharT>&
f(std::basic_ostream<CharT>& os)
{
os << "testing...";
return os;
}
int main()
{
{
testbuf<char> sb;
std::ostream os(&sb);
os << f;
assert(sb.str() == "testing...");
}
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// basic_ostream<charT,traits>& operator<<(basic_streambuf<charT,traits>* sb);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
testbuf(const std::basic_string<CharT>& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
testbuf<char> sb;
std::ostream os(&sb);
testbuf<char> sb2("testing...");
assert(sb.str() == "");
os << &sb2;
assert(sb.str() == "testing...");
}
}

View File

@@ -0,0 +1,80 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template <class charT, class traits>
// basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
#include <ostream>
#include <cassert>
int sync_called = 0;
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
virtual int
sync()
{
++sync_called;
return 0;
}
};
int main()
{
{
testbuf<char> sb;
std::ostream os(&sb);
endl(os);
assert(sb.str() == "\n");
assert(sync_called == 1);
assert(os.good());
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
endl(os);
assert(sb.str() == L"\n");
assert(sync_called == 2);
assert(os.good());
}
}

View File

@@ -0,0 +1,71 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template <class charT, class traits>
// basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
#include <ostream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
testbuf<char> sb;
std::ostream os(&sb);
ends(os);
assert(sb.str().size() == 1);
assert(sb.str().back() == 0);
assert(os.good());
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
ends(os);
assert(sb.str().size() == 1);
assert(sb.str().back() == 0);
assert(os.good());
}
}

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template <class charT, class traits>
// basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
#include <ostream>
#include <cassert>
int sync_called = 0;
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
public:
testbuf()
{
}
protected:
virtual int
sync()
{
++sync_called;
return 0;
}
};
int main()
{
{
testbuf<char> sb;
std::ostream os(&sb);
flush(os);
assert(sync_called == 1);
assert(os.good());
}
{
testbuf<wchar_t> sb;
std::wostream os(&sb);
flush(os);
assert(sync_called == 2);
assert(os.good());
}
}

View File

@@ -0,0 +1,72 @@
//===----------------------------------------------------------------------===//
//
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <ostream>
// template <class charT, class traits = char_traits<charT> >
// class basic_ostream;
// template <class charT, class traits, class T>
// basic_ostream<charT, traits>&
// operator<<(basic_ostream<charT, traits>&& os, const T& x);
#include <ostream>
#include <cassert>
#ifdef _LIBCPP_MOVE
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
#endif
int main()
{
#ifdef _LIBCPP_MOVE
{
testbuf<char> sb;
std::ostream(&sb) << "testing...";
assert(sb.str() == "testing...");
}
{
testbuf<wchar_t> sb;
std::wostream(&sb) << L"123";
assert(sb.str() == L"123");
}
#endif
}

Some files were not shown because too many files have changed in this diff Show More