Class Range

Range is a class that defines an interval of items, such as an interval of characters in a string or ints in a vector. Range has members first and size. They uniquely define the interval. First is the position (or index) of the first item belonging to the interval, and size is the length of the interval. First and size must be non-negative numbers. You may omit giving the size parameter, which means that you want the interval span till the string (or vector etc.) end.

Range is an auxiliar class. For instance, it is given as a parameter in string methods to limit the search in a specific range, or it is given as a parameter for vector method remove, to specify the range to be removed.

CONSTRUCTION

COMPARISION

OTHER METHODS

Example

main
  string s = "abcdef"

  // Specify range consisting of characters 'b', 'c' and 'd'
  range r = 1 size 3

  // Specify range consisting of all characters starting from 'c'
  r = 2 to s.get size

  // Use range in the string methods for instance
  s[r] = ""
  print s                           // LOG: ab
            

(range) <int first> size <int size>

Creates a new range with the given first position and size.

Parameters

Exceptions

Example

main
  range r = 0 size 10       // Includes 10 elements, starting from the first element
            

(range) <int first> to <int last>

Creates a new range from the given first position up to the last element.

Parameters

Exceptions

Example

main
  range r = 5 to 10    // Includes 6 elements, starting from element at index 5.
            

(range) <int first> to end

Creates a new range with the given first position. The range consists all elements starting at 'first' till end

Parameters

Exceptions

(range) <range sourceRange>.copy

Creates a new range that is an exact copy of sourceRange.

Parameters

Return value

Example

main
  range r1 = 0 size 10
  range r2 = r1.copy         // Includes 10 elements, starting from the first element
            

(bool) <range r1> == <range r2>

Comparision

Parameters

Return value

Example

main
  range r1 = 0 size 10
  range r2 = 5 to 10
  bool result = r1 == r2    // result == false
            

(bool) <range r1> != <range r2>

Comparision

Parameters

Return value

Example

main
  range r1 = 0 size 10
  range r2 = 5 to 10    
  bool result = r1 != r2    // result == true
            

(int) get first

Get the value of the first position.

Return value

Example

main
  range r = 0 size 10
  int firstElement = r.get first    // firstElement == 0
            

(int) get size

Get the value of the size.

Return value

Example

main
  range r = 5 to 10
  int size = r.get size    // size == 6
            

set first to <int newFirst>

Assing a new value for the first position.

Parameters

Exceptions

Example

main
  range r = 0 size 10       // Includes 10 elements, starting from the first element
  r.set first to 1          // Includes 9 elements, starting from element at index 1
            

set size to <int newSize>

Assing a new value for the size.

Parameters

Exceptions

Example

main
  range r = 0 size 10       // Includes 10 elements, starting from the first element
  r.set size to 5           // Includes 5 elements, starting from the first element