#include <FixedArray.h>
Public Types | |
STL container requirements. | |
typedef Types::value_type | value_type |
The element type of the array. | |
typedef Types::parameter_type | parameter_type |
The parameter type for the value type. | |
typedef Types::pointer | pointer |
A pointer to an array element. | |
typedef Types::const_pointer | const_pointer |
A const pointer to an array element. | |
typedef Types::iterator | iterator |
An iterator in the array. | |
typedef Types::const_iterator | const_iterator |
A const iterator in the array. | |
typedef Types::reference | reference |
A reference to an array element. | |
typedef Types::const_reference | const_reference |
A const reference to an array element. | |
typedef Types::size_type | size_type |
The size type is a signed integer. | |
typedef Types::difference_type | difference_type |
Pointer difference type. | |
Public Member Functions | |
Constructors etc. | |
The size and element type are template parameters. One can use the default constructor, FixedArray(), to make an array of uninitialized elements. The default element type is double. Below is an array of double's. Note that since the size is a template parameter, it must be known at compile time. The following would generate a compile time error. int n; std::cin >> n; ads::FixedArray<n,int> a; | |
FixedArray () | |
Default constructor. Leave the data uninitialized. | |
~FixedArray () | |
Trivial destructor. | |
FixedArray (const FixedArray &x) | |
Copy constructor. | |
template<typename T2> | |
FixedArray (const FixedArray< N, T2 > &x) | |
Copy constructor for a FixedArray of different type. | |
FixedArray (parameter_type x) | |
Constructor. Specify an initializing value for the components. | |
FixedArray (const const_pointer p) | |
Constructor. Initialize from a C array of the value type. | |
FixedArray (const void *p) | |
Constructor. Initialize from a block of memory. | |
FixedArray (parameter_type x0, parameter_type x1) | |
Constructor. Specify the two components. | |
FixedArray (parameter_type x0, parameter_type x1, parameter_type x2) | |
Constructor. Specify the three components. | |
FixedArray (parameter_type x0, parameter_type x1, parameter_type x2, parameter_type x3) | |
Constructor. Specify the four components. | |
FixedArray (parameter_type x0, parameter_type x1, parameter_type x2, parameter_type x3, parameter_type x4) | |
Constructor. Specify the five components. | |
FixedArray (parameter_type x0, parameter_type x1, parameter_type x2, parameter_type x3, parameter_type x4, parameter_type x5) | |
Constructor. Specify the six components. | |
FixedArray (parameter_type x0, parameter_type x1, parameter_type x2, parameter_type x3, parameter_type x4, parameter_type x5, parameter_type x6) | |
Constructor. Specify the seven components. | |
FixedArray (parameter_type x0, parameter_type x1, parameter_type x2, parameter_type x3, parameter_type x4, parameter_type x5, parameter_type x6, parameter_type x7) | |
Constructor. Specify the eight components. | |
Assignment operators. | |
FixedArray & | operator= (const FixedArray &x) |
Assignment operator. | |
template<typename T2> | |
FixedArray & | operator= (const FixedArray< N, T2 > &x) |
Assignment operator for a FixedArray of different type. | |
template<typename T2, bool A> | |
FixedArray & | operator= (const Array< 1, T2, A > &x) |
Assignment operator for an Array. | |
FixedArray & | operator= (parameter_type x) |
Assignment operator. Assign from a value. | |
Accessors. | |
const_iterator | begin () const |
Return a const_iterator to the beginning of the data. | |
const_iterator | end () const |
Return a const_iterator to the end of the data. | |
const_pointer | data () const |
Return a const_pointer to the data. | |
parameter_type | operator() (const int i) const |
Subscripting. Return the i_th component. | |
parameter_type | operator[] (const int i) const |
Subscripting. Return the i_th component. | |
template<typename EqualityComparable> | |
const_iterator | find (const EqualityComparable &x) const |
Linear search for x . | |
template<typename EqualityComparable> | |
int | find_index (const EqualityComparable &x) const |
Linear search for x . Return the index of the matching element. | |
template<typename EqualityComparable> | |
bool | has (const EqualityComparable &x) const |
Return true if this array has the element x . | |
bool | is_sorted () const |
Return true if the array is in sorted order. | |
template<class StrictWeakOrdering> | |
bool | is_sorted (StrictWeakOrdering comp) const |
Return true if the array is in sorted order. | |
int | min_index () const |
Return the index of the minimum element. | |
template<class StrictWeakOrdering> | |
int | min_index (StrictWeakOrdering comp) const |
Return the index of the minimum element using the comparison functor. | |
int | max_index () const |
Return the index of the maximum element. | |
template<class StrictWeakOrdering> | |
int | max_index (StrictWeakOrdering comp) const |
Return the index of the maximum element using the comparison functor. | |
Manipulators. | |
iterator | begin () |
Return an iterator to the beginning of the data. | |
iterator | end () |
Return an iterator to the end of the data. | |
pointer | data () |
Return a pointer to the data. | |
reference | operator() (const int i) |
Subscripting. Return a reference to the i_th component. | |
reference | operator[] (const int i) |
Subscripting. Return a reference to the i_th component. | |
void | swap (FixedArray &x) |
Swaps data with another FixedArray of the same size and type. | |
template<typename EqualityComparable> | |
iterator | find (const EqualityComparable &x) |
Linear search for x . | |
void | negate () |
Negate each component. | |
void | fill (parameter_type value) |
Fill the array with the given value . | |
template<typename InputIterator> | |
void | copy (InputIterator start, InputIterator finish) |
Copy the specified range into the array. | |
void | sort () |
Sort the elements of the array. | |
template<class StrictWeakOrdering> | |
void | sort (StrictWeakOrdering comp) |
Sort the elements of the array. | |
Assignment operators with scalar operand. | |
FixedArray & | operator+= (parameter_type x) |
Add x to each component. | |
FixedArray & | operator-= (parameter_type x) |
Subtract x from each component. | |
FixedArray & | operator *= (parameter_type x) |
Multiply each component by x . | |
FixedArray & | operator/= (parameter_type x) |
Divide each component by x . | |
FixedArray & | operator%= (parameter_type x) |
Mod each component by x . | |
FixedArray & | operator<<= (int offset) |
Left-shift each component by the offset . | |
FixedArray & | operator>>= (int offset) |
Right-shift each component by the offset . | |
Assignment operators with FixedArray operand. | |
template<typename T2> | |
FixedArray & | operator+= (const FixedArray< N, T2 > &x) |
Add x to this. | |
template<typename T2> | |
FixedArray & | operator-= (const FixedArray< N, T2 > &x) |
Subtract x from this. | |
template<typename T2> | |
FixedArray & | operator *= (const FixedArray< N, T2 > &x) |
Multiply this by x . | |
template<typename T2> | |
FixedArray & | operator/= (const FixedArray< N, T2 > &x) |
Divide this by x . | |
template<typename T2> | |
FixedArray & | operator%= (const FixedArray< N, T2 > &x) |
Mod this by x . | |
Static Public Member Functions | |
Static members. | |
static size_type | size () |
Return the size of the array. | |
static bool | empty () |
Return true if the array has zero size. | |
static size_type | max_size () |
Return the size of the largest possible FixedArray. | |
Related Functions | |
(Note that these are not member functions.) | |
FixedArray< N, T > & | operator+ (FixedArray< N, T > &x) |
Unary positive operator. | |
FixedArray< N, T > | operator- (const FixedArray< N, T > &x) |
Unary negate operator. | |
FixedArray< N, T > | operator+ (const FixedArray< N, T > &x, const typename FixedArray< N, T >::parameter_type value) |
FixedArray-scalar addition. | |
FixedArray< N, T > | operator+ (const typename FixedArray< N, T >::parameter_type value, const FixedArray< N, T > &x) |
Scalar-FixedArray addition. | |
FixedArray< N, T > | operator+ (const FixedArray< N, T > &x, const FixedArray< N, T > &y) |
FixedArray-FixedArray addition. | |
FixedArray< N, T > | operator- (const FixedArray< N, T > &x, const typename FixedArray< N, T >::parameter_type value) |
FixedArray-scalar subtraction. | |
FixedArray< N, T > | operator- (const typename FixedArray< N, T >::parameter_type value, const FixedArray< N, T > &x) |
Scalar-FixedArray subtraction. | |
FixedArray< N, T > | operator- (const FixedArray< N, T > &x, const FixedArray< N, T > &y) |
FixedArray-FixedArray subtraction. | |
FixedArray< N, T > | operator * (const FixedArray< N, T > &x, const typename FixedArray< N, T >::parameter_type value) |
FixedArray-scalar multiplication. | |
FixedArray< N, T > | operator * (const typename FixedArray< N, T >::parameter_type value, const FixedArray< N, T > &x) |
Scalar-FixedArray multiplication. | |
FixedArray< N, T > | operator * (const FixedArray< N, T > &x, const FixedArray< N, T > &y) |
FixedArray-FixedArray multiplication. | |
FixedArray< N, T > | operator/ (const FixedArray< N, T > &x, const typename FixedArray< N, T >::parameter_type value) |
FixedArray-scalar division. | |
FixedArray< N, T > | operator/ (const typename FixedArray< N, T >::parameter_type value, const FixedArray< N, T > &x) |
Scalar-FixedArray division. | |
FixedArray< N, T > | operator/ (const FixedArray< N, T > &x, const FixedArray< N, T > &y) |
FixedArray-FixedArray division. | |
FixedArray< N, T > | operator% (const FixedArray< N, T > &x, const typename FixedArray< N, T >::parameter_type value) |
FixedArray-scalar modulus. | |
FixedArray< N, T > | operator% (const typename FixedArray< N, T >::parameter_type value, const FixedArray< N, T > &x) |
Scalar-FixedArray modulus. | |
FixedArray< N, T > | operator% (const FixedArray< N, T > &x, const FixedArray< N, T > &y) |
FixedArray-FixedArray modulus. | |
T | computeSum (const FixedArray< N, T > &x) |
Return the sum of the components. | |
T | computeProduct (const FixedArray< N, T > &x) |
Return the product of the components. | |
T | computeMinimum (const FixedArray< N, T > &x) |
Return the minimum component. Use < for comparison. | |
T | computeMaximum (const FixedArray< N, T > &x) |
Return the maximum component. Use > for comparison. | |
FixedArray< N, T > | computeMaximum (const FixedArray< N, T > &x, const FixedArray< N, T > &y) |
Return a FixedArray that is element-wise the maximum of the two. | |
FixedArray< N, T > | computeMinimum (const FixedArray< N, T > &x, const FixedArray< N, T > &y) |
Return a FixedArray that is element-wise the minimum of the two. | |
void | applyAbs (FixedArray< N, T > *x) |
Apply the absolute value (![]() | |
void | applyAcos (FixedArray< N, T > *x) |
Apply the inverse cosine (![]() | |
void | applyAsin (FixedArray< N, T > *x) |
Apply the inverse sine (![]() | |
void | applyAtan (FixedArray< N, T > *x) |
Apply the inverse tangent (![]() | |
void | applyCeil (FixedArray< N, T > *x) |
Apply the ceiling function (![]() | |
void | applyCos (FixedArray< N, T > *x) |
Apply the cosine (![]() | |
void | applyCosh (FixedArray< N, T > *x) |
Apply the hyperbolic cosine (![]() | |
void | applyExp (FixedArray< N, T > *x) |
Apply the exponential function (![]() | |
void | applyFloor (FixedArray< N, T > *x) |
Apply the floor function (![]() | |
void | applyLog (FixedArray< N, T > *x) |
Apply the natural logarithm (![]() | |
void | applyLog10 (FixedArray< N, T > *x) |
Apply the logarithm base 10 (![]() | |
void | applySin (FixedArray< N, T > *x) |
Apply the sine (![]() | |
void | applySinh (FixedArray< N, T > *x) |
Apply the hyperbolic sine (![]() | |
void | applySqrt (FixedArray< N, T > *x) |
Apply the square root (![]() | |
void | applyTan (FixedArray< N, T > *x) |
Apply the tangent (![]() | |
void | applyTanh (FixedArray< N, T > *x) |
Apply the hyperbolic tangent (![]() | |
FixedArray< N, T > | abs (FixedArray< N, T > x) |
Return the absolute value (![]() | |
FixedArray< N, T > | acos (FixedArray< N, T > x) |
Return the inverse cosine (![]() | |
FixedArray< N, T > | asin (FixedArray< N, T > x) |
Return the inverse sine (![]() | |
FixedArray< N, T > | atan (FixedArray< N, T > x) |
Return the inverse tangent (![]() | |
FixedArray< N, T > | ceil (FixedArray< N, T > x) |
Return the ceiling function (![]() | |
FixedArray< N, T > | cos (FixedArray< N, T > x) |
Return the cosine (![]() | |
FixedArray< N, T > | cosh (FixedArray< N, T > x) |
Return the hyperbolic cosine (![]() | |
FixedArray< N, T > | exp (FixedArray< N, T > x) |
Return the exponential function (![]() | |
FixedArray< N, T > | floor (FixedArray< N, T > x) |
Return the floor function (![]() | |
FixedArray< N, T > | log (FixedArray< N, T > x) |
Return the natural logarithm (![]() | |
FixedArray< N, T > | log10 (FixedArray< N, T > x) |
Return the logarithm base 10 (![]() | |
FixedArray< N, T > | sin (FixedArray< N, T > x) |
Return the sine (![]() | |
FixedArray< N, T > | sinh (FixedArray< N, T > x) |
Return the hyperbolic sine (![]() | |
FixedArray< N, T > | sqrt (FixedArray< N, T > x) |
Return the square root (![]() | |
FixedArray< N, T > | tan (FixedArray< N, T > x) |
Return the tangent (![]() | |
FixedArray< N, T > | tanh (FixedArray< N, T > x) |
Return the hyperbolic tangent (![]() | |
bool | operator== (const FixedArray< N, T1 > &a, const FixedArray< N, T2 > &b) |
Return true if the arrays are equal. | |
bool | operator!= (const FixedArray< N, T1 > &a, const FixedArray< N, T2 > &b) |
Return true if the arrays are not equal. | |
bool | operator< (const FixedArray< N, T1 > &a, const FixedArray< N, T2 > &b) |
Lexicographical less than comparison. | |
bool | operator> (const FixedArray< N, T1 > &a, const FixedArray< N, T2 > &b) |
Lexicographical greater than comparison. | |
bool | operator<= (const FixedArray< N, T1 > &a, const FixedArray< N, T2 > &b) |
Lexicographical less than or equal to comparison. | |
bool | operator>= (const FixedArray< N, T1 > &a, const FixedArray< N, T2 > &b) |
Lexicographical greater than or equal to comparison. | |
std::ostream & | operator<< (std::ostream &out, const FixedArray< N, T > &p) |
Write an array as space-separated numbers. | |
std::istream & | operator>> (std::istream &in, FixedArray< N, T > &p) |
Read white space-separated numbers into an array. | |
void | write_elements_binary (std::ostream &out, const FixedArray< N, T > &x) |
Write the array elements in binary format. | |
void | read_elements_binary (std::istream &in, FixedArray< N, T > &x) |
Read the array elements in binary format. |
N | is the size of the array. N must be positive. | |
T | is the value type of the array. By default it is double. |
The array supports indexing and mathematical operations. The indices are in the range . This class does not have any virtual functions. The memory usage of the array is N times the size of the value type T.
Through partial template specialization, there are optimized versions of this class for N = 0, 1, 2 and 3.
typedef Types::size_type ads::FixedArray< N, T >::size_type |
The size type is a signed integer.
Having std::size_t
(which is an unsigned integer) as the size type causes minor problems. Consult "Large Scale C++ Software Design" by John Lakos for a discussion of using unsigned integers in a class interface.
ads::FixedArray< N, T >::FixedArray | ( | parameter_type | x0, | |
parameter_type | x1 | |||
) |
Constructor. Specify the two components.
ads::FixedArray< N, T >::FixedArray | ( | parameter_type | x0, | |
parameter_type | x1, | |||
parameter_type | x2 | |||
) |
Constructor. Specify the three components.
ads::FixedArray< N, T >::FixedArray | ( | parameter_type | x0, | |
parameter_type | x1, | |||
parameter_type | x2, | |||
parameter_type | x3 | |||
) |
Constructor. Specify the four components.
ads::FixedArray< N, T >::FixedArray | ( | parameter_type | x0, | |
parameter_type | x1, | |||
parameter_type | x2, | |||
parameter_type | x3, | |||
parameter_type | x4 | |||
) |
Constructor. Specify the five components.
ads::FixedArray< N, T >::FixedArray | ( | parameter_type | x0, | |
parameter_type | x1, | |||
parameter_type | x2, | |||
parameter_type | x3, | |||
parameter_type | x4, | |||
parameter_type | x5 | |||
) |
Constructor. Specify the six components.
ads::FixedArray< N, T >::FixedArray | ( | parameter_type | x0, | |
parameter_type | x1, | |||
parameter_type | x2, | |||
parameter_type | x3, | |||
parameter_type | x4, | |||
parameter_type | x5, | |||
parameter_type | x6 | |||
) |
Constructor. Specify the seven components.
ads::FixedArray< N, T >::FixedArray | ( | parameter_type | x0, | |
parameter_type | x1, | |||
parameter_type | x2, | |||
parameter_type | x3, | |||
parameter_type | x4, | |||
parameter_type | x5, | |||
parameter_type | x6, | |||
parameter_type | x7 | |||
) |
Constructor. Specify the eight components.
iterator ads::FixedArray< N, T >::find | ( | const EqualityComparable & | x | ) | [inline] |
const_iterator ads::FixedArray< N, T >::find | ( | const EqualityComparable & | x | ) | const [inline] |
int ads::FixedArray< N, T >::find_index | ( | const EqualityComparable & | x | ) | const [inline] |
Linear search for x
. Return the index of the matching element.
If the element is not in the array, return size()
.