DR 434.
authorPaolo Carlini <pcarlini@suse.de>
Thu, 18 Nov 2004 09:52:57 +0000 (09:52 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 18 Nov 2004 09:52:57 +0000 (09:52 +0000)
2004-11-18  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.

From-SVN: r90854

libstdc++-v3/ChangeLog
libstdc++-v3/docs/html/ext/howto.html
libstdc++-v3/include/std/std_bitset.h
libstdc++-v3/testsuite/23_containers/bitset/to_string/1.cc [new file with mode: 0644]

index ab9349737de4cf05f0f72174299dc89686b5772c..370044a268a621473ff8edf07d04fa80c56c17ed 100644 (file)
@@ -1,3 +1,11 @@
+2004-11-18  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.
+
 2004-11-17  Paolo Carlini  <pcarlini@suse.de>
 
        * include/bits/istream.tcc (getline(basic_istream<>&, basic_string<>&,
index 5b4a69fb1f76c5739d7e7924c8454538932024e3..194bc5d37c924ed0ea64e568c803d83b5ca98d20 100644 (file)
     <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>
index 3f131aa6df1b6b583836b27bc4b602d474aeba81..fa17a61cec3911ae11da9fe786f7d6f1554a82af 100644 (file)
@@ -1013,12 +1013,6 @@ namespace _GLIBCXX_STD
        *  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 @@ namespace _GLIBCXX_STD
          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 --git a/libstdc++-v3/testsuite/23_containers/bitset/to_string/1.cc b/libstdc++-v3/testsuite/23_containers/bitset/to_string/1.cc
new file mode 100644 (file)
index 0000000..8a75512
--- /dev/null
@@ -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;
+}