C++ Container Library::std::array














































C++ Container Library::std::array



 
In the previous article we have discuss about Introduction to Container Library.If you have not gone through it you see through this link Container Library . In this article we will learn about Array.                              
                  Introduction to Array

The array is a container for constant size arrays. This container wraps around fixed size arrays and also doesn't loose the information of its length when decayed to a pointer.

In order to utilize array, we need to include the array header:

        #include <array> 


Below is the definition of std::array from <array> header file.

template < class T, size_t N >

class array;


         Parameters


  • T - Type of the element contained.

  • T may be substituted by any other data type including user-defined type.

  • N - Size of the array.

    Zero sized arrays are also valid. In that case array.begin() and array.end() points to same location. But behavior of calling front() or back() is undefined.


  • List of  Member types and Member Functions


  • Member types


  • Following member types can be used as parameters or return type by member functions.

    Sr.No.Member typesDefinition
    1value_typeT (First parameter of the template)
    2referencevalue_type&
    3const_referenceconst value_type&
    4pointervalue_type*
    5const_pointerconst value_type*
    6iteratora random access iterator to value_type
    7const_iteratora random access iterator to const value_type
    8reverse_iteratorstd::reverse_iterator <iterator>
    9const_reverse_iteratorstd::reverse_iterator <const_iterator>
    10size_typesize_t
    11difference_typeptrdiff_t

  • Member Function

    Below is list of all methods from <array> header.

    Member functions

    Sr.No.Method & Description
    1array::at

    Returns a reference to the element present at location N in given array container.

    2array::back

    Returns a reference to the last element of the array container.

    3array::begin

    Returns an iterator which points to the start of the array.

    4array::cbegin

    Returns a constant iterator which points to the start of the array.

    5array::cend

    Returns a constant iterator which points to the past-end element of array.

    6array::crbegin

    Returns a constant reverse iterator pointing to the last element of the array.

    7array::crend

    Returns a constant reverse iterator which points to the past-end.

    8array::data

    Return a pointer pointing to the first element of the array container.

    9array::empty

    Tests whether size of array is zero or not.

    10array::end

    Returns an iterator which points to the past-end element of array.

    11array::fill

    Sets given value to all elements of array.

    12array::front

    Returns a reference to the first element of the array container.

    13array::max_size

    Returns the maximum number of elements that can be held by array container.

    14array::operator[]

    Returns a reference to the element present at location N in a given array container.

    15array::rbegin

    Returns a reverse iterator pointing to the last element of the array.

    16array::rend

    Returns a reverse iterator which points to the theoretical element preceding to first element of the array.

    17array::size

    Returns the number of elements present in the array.

    18array::swap

    Swap the contents of the two array.




More Articles of SAYENDEEP MAHANTY:

Name Views Likes
C++ Exception Handling-|| 85 3
C++ Exception Handling 116 3
C++ File Handling EOF 94 5
C++ File Handling Error Handling During file Operation 1135 5
C++ File Handling seekp() Function 105 5
C++ File Handling seekg() Function 105 6
C++ File Handling tellg() Function 127 5
C++ File Handling tellp() Function 133 5
C++ File Handling close() Function 78 5
C++ File Handling:: open() 106 5
C++ File Handling Introduction 131 5
C++ Container Library:: std ::array-II 102 4
Top Django Interview Questions and Answers You Need to Know 303 6
C++ Container Library::std::array 97 6
C++ Container Library Introduction 103 5
Essential Engineering Skills for Your Resume 127 5
Mistakes To Avoid During Technical Interview 133 5
Mistakes You Must Avoid During Work From Home 178 6
Seven Common Mistakes that Beginners Should Avoid While Learning to Code 109 6
Simple Linear Regression 96 6
Python wagtailmenus 123 6
Python wagtail application 119 6
Python guppy GSL 136 5
Python wagtail guppy subpackage heapy 174 6
Python guppy Introduction 215 6
Python wagtail Structural Block 258 6
Python wagtail Integrating into Django Project 370 6
Python wagtail testing 281 7
Python wagtail Basic Block 349 7
Python wagtail image tag 216 7
Python wagtail Templates 179 6
Python wagtail Backends 206 6
Python wagtail Indexing 190 6
Python wagtail Search 173 7
Python wagtail Snippets 192 6
Python wagtail Writing your own page models 165 9
Python wagtail model class PageRevision 196 10
Python wagtail model class Site 199 9
Python wagtail wagtail core model 219 9
Python wagtail page models 189 10
Python wagtail 166 11

Comments