[cfe-commits] [libcxx] r116404 - /libcxx/trunk/include/random

Howard Hinnant hhinnant at apple.com
Wed Oct 13 07:37:09 PDT 2010


Author: hhinnant
Date: Wed Oct 13 09:37:09 2010
New Revision: 116404

URL: http://llvm.org/viewvc/llvm-project?rev=116404&view=rev
Log:
Patch by Marshall Clow to make the assignment operators of piecewise_constant_distribution and piecewise_linear_distribution exception safe.

Modified:
    libcxx/trunk/include/random

Modified: libcxx/trunk/include/random
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/random?rev=116404&r1=116403&r2=116404&view=diff
==============================================================================
--- libcxx/trunk/include/random (original)
+++ libcxx/trunk/include/random Wed Oct 13 09:37:09 2010
@@ -5938,6 +5938,7 @@
         template<class _UnaryOperation>
             param_type(size_t __nw, result_type __xmin, result_type __xmax,
                        _UnaryOperation __fw);
+        param_type & operator=(const param_type& __rhs);
 
         _LIBCPP_INLINE_VISIBILITY
         vector<result_type> intervals() const {return __b_;}
@@ -6048,6 +6049,23 @@
 };
 
 template<class _RealType>
+typename piecewise_constant_distribution<_RealType>::param_type &
+piecewise_constant_distribution<_RealType>::param_type::operator=
+                                                       (const param_type& __rhs)
+{
+//  These can throw
+    __b_.reserve        (__rhs.__b_.size ());
+    __densities_.reserve(__rhs.__densities_.size());
+    __areas_.reserve    (__rhs.__areas_.size());
+
+//  These can not throw
+    __b_         = __rhs.__b_;
+    __densities_ = __rhs.__densities_;
+    __areas_     =  __rhs.__areas_;
+    return *this;
+}
+
+template<class _RealType>
 void
 piecewise_constant_distribution<_RealType>::param_type::__init()
 {
@@ -6239,7 +6257,8 @@
         template<class _UnaryOperation>
             param_type(size_t __nw, result_type __xmin, result_type __xmax,
                        _UnaryOperation __fw);
-
+        param_type & operator=(const param_type& __rhs);
+        
         _LIBCPP_INLINE_VISIBILITY
         vector<result_type> intervals() const {return __b_;}
         _LIBCPP_INLINE_VISIBILITY
@@ -6349,6 +6368,24 @@
 };
 
 template<class _RealType>
+typename piecewise_linear_distribution<_RealType>::param_type &
+piecewise_linear_distribution<_RealType>::param_type::operator=
+                                                       (const param_type& __rhs)
+{
+//  These can throw
+    __b_.reserve        (__rhs.__b_.size ());
+    __densities_.reserve(__rhs.__densities_.size());
+    __areas_.reserve    (__rhs.__areas_.size());
+
+//  These can not throw
+    __b_         = __rhs.__b_;
+    __densities_ = __rhs.__densities_;
+    __areas_     =  __rhs.__areas_;
+    return *this;
+}
+
+
+template<class _RealType>
 void
 piecewise_linear_distribution<_RealType>::param_type::__init()
 {





More information about the cfe-commits mailing list