$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r53789 - trunk/boost/multi_array
From: garcia_at_[hidden]
Date: 2009-06-10 16:27:13
Author: garcia
Date: 2009-06-10 16:27:13 EDT (Wed, 10 Jun 2009)
New Revision: 53789
URL: http://svn.boost.org/trac/boost/changeset/53789
Log:
Fixed asserts in generate_array_view to properly handle negative strides.
Text files modified: 
   trunk/boost/multi_array/base.hpp |    27 +++++++++++++++++----------             
   1 files changed, 17 insertions(+), 10 deletions(-)
Modified: trunk/boost/multi_array/base.hpp
==============================================================================
--- trunk/boost/multi_array/base.hpp	(original)
+++ trunk/boost/multi_array/base.hpp	2009-06-10 16:27:13 EDT (Wed, 10 Jun 2009)
@@ -436,17 +436,24 @@
       const index_range& current_range = indices.ranges_[n];
       index start = current_range.get_start(default_start);
       index finish = current_range.get_finish(default_finish);
-      index index_factor = current_range.stride();
+      index factor = current_range.stride();
 
-      // integral trick for ceiling((finish-start) / index_factor)
-      index shrinkage = index_factor > 0 ? 1 : -1;
-      index len = (finish - start + (index_factor - shrinkage)) / index_factor;
+      // integral trick for ceiling((finish-start) / factor) 
+      index shrinkage = factor > 0 ? 1 : -1;
+      index len = (finish - start + (factor - shrinkage)) / factor;
 
       BOOST_ASSERT(index_bases[n] <= start &&
-                   start <= index_bases[n]+index(extents[n]));
-      BOOST_ASSERT(index_bases[n] <= finish &&
-                   finish <= index_bases[n]+index(extents[n]));
-      BOOST_ASSERT(index_factor != 0);
+                   start < index_bases[n]+index(extents[n]));
+
+#ifndef BOOST_DISABLE_ASSERTS
+      // The legal values of finish depends on the sign of the factor
+      index lb_adjustment = factor < 0 ? 1 : 0;
+      index ub_adjustment = factor > 0 ? 1 : 0;
+      BOOST_ASSERT(index_bases[n] - lb_adjustment <= finish &&
+                   finish < index_bases[n]+index(extents[n]) + ub_adjustment);
+#endif // BOOST_DISABLE_ASSERTS
+
+      BOOST_ASSERT(factor != 0);
 
       // the array data pointer is modified to account for non-zero
       // bases during slicing (see [Garcia] for the math involved)
@@ -454,9 +461,9 @@
 
       if (!current_range.is_degenerate()) {
 
-        // The index_factor for each dimension is included into the
+        // The factor for each dimension is included into the
         // strides for the array_view (see [Garcia] for the math involved).
-        new_strides[dim] = index_factor * strides[n];
+        new_strides[dim] = factor * strides[n];
         
         // calculate new extents
         new_extents[dim] = len;