This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3, v7-branch] Implement resolution of DR 434


Hi,

seems rather straightforward. Tested x86-linux, committing
to libstdcxx_so_7-branch.

Paolo.

////////////////
2004-11-17  Paolo Carlini  <pcarlini@suse.de>

	DR 434. bitset::to_string() hard to use [Ready]
	* include/std/std_bitset.h (to_string): Add three overloads, taking
	fewer template arguments.
	* docs/html/ext/howto.html: Add an entry for DR 434.
	* testsuite/23_containers/bitset/to_string/1.cc: New.
diff -urN libstdc++-v3-orig/docs/html/ext/howto.html libstdc++-v3/docs/html/ext/howto.html
--- libstdc++-v3-orig/docs/html/ext/howto.html	2004-10-03 18:28:02.000000000 +0200
+++ libstdc++-v3/docs/html/ext/howto.html	2004-11-17 11:39:34.000000000 +0100
@@ -497,6 +497,12 @@
     <dd>Replace &quot;new&quot; with &quot;::new&quot;.
     </dd>
 
+    <dt><a href="lwg-active.html#434">434</a>:
+        <em>bitset::to_string() hard to use</em>
+    </dt>
+    <dd>Add three overloads, taking fewer template arguments.
+    </dd>
+
     <dt><a href="lwg-active.html#453">453</a>:
         <em>basic_stringbuf::seekoff need not always fail for an empty stream</em>
     </dt>
diff -urN libstdc++-v3-orig/include/std/std_bitset.h libstdc++-v3/include/std/std_bitset.h
--- libstdc++-v3-orig/include/std/std_bitset.h	2004-08-17 16:48:49.000000000 +0200
+++ libstdc++-v3/include/std/std_bitset.h	2004-11-17 11:33:19.000000000 +0100
@@ -1013,12 +1013,6 @@
        *  Note the ordering of the bits:  decreasing character positions
        *  correspond to increasing bit positions (see the main class notes for
        *  an example).
-       *
-       *  Also note that you must specify the string's template parameters
-       *  explicitly.  Given a bitset @c bs and a string @s:
-       *  @code
-       *     s = bs.to_string<char,char_traits<char>,allocator<char> >();
-       *  @endcode
        */
       template<class _CharT, class _Traits, class _Alloc>
 	basic_string<_CharT, _Traits, _Alloc>
@@ -1029,6 +1023,22 @@
 	  return __result;
 	}
 
+      // _GLIBCXX_RESOLVE_LIB_DEFECTS
+      // 434. bitset::to_string() hard to use.
+      template<class _CharT, class _Traits>
+	basic_string<_CharT, _Traits, allocator<_CharT> >
+	to_string() const
+	{ return to_string<_CharT, _Traits, allocator<_CharT> >(); }
+
+      template<class _CharT>
+	basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
+	to_string() const
+	{ return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(); }
+
+      basic_string<char, char_traits<char>, allocator<char> >
+      to_string() const
+      { return to_string<char, char_traits<char>, allocator<char> >(); }
+
       // Helper functions for string operations.
       template<class _CharT, class _Traits, class _Alloc>
 	void
diff -urN libstdc++-v3-orig/testsuite/23_containers/bitset/to_string/1.cc libstdc++-v3/testsuite/23_containers/bitset/to_string/1.cc
--- libstdc++-v3-orig/testsuite/23_containers/bitset/to_string/1.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/23_containers/bitset/to_string/1.cc	2004-11-17 11:32:34.000000000 +0100
@@ -0,0 +1,53 @@
+// 2004-11-17  Paolo Carlini  <pcarlini@suse.de>
+
+// Copyright (C) 2004 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 23.3.5.2 bitset members
+
+#include <bitset>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+  using namespace std;
+  bool test __attribute__((unused)) = true;
+
+  bitset<5> b5;
+  string s0 = b5.to_string<char, char_traits<char>, allocator<char> >();
+  VERIFY( s0 == "00000" );
+
+  // DR 434. bitset::to_string() hard to use.
+  b5.set(0);
+  string s1 = b5.to_string<char, char_traits<char> >();
+  VERIFY( s1 == "00001" );
+
+  b5.set(2);
+  string s2 = b5.to_string<char>();
+  VERIFY( s2 == "00101" );
+
+  b5.set(4);
+  string s3 = b5.to_string();
+  VERIFY( s3 == "10101" );
+}
+
+int main()
+{
+  test01();
+  return 0;
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]