octave-patch-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-patch-tracker] [patch #9030] dim_vector constructor for any numb


From: Carnë Draug
Subject: [Octave-patch-tracker] [patch #9030] dim_vector constructor for any number of dimensions
Date: Thu, 11 Aug 2016 14:55:39 +0000 (UTC)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0

Follow-up Comment #4, patch #9030 (project octave):

Splitting the loop seems to work for me. Does this not work for you (or maybe
I understood your problem incorrectly)?


#include <initializer_list>

class foo
{
public:
  template <typename... Ints>
  foo (const long int r, const long int c, Ints... lengths)
    :rep (new long int [2+sizeof... (Ints)])
  {
    *rep++ = r;
    *rep++ = c;
    for (const long int l: {lengths...})
      *rep++ = l;
    rep -= (2+sizeof... (Ints));
  }
  ~foo () { delete[] rep; }

  long int* rep;
};

int main() {
  int a = 5;
  int b = 6;
  int c = 7;
  foo f (a, b, c);
  return 0;
}


Just an aside: my preferred way to handle this would be a constructor that
takes an initializer list instead of a parameter pack. The problem with that
is that a user could then specify an initializer list with only one value so
we'd need a size check in the constructor. Not only is that an extra check, it
also means the constructor could throw. There should be no need for that
because size of an initializer list is known at compile time. Indeed, c++14
specified it as constexpr so we will be able to use static_assert and a single
initializer_list when we require c++14.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/patch/?9030>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]