From ab192ca5f18f79420679ee7dfcf1ff59613e1ea3 Mon Sep 17 00:00:00 2001 From: Miutsuru kariya Date: Thu, 13 Jun 2019 08:45:11 +0900 Subject: [PATCH] Make default constructor non-explicit (#48) It is better to support copy-initialization with default constructor. cf. LWG Issue 2193. Default constructors for standard library containers are explicit. --- dynamic_bitset.html | 30 ++++++++++++++----- .../boost/dynamic_bitset/dynamic_bitset.hpp | 4 ++- test/dyn_bitset_unit_tests1.cpp | 5 ++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/dynamic_bitset.html b/dynamic_bitset.html index 82d0b08..b7dbd79 100644 --- a/dynamic_bitset.html +++ b/dynamic_bitset.html @@ -144,8 +144,11 @@ public: typedef bool const_reference; + dynamic_bitset(); + explicit dynamic_bitset(const Allocator& alloc = Allocator()); +"#cons1">dynamic_bitset(const Allocator& alloc); explicit dynamic_bitset(size_type num_bits, unsigned long value = 0, @@ -570,19 +573,30 @@ The maximum value of size_type.
 dynamic_bitset(const Allocator& alloc = Allocator())
+"cons0">dynamic_bitset()
+
+ +Effects: Constructs a bitset of size zero. The allocator +for this bitset is a default-constructed object of type +Allocator.
+ Postconditions: this->size() == 0.
+ Throws: Nothing unless the default constructor of +Allocator throws an exception.
+ (Required by Default +Constructible.) + +
+
+dynamic_bitset(const Allocator& alloc)
 
Effects: Constructs a bitset of size zero. A copy of the alloc object will be used in subsequent bitset operations such as resize to allocate memory.
Postconditions: this->size() == 0.
- Throws: An allocation error if memory is exhausted -(std::bad_alloc if -Allocator=std::allocator).
- (Required by Default -Constructible.) + Throws: nothing.
diff --git a/include/boost/dynamic_bitset/dynamic_bitset.hpp b/include/boost/dynamic_bitset/dynamic_bitset.hpp
index a20e19c..f224051 100644
--- a/include/boost/dynamic_bitset/dynamic_bitset.hpp
+++ b/include/boost/dynamic_bitset/dynamic_bitset.hpp
@@ -128,8 +128,10 @@ public:
     typedef bool const_reference;
 
     // constructors, etc.
+    dynamic_bitset() : m_num_bits(0) {}
+
     explicit
-    dynamic_bitset(const Allocator& alloc = Allocator());
+    dynamic_bitset(const Allocator& alloc);
 
     explicit
     dynamic_bitset(size_type num_bits, unsigned long value = 0,
diff --git a/test/dyn_bitset_unit_tests1.cpp b/test/dyn_bitset_unit_tests1.cpp
index 07f088e..c722701 100644
--- a/test/dyn_bitset_unit_tests1.cpp
+++ b/test/dyn_bitset_unit_tests1.cpp
@@ -517,6 +517,11 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
      bitset_test::max_size(b);
   }
 #endif
+  // Test copy-initialize with default constructor
+  {
+    boost::dynamic_bitset b[1] = {};
+    (void)b;
+  }
 }
 
 int