changeset 22277:7a6279f4018f

dim_vector: fix type deduction in constructor with parameter pack (patch #9030) * liboctave/array/dim-vector.h: recent rewrite of the multiple constructor changed rules of implicit conversion if arguments were not octave_idx_type (comment #3 on patch #9030). This is because mixed types between the arguments and parameter pack prevented deduction for the implicit initializer list. Fix it by making it explicit.
author Carnë Draug <carandraug@octave.org>
date Thu, 11 Aug 2016 22:02:47 +0100
parents dd0d2a27e5b3
children 3fe6663808cc
files liboctave/array/dim-vector.h
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/array/dim-vector.h	Fri Aug 12 04:52:29 2016 +0100
+++ b/liboctave/array/dim-vector.h	Thu Aug 11 22:02:47 2016 +0100
@@ -28,6 +28,7 @@
 
 #include <cassert>
 
+#include <initializer_list>
 #include <string>
 
 #include "lo-error.h"
@@ -196,17 +197,19 @@
       - a column vector, i.e., assume @f$[N, 1]@f$;
       - a square matrix, i.e., as is common in Octave interpreter;
       - support for a 1 dimensional Array (does not exist);
+
+    Using r, c, and lengths... as arguments, allow us to check at compile
+    time that there's at least 2 dimensions specified, while maintaining
+    type safety.
   */
   template <typename... Ints>
   dim_vector (const octave_idx_type r, const octave_idx_type c,
               Ints... lengths) : rep (newrep (2 + sizeof... (Ints)))
   {
-    // Using r, c, and lengths, makes sure that there's always a min of
-    // 2 dimensions specified, and that lengths are ints (since otherwise
-    // they can't form a list.
-    for (const auto l: {r, c, lengths...})
+    std::initializer_list<octave_idx_type> all_lengths = {r, c, lengths...};
+    for (const octave_idx_type l: all_lengths)
       *rep++ = l;
-    rep -= (2 + sizeof... (Ints));
+    rep -= all_lengths.size ();
   }
 
   octave_idx_type& elem (int i)