summaryrefslogtreecommitdiffstats
path: root/libcxx
diff options
context:
space:
mode:
authorHoward Hinnant <hhinnant@apple.com>2010-11-17 21:53:14 +0000
committerHoward Hinnant <hhinnant@apple.com>2010-11-17 21:53:14 +0000
commitd09f711dc23f13a9ea98bfd2583c5f1f7d55523a (patch)
tree96b2f71a4998a524ffdae38379b67da0b9e83dcb /libcxx
parent20d9ce21ef2c43fa1a4acb625c183936276217ba (diff)
downloadbcm5719-llvm-d09f711dc23f13a9ea98bfd2583c5f1f7d55523a.tar.gz
bcm5719-llvm-d09f711dc23f13a9ea98bfd2583c5f1f7d55523a.zip
LWG 1325
llvm-svn: 119571
Diffstat (limited to 'libcxx')
-rw-r--r--libcxx/include/bitset29
-rw-r--r--libcxx/test/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp5
2 files changed, 21 insertions, 13 deletions
diff --git a/libcxx/include/bitset b/libcxx/include/bitset
index 6658d3624e0..a2b8b587848 100644
--- a/libcxx/include/bitset
+++ b/libcxx/include/bitset
@@ -40,7 +40,10 @@ public:
// 23.3.5.1 constructors:
constexpr bitset();
constexpr bitset(unsigned long long val);
- explicit bitset( const char* str );
+ template <class charT>
+ explicit bitset(const charT* str,
+ typename basic_string<charT>::size_type n = basic_string<charT>::npos,
+ charT zero = charT('0'), charT one = charT('1'));
template<class charT, class traits, class Allocator>
explicit bitset(const basic_string<charT,traits,Allocator>& str,
typename basic_string<charT,traits,Allocator>::size_type pos = 0,
@@ -605,7 +608,10 @@ public:
// 23.3.5.1 constructors:
/*constexpr*/ _LIBCPP_INLINE_VISIBILITY bitset() {}
/*constexpr*/ _LIBCPP_INLINE_VISIBILITY bitset(unsigned long long __v) : base(__v) {}
- explicit bitset(const char* __str);
+ template<class _CharT>
+ explicit bitset(const _CharT* __str,
+ typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
+ _CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
template<class _CharT, class _Traits, class _Allocator>
explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
@@ -663,11 +669,14 @@ private:
};
template <size_t _Size>
-bitset<_Size>::bitset(const char* __str)
+template<class _CharT>
+bitset<_Size>::bitset(const _CharT* __str,
+ typename basic_string<_CharT>::size_type __n,
+ _CharT __zero, _CharT __one)
{
- size_t __rlen = strlen(__str);
+ size_t __rlen = _STD::min(__n, char_traits<_CharT>::length(__str));
for (size_t __i = 0; __i < __rlen; ++__i)
- if (__str[__i] != '0' && __str[__i] != '1')
+ if (__str[__i] != __zero && __str[__i] != __one)
#ifndef _LIBCPP_NO_EXCEPTIONS
throw invalid_argument("bitset string ctor has invalid argument");
#else
@@ -677,15 +686,11 @@ bitset<_Size>::bitset(const char* __str)
size_t __i = 0;
for (; __i < _M; ++__i)
{
- switch (__str[_M - 1 - __i])
- {
- case '0':
+ _CharT __c = __str[_M - 1 - __i];
+ if (__c == __zero)
(*this)[__i] = false;
- break;
- case '1':
+ else
(*this)[__i] = true;
- break;
- }
}
_STD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
}
diff --git a/libcxx/test/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp b/libcxx/test/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp
index e1de6146d49..247e15c74aa 100644
--- a/libcxx/test/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp
+++ b/libcxx/test/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp
@@ -7,7 +7,10 @@
//
//===----------------------------------------------------------------------===//
-// test bitset(const char *str);
+// template <class charT>
+// explicit bitset(const charT* str,
+// typename basic_string<charT>::size_type n = basic_string<charT>::npos,
+// charT zero = charT('0'), charT one = charT('1'));
#include <bitset>
#include <cassert>
OpenPOWER on IntegriCloud