changeset 23677:66c4d224f7cb

use generic template for construction from standard containers * Cell.h (Cell (const C<V>& container))): New constructor. * Cell.h, Cell.cc (Cell (std::list<std::string>&)): Delete.
author John W. Eaton <jwe@octave.org>
date Thu, 22 Jun 2017 15:08:29 -0400
parents e719f04a5707
children dcba41788495
files libinterp/corefcn/Cell.cc libinterp/corefcn/Cell.h
diffstat 2 files changed, 19 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/Cell.cc	Thu Jun 22 08:22:25 2017 -0400
+++ b/libinterp/corefcn/Cell.cc	Thu Jun 22 15:08:29 2017 -0400
@@ -61,22 +61,6 @@
     }
 }
 
-Cell::Cell (const std::list<std::string>& lst)
-  : Array<octave_value> ()
-{
-  size_t n = lst.size ();
-
-  if (n > 0)
-    {
-      resize (dim_vector (n, 1));
-
-      octave_idx_type i = 0;
-
-      for (const auto& str : lst)
-        elem(i++,0) = str;
-    }
-}
-
 Cell::Cell (const Array<std::string>& sa)
   : Array<octave_value> (sa.dims ())
 {
--- a/libinterp/corefcn/Cell.h	Thu Jun 22 08:22:25 2017 -0400
+++ b/libinterp/corefcn/Cell.h	Thu Jun 22 15:08:29 2017 -0400
@@ -63,7 +63,25 @@
 
   Cell (const string_vector& sv, bool trim = false);
 
-  Cell (const std::list<std::string>& lst);
+  // Constructor for standard containers.  V must be convertible to an
+  // octave_value object.
+  template <typename V, template <typename...> class C>
+  explicit
+  Cell (const C<V>& container)
+    : Array<octave_value> ()
+  {
+    size_t n = container.size ();
+
+    if (n > 0)
+      {
+        resize (dim_vector (n, 1));
+
+        octave_idx_type i = 0;
+
+        for (const auto& val : container)
+          elem(i++,0) = val;
+      }
+  }
 
   Cell (const Array<std::string>& sa);