iomanip (get_money, put_money): Add in C++0x mode; tidy.

2010-03-01  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/std/iomanip (get_money, put_money): Add in C++0x mode; tidy.
	* testsuite/27_io/manipulators/extended/get_money/char/1.cc: New.
	* testsuite/27_io/manipulators/extended/get_money/wchar_t/1.cc:
	Likewise.
	* testsuite/27_io/manipulators/extended/put_money/char/1.cc: Likewise.
	* testsuite/27_io/manipulators/extended/put_money/wchar_t/1.cc:
	Likewise.

From-SVN: r157153
This commit is contained in:
Paolo Carlini 2010-03-01 19:12:39 +00:00 committed by Paolo Carlini
parent 44de0937ab
commit 604b384dd4
6 changed files with 293 additions and 38 deletions

View File

@ -1,3 +1,13 @@
2010-03-01 Paolo Carlini <paolo.carlini@oracle.com>
* include/std/iomanip (get_money, put_money): Add in C++0x mode; tidy.
* testsuite/27_io/manipulators/extended/get_money/char/1.cc: New.
* testsuite/27_io/manipulators/extended/get_money/wchar_t/1.cc:
Likewise.
* testsuite/27_io/manipulators/extended/put_money/char/1.cc: Likewise.
* testsuite/27_io/manipulators/extended/put_money/wchar_t/1.cc:
Likewise.
2010-03-01 Benjamin Kosnik <bkoz@redhat.com>
* include/bits/atomicfwd_cxx.h: Add typedefs to group.

View File

@ -1,7 +1,7 @@
// Standard stream manipulators -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
// 2006, 2007, 2009
// 2006, 2007, 2008, 2009, 2010
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@ -41,6 +41,10 @@
#include <iosfwd>
#include <bits/ios_base.h>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <locale>
#endif
_GLIBCXX_BEGIN_NAMESPACE(std)
// [27.6.3] standard manipulators
@ -57,11 +61,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
inline _Resetiosflags
resetiosflags(ios_base::fmtflags __mask)
{
_Resetiosflags __x;
__x._M_mask = __mask;
return __x;
}
{ return { __mask }; }
template<typename _CharT, typename _Traits>
inline basic_istream<_CharT, _Traits>&
@ -91,11 +91,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
inline _Setiosflags
setiosflags(ios_base::fmtflags __mask)
{
_Setiosflags __x;
__x._M_mask = __mask;
return __x;
}
{ return { __mask }; }
template<typename _CharT, typename _Traits>
inline basic_istream<_CharT, _Traits>&
@ -126,11 +122,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
inline _Setbase
setbase(int __base)
{
_Setbase __x;
__x._M_base = __base;
return __x;
}
{ return { __base }; }
template<typename _CharT, typename _Traits>
inline basic_istream<_CharT, _Traits>&
@ -155,7 +147,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
}
template<typename _CharT>
template<typename _CharT>
struct _Setfill { _CharT _M_c; };
/**
@ -165,14 +157,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* Sent to a stream object, this manipulator calls @c fill(c) for that
* object.
*/
template<typename _CharT>
inline _Setfill<_CharT>
template<typename _CharT>
inline _Setfill<_CharT>
setfill(_CharT __c)
{
_Setfill<_CharT> __x;
__x._M_c = __c;
return __x;
}
{ return { __c }; }
template<typename _CharT, typename _Traits>
inline basic_istream<_CharT, _Traits>&
@ -202,11 +190,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
inline _Setprecision
setprecision(int __n)
{
_Setprecision __x;
__x._M_n = __n;
return __x;
}
{ return { __n }; }
template<typename _CharT, typename _Traits>
inline basic_istream<_CharT, _Traits>&
@ -236,28 +220,97 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
inline _Setw
setw(int __n)
{
_Setw __x;
__x._M_n = __n;
return __x;
}
{ return { __n }; }
template<typename _CharT, typename _Traits>
inline basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, _Setw __f)
{
__is.width(__f._M_n);
{
__is.width(__f._M_n);
return __is;
}
template<typename _CharT, typename _Traits>
inline basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, _Setw __f)
{
__os.width(__f._M_n);
{
__os.width(__f._M_n);
return __os;
}
#ifdef __GXX_EXPERIMENTAL_CXX0X__
template<typename _MoneyT>
struct _Get_money { _MoneyT& _M_mon; bool _M_intl; };
/**
* @brief Extended manipulator for extracting money.
* @param mon Either long double or a specialization of @c basic_string.
* @param intl A bool indicating whether international format
* is to be used.
*
* Sent to a stream object, this manipulator extracts @a mon.
*/
template<typename _MoneyT>
inline _Get_money<_MoneyT>
get_money(_MoneyT& __mon, bool __intl = false)
{ return { __mon, __intl }; }
template<typename _CharT, typename _Traits, typename _MoneyT>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, _Get_money<_MoneyT> __f)
{
typedef istreambuf_iterator<_CharT, _Traits> _Iter;
typedef money_get<_CharT, _Iter> _MoneyGet;
ios_base::iostate __err = ios_base::goodbit;
const _MoneyGet& __mg = use_facet<_MoneyGet>(__is.getloc());
__mg.get(_Iter(__is.rdbuf()), _Iter(), __f._M_intl,
__is, __err, __f._M_mon);
if (ios_base::goodbit != __err)
__is.setstate(__err);
return __is;
}
template<typename _MoneyT>
struct _Put_money { const _MoneyT& _M_mon; bool _M_intl; };
/**
* @brief Extended manipulator for inserting money.
* @param mon Either long double or a specialization of @c basic_string.
* @param intl A bool indicating whether international format
* is to be used.
*
* Sent to a stream object, this manipulator inserts @a mon.
*/
template<typename _MoneyT>
inline _Put_money<_MoneyT>
put_money(const _MoneyT& __mon, bool __intl = false)
{ return { __mon, __intl }; }
template<typename _CharT, typename _Traits, typename _MoneyT>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, _Put_money<_MoneyT> __f)
{
typedef ostreambuf_iterator<_CharT, _Traits> _Iter;
typedef money_put<_CharT, _Iter> _MoneyPut;
const _MoneyPut& __mp = use_facet<_MoneyPut>(__os.getloc());
const _Iter __end = __mp.put(_Iter(__os.rdbuf()), __f._M_intl,
__os, __os.fill(), __f._M_mon);
if (__end.failed())
__os.setstate(ios_base::badbit);
return __os;
}
#endif
// Inhibit implicit instantiations for required instantiations,
// which are defined via explicit instantiations elsewhere.
// NB: This syntax is a GNU extension.

View File

@ -0,0 +1,49 @@
// { dg-options "-std=gnu++0x" }
// { dg-require-namedlocale "" }
// 2010-03-01 Paolo Carlini <paolo.carlini@oracle.com>
// Copyright (C) 2010 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <sstream>
#include <iomanip>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::locale loc_de = std::locale("de_DE@euro");
std::istringstream iss;
iss.imbue(loc_de);
iss.str("7200000000,00 ");
std::string str;
iss >> std::get_money(str);
VERIFY( str == "720000000000" );
VERIFY( iss.eof() );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,49 @@
// { dg-options "-std=gnu++0x" }
// { dg-require-namedlocale "" }
// 2010-03-01 Paolo Carlini <paolo.carlini@oracle.com>
// Copyright (C) 2010 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <sstream>
#include <iomanip>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::locale loc_de = std::locale("de_DE@euro");
std::wistringstream iss;
iss.imbue(loc_de);
iss.str(L"7200000000,00 ");
std::wstring str;
iss >> get_money(str);
VERIFY( str == L"720000000000" );
VERIFY( iss.eof() );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,47 @@
// { dg-options "-std=gnu++0x" }
// { dg-require-namedlocale "" }
// 2010-03-01 Paolo Carlini <paolo.carlini@oracle.com>
// Copyright (C) 2010 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <sstream>
#include <iomanip>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::locale loc_de = std::locale("de_DE@euro");
std::ostringstream oss;
oss.imbue(loc_de);
const std::string str("720000000000");
oss << std::put_money(str);
VERIFY( oss.str() == "7.200.000.000,00 " );
VERIFY( oss.good() );
}
int main()
{
test01();
return 0;
}

View File

@ -0,0 +1,47 @@
// { dg-options "-std=gnu++0x" }
// { dg-require-namedlocale "" }
// 2010-03-01 Paolo Carlini <paolo.carlini@oracle.com>
// Copyright (C) 2010 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <sstream>
#include <iomanip>
#include <testsuite_hooks.h>
void test01()
{
bool test __attribute__((unused)) = true;
std::locale loc_de = std::locale("de_DE@euro");
std::wostringstream oss;
oss.imbue(loc_de);
const std::wstring str(L"720000000000");
oss << std::put_money(str);
VERIFY( oss.str() == L"7.200.000.000,00 " );
VERIFY( oss.good() );
}
int main()
{
test01();
return 0;
}