Skip to content

vaahe/std-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STD::ARRAY

The array is a collection of homogeneous objects and this array container is defined for constant size. This container is an aggregate type with the same semantics as a struct holding a C-style array T[N] as its only non-static data member. Unlike a C-style array, it doesn't decay to T* automatically. As an aggregate type, it can be initialized with aggregate-initialization given at most N initializers that are convertible to T: std::array{int, 3} a = {1,2,3};.

This C++ STL array is a kind of sequential container and is not used extremely in regular programming or in competitive programming but sometimes its member function provides an upper edge to it over the regular normal array that we use in our daily life. So, we are discussing some of the important member function that is used with such kind of array:
  • [ ] Operator : This is similar to the normal array, we use it to access the element store at index ‘i’ .
  • front( ) and back( ): These methods are used to access the first and the last element of the array directly.
  • empty( ): This function is used to check whether the declared STL array is empty or not, if it is empty then it returns true else false.
  • at( ): is used to access the element stored at a specific location, if we try to access the element which is out of bounds of the array size then it throws an exception.
  • fill( ): is specially used to initialize or fill all the indexes of the array with a similar value.
  • size( ): is used to get the maximum number of indexes in the array.
  • data( ): returns the pointer to the first element of the array object. Because elements in the array are stored in contiguous memory locations. This data( ) function return us the base address of the string/char type object.
  • front( ): returns a reference to the first element in the container.
  • back( ): returns a reference to the last element in the container.
  • begin( ): returns an iterator to the first element of the array.
  • end( ): returns an iterator to the element following the last element of the array.
  • rbegin( ): returns a reverse iterator to the first element of the reversed array. It corresponds to the last element of the non-reversed array. If the array is empty, the returned iterator is equal to rend().
  • rend( ): returns a reverse iterator to the element following the last element of the reversed array.
  • operator<( ): compares the contents of two arrays.
  • operator<=( ): compares the contents of two arrays.
  • operator>( ): compares the contents of two arrays.
  • operator>=( ): compares the contents of two arrays.
  • operator==( ): compares the contents of two arrays.
  • operator!=( ): compares the contents of two arrays.
  • operator=( ): Copy assignment operator - overwrites every element of the array with the corresponding element of another array.
  • operator( ): Move assignment operator - typically "steal" the resources held by the argument (e.g. pointers to dynamically-allocated objects, file descriptors, TCP sockets, I/O streams, running threads, etc.), rather than make copies of them, and leave the argument in some valid but otherwise indeterminate state.
  • operator<<( ): generates a sequence of characters with the representation of val , properly formatted according to the locale and other formatting settings selected in the stream, and inserts them into the output stream.
  • operator+( ), operator+=( ): are used for adding sum of one array to another array.

Here are how works begin() and end() functions:

begin_end


Here are how works rbegin() and rend() functions(with reverse iterators):

rbegin_rend


Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

About

Implementation of std::array

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published