D Programming Language 2.0

- Comments
- D
- Search
- Home

Last update Mon May 11 15:11:38 2009

# std.array

bool empty(T)(in T[] a);
  Implements the range interface primitive empty for built-in arrays. Due to the fact that nonmember functions can be called with the first argument using the dot notation, array.empty is equivalent to empty(array).

  Example:

      void main()
      {
          auto a = [ 1, 2, 3 ];
          assert(!a.empty);
          assert(a[3 .. $].empty);
      }

void popFront(T)(ref T[] a);
  Implements the range interface primitive popFront for built-in arrays. Due to the fact that nonmember functions can be called with the first argument using the dot notation, array.popFront is equivalent to popFront(array).

  Example:

      void main()
      {
          int[] a = [ 1, 2, 3 ];
          a.popFront;
          assert(a == [ 2, 3 ]);
      }

void popBack(T)(ref T[] a);
  Implements the range interface primitive popBack for built-in arrays. Due to the fact that nonmember functions can be called with the first argument using the dot notation, array.popBack is equivalent to popBack(array).

  Example:

      void main()
      {
          int[] a = [ 1, 2, 3 ];
          a.popBack;
          assert(a == [ 1, 2 ]);
      }

typeof(A[0]) front(A)(A a);
void front(T)(T[] a, T v);
  Implements the range interface primitive front for built-in arrays. Due to the fact that nonmember functions can be called with the first argument using the dot notation, array.front is equivalent to front(array).

  Example:

      void main()
      {
          int[] a = [ 1, 2, 3 ];
          assert(a.front == 1);
      }

T back(T)(T[] a);
  Implements the range interface primitive back for built-in arrays. Due to the fact that nonmember functions can be called with the first argument using the dot notation, array.back is equivalent to back(array).

  Example:

      void main()
      {
          int[] a = [ 1, 2, 3 ];
          assert(a.front == 1);
      }

void put(T, E)(ref T[] a, E e);
  Implements the range interface primitive put for built-in arrays. Due to the fact that nonmember functions can be called with the first argument using the dot notation, array.put(e) is equivalent to put(array, e).

  Example:

      void main()
      {
          int[] a = [ 1, 2, 3 ];
          int[] b = a;
          a.put(5);
          assert(a == [ 2, 3 ]);
          assert(b == [ 5, 2, 3 ]);
      }

void insert(T, Range)(ref T[] array, size_t pos, Range stuff);
  Inserts stuff in container at position pos.

void replace(T, Range)(ref T[] array, size_t from, size_t to, Range stuff);
  Erases elements from array with indices ranging from from (inclusive) to to (exclusive).

  Erases element from array at index from.

  Replaces elements from array with indices ranging from from (inclusive) to to (exclusive) with the range stuff. Expands or shrinks the array as needed.

struct Appender(A : T[],T);
  Implements an output range that appends data to an array. This is recommended over a ~= data because it is more efficient.

  Example:

      string arr;
      auto app = appender(&arr);
      string b = "abcdefg";
      foreach (char c; b) app.put(c);
      assert(app.data == "abcdefg");

      int[] a = [ 1, 2 ];
      auto app2 = appender(&a);
      app2.put(3);
      app2.put([ 4, 5, 6 ]);
      assert(app2.data == [ 1, 2, 3, 4, 5, 6 ]);

  this(T[]* p);
    Initialize an Appender with a pointer to an existing array. The Appender object will append to this array. If null is passed (or the default constructor gets called), the Appender object will allocate and use a new array.

  T[] data();
    Returns the managed array.

  const size_t capacity();
    Returns the capacity of the array (the maximum number of elements the managed array can accommodate before triggering a reallocation).

  template put(U) if (isImplicitlyConvertible!(U,T) || isSomeString!(T[]) && isSomeString!(U[]))
    Appends one item to the managed array.

    void put(U item);
      Appends one item to the managed array.

  template put(Range) if (isForwardRange!(Range) && is(typeof(Appender.init.put(ElementType!(Range).init))))
    Appends an entire range to the managed array.

    void put(Range items);
      Appends an entire range to the managed array.

  void clear();
    Clears the managed array.

Appender!(E[]) appender(A : E[], E)(A* array = null);
  Convenience function that returns an Appender!(T) object initialized with t.

Copyright © 1999-2009 by Digital Mars, All Rights Reserved | Page generated by Ddoc.