get_money.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <iomanip> 11 12// template <class moneyT> T7 get_money(moneyT& mon, bool intl = false); 13 14#include <iomanip> 15#include <cassert> 16 17template <class CharT> 18struct testbuf 19 : public std::basic_streambuf<CharT> 20{ 21 typedef std::basic_string<CharT> string_type; 22 typedef std::basic_streambuf<CharT> base; 23private: 24 string_type str_; 25public: 26 27 testbuf() {} 28 testbuf(const string_type& str) 29 : str_(str) 30 { 31 base::setg(const_cast<CharT*>(str_.data()), 32 const_cast<CharT*>(str_.data()), 33 const_cast<CharT*>(str_.data()) + str_.size()); 34 } 35}; 36 37int main() 38{ 39 { 40 testbuf<char> sb(" -$1,234,567.89"); 41 std::istream is(&sb); 42 is.imbue(std::locale("en_US")); 43 long double x = 0; 44 is >> std::get_money(x, false); 45 assert(x == -123456789); 46 } 47 { 48 testbuf<char> sb(" -USD 1,234,567.89"); 49 std::istream is(&sb); 50 is.imbue(std::locale("en_US")); 51 long double x = 0; 52 is >> std::get_money(x, true); 53 assert(x == -123456789); 54 } 55 { 56 testbuf<wchar_t> sb(L" -$1,234,567.89"); 57 std::wistream is(&sb); 58 is.imbue(std::locale("en_US")); 59 long double x = 0; 60 is >> std::get_money(x, false); 61 assert(x == -123456789); 62 } 63 { 64 testbuf<wchar_t> sb(L" -USD 1,234,567.89"); 65 std::wistream is(&sb); 66 is.imbue(std::locale("en_US")); 67 long double x = 0; 68 is >> std::get_money(x, true); 69 assert(x == -123456789); 70 } 71} 72