js4cpp
Bunch of C++ classes with JavaScript flavor
 All Classes Namespaces Files Functions Pages
Public Member Functions
js4cpp::Array< T > Class Template Reference

#include <array.hpp>

List of all members.

Public Member Functions

 Array (size_t length=0)
template<class InputIterator >
 Array (InputIterator begin, InputIterator end)
T & operator[] (size_t i)
ssize_t indexOf (const T &item) const
void push (const T &value)
void unshift (const T &value)
T pop ()
T shift ()
void reverse ()
Array< T > slice (ssize_t begin, ssize_t end=0) const
void sort (std::tr1::function< bool(const T &, const T &)> comparator=std::less< T >())
void forEach (std::tr1::function< void(T &)> callback)
template<typename R >
Array< R > map (std::tr1::function< R(const T &)> callback) const
bool every (std::tr1::function< bool(const T &)> condition) const
bool some (std::tr1::function< bool(const T &)> condition) const
Array< T > filter (std::tr1::function< bool(const T &)> test) const
T reduce (std::tr1::function< T(const T &, const T &)> callback=std::plus< T >()) const
T reduce (std::tr1::function< T(const T &, const T &)> callback, const T &initialValue, size_t startFrom=0) const
size_t length () const

Detailed Description

template<typename T>
class js4cpp::Array< T >

JS-style array.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array
Template Parameters:
TArray's elements type.

Constructor & Destructor Documentation

template<typename T>
js4cpp::Array< T >::Array ( size_t  length = 0)
inlineexplicit

Create new array with given preallocated length.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array#Syntax
Parameters:
lengthLength.
template<typename T>
template<class InputIterator >
js4cpp::Array< T >::Array ( InputIterator  begin,
InputIterator  end 
)
inline

Create new array from iterators range.

Template Parameters:
InputIteratorIterator.
Parameters:
beginRange's begin.
endRange's end.

Member Function Documentation

template<typename T>
bool js4cpp::Array< T >::every ( std::tr1::function< bool(const T &)>  condition) const
inline

Tests whether all elements in the array pass the test implemented by the provided function.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/every
Parameters:
conditionTest implementation.
Returns:
true if all elements passed the test and false otherwise.
template<typename T>
Array<T> js4cpp::Array< T >::filter ( std::tr1::function< bool(const T &)>  test) const
inline

Create new array consists of only this array's elements passed the test.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/filter
Parameters:
testTest implementation.
Returns:
New array.
template<typename T>
void js4cpp::Array< T >::forEach ( std::tr1::function< void(T &)>  callback)
inline

Iterate over all elements and call callback for every one.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach
Parameters:
callbackCallback.
template<typename T>
ssize_t js4cpp::Array< T >::indexOf ( const T &  item) const
inline

Get index of given item.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf
Parameters:
itemItem index of which we want to find out.
Returns:
Item's index or -1 if item does not exist in the array.
template<typename T>
size_t js4cpp::Array< T >::length ( ) const
inline
template<typename T>
template<typename R >
Array<R> js4cpp::Array< T >::map ( std::tr1::function< R(const T &)>  callback) const
inline

Creates a new array with the results of calling a provided function on every element in this array.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map
Template Parameters:
RNew array's element type.
Parameters:
callbackFunction generates new array's element from this array's one.
Returns:
New array.
template<typename T>
T& js4cpp::Array< T >::operator[] ( size_t  i)
inline

Get element under given index.

Parameters:
iIndex.
Returns:
Element.
template<typename T>
T js4cpp::Array< T >::pop ( )
inline

Remove one element from the end of the array.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/pop
Returns:
Removed element.
template<typename T>
void js4cpp::Array< T >::push ( const T &  value)
inline

Push value to the end of array.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/push
Parameters:
valueValue to be pushed.
template<typename T>
T js4cpp::Array< T >::reduce ( std::tr1::function< T(const T &, const T &)>  callback = std::plus<T>()) const
inline

Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/reduce
Parameters:
callbackFunction to execute on each value in the array.
Returns:
Accumulated value.
template<typename T>
T js4cpp::Array< T >::reduce ( std::tr1::function< T(const T &, const T &)>  callback,
const T &  initialValue,
size_t  startFrom = 0 
) const
inline

Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/reduce
Parameters:
callbackFunction to execute on each value in the array.
initialValueAccumulator initial value.
startFromIndex from which iteration will start.
Returns:
Accumulated value.
template<typename T>
void js4cpp::Array< T >::reverse ( )
inline
template<typename T>
T js4cpp::Array< T >::shift ( )
inline

Remove element from the end of the array.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/shift
Returns:
Removed element.
template<typename T>
Array<T> js4cpp::Array< T >::slice ( ssize_t  begin,
ssize_t  end = 0 
) const
inline

Create subarray bounded by begin and end indexes.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/slice
Parameters:
beginBegin index.
endEnd index. If not specified, subarray will be bounded at the end by length of original array.
Returns:
Subarray.
template<typename T>
bool js4cpp::Array< T >::some ( std::tr1::function< bool(const T &)>  condition) const
inline

Tests whether any of elements in the array pass the test implemented by the provided function.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/some
Parameters:
conditionTest implementation.
Returns:
true if at least one element passed the test and false otherwise.
template<typename T>
void js4cpp::Array< T >::sort ( std::tr1::function< bool(const T &, const T &)>  comparator = std::less<T>())
inline

Rearrange elements by given comparator.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort
Parameters:
comparatorComparator.
template<typename T>
void js4cpp::Array< T >::unshift ( const T &  value)
inline

Insert value just before the first element of the array.

See also:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/unshift
Parameters:
valueValue to be inserted.

The documentation for this class was generated from the following file: