array construction without heap alloc

Frank Benoit keinfarbton at googlemail.com
Fri Dec 21 12:25:31 PST 2007


With D1:

I have a function with this unchangable signature:

  void func( int[] a ){} // will not store the array ref

Now i want to pass in some non-const integer values:

  void bar( int a, int b ){
    func( [ a, b ] );
  }

My problem is, i want to do it without heap allocation. So I can do this:

  void bar( int a, int b ){
    int[2] arr;
    arr[0] = a;
    arr[1] = b;
    func( arr );
  }

This works, but the syntax sucks.
Any suggestions?




More information about the Digitalmars-d-learn mailing list