Search for:
C++ Library – iterator

C++ Library &-8211; iterator &-8211; this Article or News was published on this date:2019-05-12 18:21:57 kindly share it with friends if you find it helpful

C++ Library &-8211; iterator>


Advertisements


Introduction

It is a pointer-like object that can be incremented with ++, dereferenced with *, and compared against another iterator with !=

Categories

category properties valid expressions
all categories copy-constructible,
copy-assignable and destructible
X b(a);

b = a;

It can be incremented ++a

a++

Random Access Bidirectional Forward Input It supports equality/inequality comparisons a == b

a != b

It can be dereferenced as an rvalue *a

a->m

Output It can be dereferenced as an lvalue

(only for mutable iterator types)

*a = t

*a++ = t

default-constructible X a;

X()

Multi-pass: neither dereferencing nor incrementing affects dereferenceability { b = a; *a++; *b; }
It can be decremented --a

a&-8211;

*a&-8211;

It supports arithmetic operators
+
and
-
a + n

n + a

a &-8211; n

a &-8211; b

It supports inequality comparisons (
,
>,
= and
>=) between iterators
a b

a > b

a = b

a >= b

It supports compound assignment operations
+= and
-=

a += n

a -= n

It supports offset dereference operator ([]) a[n]

Functions

Sr.No. Functions & Description
1 advance

It advances the iterator it by n element positions.

2 distance

It returns distance between iterators.

3 begin

It is used to begin an iterator.

4 end

It is used to end an iterator.

5 prev

It is used to get iterator to previous element.

6 next

It is used to get iterator to next element.

Iterator generators

!&-8211;

&-8211;>

Sr.No. Iterator generators & Description
1 back_inserter

It constructs back insert iterator.

2 front_inserter

It constructs front insert iterator.

2 inserter

It constructs insert iterator

3 make_move_iterator

It construct move iterators.

Classes

Sr.No. Classes & Description
1 iterator

It iterators base class.

2 iterator_traits

It is an iterator traits.

Predefined iterators

Sr.No. Predefined iterators & Description
1 reverse_iterator

It is a reverse iterator.

2 move_iterator

It is a move iterator.

3 back_insert_iterator

It is a back insert iterator.

4 front_insert_iterator

It is a front insert iterator.

5 insert_iterator

It is used to insert an iterator.

6 istream_iterator

It is an input stream iterator.

7 ostream_iterator

It is an output stream iterator.

8 istreambuf_iterator

It is an input stream buffer iterator.

7 ostreambuf_iterator

It is an output stream buffer iterator.

Category tags

Sr.No. Category tags & Description
1 input_iterator_tag

Input iterator category.

2 output_iterator_tag

output iterator category.

3 forward_iterator_tag

Forward iterator category.

4 bidirectional_iterator_tag

Bidirectional iterator category.

5 random_access_iterator_tag

Random-access iterator category.



Advertisements

The C Standard Library

C++ Library &-8211; Home

C++ Library &-8211; fstream>

C++ Library &-8211; iomanip>

C++ Library &-8211; ios>

C++ Library &-8211; iosfwd>

C++ Library &-8211; iostream>

C++ Library &-8211; istream>

C++ Library &-8211; ostream>

C++ Library &-8211; sstream>

C++ Library &-8211; streambuf>

C++ Library &-8211; atomic>

C++ Library &-8211; complex>

C++ Library &-8211; exception>

C++ Library &-8211; functional>

C++ Library &-8211; limits>

C++ Library &-8211; locale>

C++ Library &-8211; memory>

C++ Library &-8211; new>

C++ Library &-8211; numeric>

C++ Library &-8211; regex>

C++ Library &-8211; stdexcept>

C++ Library &-8211; string>

C++ Library &-8211; thread>

C++ Library &-8211; tuple>

C++ Library &-8211; typeinfo>

C++ Library &-8211; utility>

C++ Library &-8211; valarray>

C++ Library &-8211; array>

C++ Library &-8211; bitset>

C++ Library &-8211; deque>

C++ Library &-8211; forward_list>

C++ Library &-8211; list>

C++ Library &-8211; map>

C++ Library &-8211; queue>

C++ Library &-8211; set>

C++ Library &-8211; stack>

C++ Library &-8211; unordered_map>

C++ Library &-8211; unordered_set>

C++ Library &-8211; vector>

C++ Library &-8211; algorithm>

C++ Library &-8211; iterator>

C++ Programming Tutorial

C++ Useful Resources

C++ Discussion

UPSC IAS Exams Notes

Developer&-8217;s Best Practices

Questions and Answers

Effective Resume Writing

HR Interview Questions

Computer Glossary

Who is Who

C++ Library – algorithm

C++ Library &-8211; algorithm &-8211; this Article or News was published on this date:2019-05-12 18:21:56 kindly share it with friends if you find it helpful

C++ Library &-8211; algorithm>


Advertisements


Introduction to algorithm

The algorithm library provides several functions that can be used for a variety of purposes, for instance searching, sorting, counting, manipulating and so on. These functions operate on ranges of elements and the range is defined as [first, last).

Functions from algorithm>

Below is list of all methods from algorithm> header.

Member functions

Sr.No. Method & Description
1 algorithm::adjacent_find()

Finds the first occurrence of two consecutive elements that are identical and returns an iterator pointing to the first element if identical element exists consecutively otherwise returns an iterator pointing to the last element.

2 algorithm::adjacent_find()

Finds the first occurrence of two consecutive elements that are identical and returns an iterator pointing to the first element if identical element exists consecutively otherwise returns an iterator pointing to the last element.

3 algorithm::all_of()

Returns true if predicate returns true for all the elements in the range of first to last.

4 algorithm::any_of()

Returns true if predicate returns true for any of the elements in the range of first to last.

5 algorithm::binary_search()

Tests whether value exists in sorted sequence or not.

6 algorithm::binary_search()

Tests whether value exists in sorted sequence or not.

7 algorithm::copy()

Copies a range of elements to a new location.

8 algorithm::copy_backward()

Copies a range of elements to a new location in backward order.

9 algorithm::copy_if()

Copies a range of elements to a new location if predicate returns true for value.

10 algorithm::copy_n()

Copies first n numbers to a new location.

11 algorithm::count()

Returns the number of occurrences of value in range.

12 algorithm::count_if()

Returns the number of occurrences of value from range that satisfies condition.

13 algorithm::equal()

Tests whether two sets of element are equal or not.

14 algorithm::equal()

Tests whether two sets of element are equal or not.

15 algorithm::equal_range()

Returns a range of element that matches specific key.

16 algorithm::equal_range()

Returns a range of element that matches specific key.

17 algorithm::fill()

Assigns certain value to a range of elements.

18 algorithm::fill_n()

Assigns value to the first n elements of the sequence pointed by first.

19 algorithm::fill_n()

Assigns value to the first n elements of the sequence pointed by first.

20 algorithm::find()

Finds the first occurrence of the element.

21 algorithm::find_end()

Finds the last occurrence of the element.

22 algorithm::find_end()

Finds the last occurrence of the element.

23 algorithm::find_first_of()

Returns an iterator to the first element in the range of (first1,last1) that matches any of the elements in first2,last2.

24 algorithm::find_first_of()

Returns an iterator to the first element in the range of (first1,last1) that matches any of the elements in first2,last2.

25 algorithm::find_if()

Finds the first occurrence of the element that satisfies the condition.

26 algorithm::find_if_not()

Finds the last occurrence of the element that satisfies the condition.

27 algorithm::for_each()

Applies provided function on each element of the range.

28 algorithm::generate()

Assigns the value returned by successive calls to gen to the elements in the range of first to last.

29 algorithm::generate_n()

Assigns the value returned by successive calls to gen to the first n elements of the sequence pointed by the first.

30 algorithm::generate_n()

Assigns the value returned by successive calls to gen to the first n elements of the sequence pointed by the first.

31 algorithm::includes()

Test whether first set is subset of another or not.

32 algorithm::includes()

Test whether first set is subset of another or not.

33 algorithm::inplace_merge()

Merges two sorted sequence in-place.

34 algorithm::inplace_merge()

Merges two sorted sequence in-place.

35 algorithm::is_heap()

Tests whether given sequence is max heap or not.

36 algorithm::is_heap()

Tests whether given sequence is max heap or not.

37 algorithm::is_heap_until()

Finds the first element from the sequence which violates the max heap condition.

38 algorithm::is_heap_until()

Finds the first element from the sequence which violates the max heap condition.

39 algorithm::is_partitioned()

Tests whether range is partitioned or not.

40 algorithm::is_permutation()

Tests whether a sequence is permutation of other or not.

41 algorithm::is_permutation()

Tests whether a sequence is permutation of other or not.

42 algorithm::is_sorted()

Tests whether range is sorted or not.

43 algorithm::is_sorted()

Tests whether range is sorted or not.

44 algorithm::is_sorted_until()

Finds first unsorted element from the sequence.

45 algorithm::is_sorted_until()

Finds first unsorted element from the sequence.

46 algorithm::iter_swap()

Exchange values of objects pointed by two iterators.

47 algorithm::lexicographical_compare()

Tests whether one range is lexicographically less than another or not.

48 algorithm::lexicographical_compare()

Tests whether one range is lexicographically less than another or not.

49 algorithm::lower_bound()

Finds the first element not less than the given value.

50 algorithm::lower_bound()

Finds the first element not less than the given value.



Advertisements

The C Standard Library

C++ Library &-8211; Home

C++ Library &-8211; fstream>

C++ Library &-8211; iomanip>

C++ Library &-8211; ios>

C++ Library &-8211; iosfwd>

C++ Library &-8211; iostream>

C++ Library &-8211; istream>

C++ Library &-8211; ostream>

C++ Library &-8211; sstream>

C++ Library &-8211; streambuf>

C++ Library &-8211; atomic>

C++ Library &-8211; complex>

C++ Library &-8211; exception>

C++ Library &-8211; functional>

C++ Library &-8211; limits>

C++ Library &-8211; locale>

C++ Library &-8211; memory>

C++ Library &-8211; new>

C++ Library &-8211; numeric>

C++ Library &-8211; regex>

C++ Library &-8211; stdexcept>

C++ Library &-8211; string>

C++ Library &-8211; thread>

C++ Library &-8211; tuple>

C++ Library &-8211; typeinfo>

C++ Library &-8211; utility>

C++ Library &-8211; valarray>

C++ Library &-8211; array>

C++ Library &-8211; bitset>

C++ Library &-8211; deque>

C++ Library &-8211; forward_list>

C++ Library &-8211; list>

C++ Library &-8211; map>

C++ Library &-8211; queue>

C++ Library &-8211; set>

C++ Library &-8211; stack>

C++ Library &-8211; unordered_map>

C++ Library &-8211; unordered_set>

C++ Library &-8211; vector>

C++ Library &-8211; algorithm>

C++ Library &-8211; iterator>

C++ Programming Tutorial

C++ Useful Resources

C++ Discussion

UPSC IAS Exams Notes

Developer&-8217;s Best Practices

Questions and Answers

Effective Resume Writing

HR Interview Questions

Computer Glossary

Who is Who

C++ Library – vector

C++ Library &-8211; vector &-8211; this Article or News was published on this date:2019-05-12 18:21:55 kindly share it with friends if you find it helpful

C++ Library &-8211; vector>


Advertisements


Introduction

Vectors are sequence container that can change size. Container is a objects that hold data of same type. Sequence containers store elements strictly in linear sequence.

Vector stores elements in contiguous memory locations and enables direct access to any element using subscript operator []. Unlike array, vector can shrink or expand as needed at run time. The storage of the vector is handled automatically.

To support shrink and expand functionality at runtime, vector container may allocate some extra storage to accommodate for possible growth thus container have actual capacity greater than the size. Therefore, compared to array, vector consumes more memory in exchange for the ability to manage storage and grow dynamically in an efficient way.

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

Definition

Below is definition of std::vector from vector> header file

template  class T, class Alloc = allocatorT> > class vector;

Parameters

  • T − Type of the element contained.

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

  • Alloc − Type of allocator object.

    By default, the allocator class template is used, which defines the simplest memory allocation model and is value-independent.

Member types

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

Sr.No. Member types Definition
1 value_type T (First parameter of the template)
2 allocator_type Alloc (Second parameter of the template)
3 reference value_type&
4 const_reference const value_type&
5 pointer value_type*
6 const_pointer const value_type*
7 iterator a random access iterator to value_type
8 const_iterator a random access iterator to const value_type
9 reverse_iterator std::reverse_iterator iterator>
10 const_reverse_iterator std::reverse_iterator const_iterator>
11 size_type size_t
12 difference_type ptrdiff_t

Functions from vector>

Below is list of all methods from vector> header.

Constructors

Sr.No. Method & Description
1 vector::vector default constructor

Constructs an empty container, with zero elements.

2 vector::vector fill constructor

Constructs a container with n elements and assignd val to each element.

3 vector::vector range constructor

Constructs a container with as many elements in range of first to last.

4 vector::vector copy constructor

Constructs a container with copy of each elements present in existing container x.

5 vector::vector move constructor

Constructs the container with the contents of other using move semantics.

6 vector::vector initializer list constructor

Constructs a container from initializer list.

Destructor

Sr.No. Method & Description
1 vector::~vector

Destroys container by deallocating container memory.

Member functions

Sr.No. Method & Description
1 vector::assign fill version

Assign new values to the vector elements by replacing old ones.

2 vector::assign range version

Assign new values to the vector elements by replacing old ones.

3 vector::assign initializer list version

Assign new values to the vector elements by replacing old ones.

4 vector::at

Returns reference to the element present at location n in the vector.

5 vector::back

Returns a reference to the last element of the vector.

6 vector::begin

Return a random access iterator pointing to the first element of the vector.

7 vector::capacity

Returns the size of allocate storage, expressed in terms of elements.

8 vector::cbegin

Returns a constant random access iterator which points to the beginning of the vector.

9 vector::cend

Returns a constant random access iterator which points to the beginning of the vector.

10 vector::clear

Destroys the vector by removing all elements from the vector and sets size of vector to zero.

11 vector::crbegin

Returns a constant reverse iterator which points to the reverser beginning of the container.

12 vector::crend

Returns a constant reverse iterator which points to the reverse end of the vector.

13 vector::data

Returns a pointer to the first element of the vector container.

14 vector::emplace

Extends container by inserting new element at position.

15 vector::emplace_back

Inserts new element at the end of vector.

16 vector::empty

Tests whether vector is empty or not.

17 vector::end

Returns an iterator which points to past-the-end element in the vector container.

18 vector::erase position version

Removes single element from the the vector.

19 vector::erase range version

Removes single element from the the vector.

20 vector::front

Returns a reference to the first element of the vector.

21 vector::get_allocator

Returns an allocator associated with vector.

22 vector::insert single element version

Extends iterator by inserting new element at position.

23 vector::insert fill version

Extends vector by inserting new element in the container.

24 vector::insert range version

Extends vector by inserting new element in the container.

25 vector::insert move version

Extends vector by inserting new element in the container.

26 vector::insert initializer list version

Extends vector by inserting new element in the container.

27 vector::max_size

Returns the maximum number of elements can be held by vector.

28 vector::operator= copy version

Assign new contents to the vector by replacing old ones and modifies size if necessary.

29 vector::operator= move version

Assign new contents to the vector by replacing old ones and modifies size if necessary.

30 vector::operator = initializer list version

Assign new contents to the vector by replacing old ones and modifies size if necessary.

31 vector::operator[]

Returns a reference to the element present at location n.

32 vector::pop_back

Removes last element from vector and reduces size of vector by one.

33 vector::push_back

Inserts new element at the end of vector and increases size of vector by one.

34 vector::rbegin

Returns a reverse iterator which points to the last element of the vector.

35 vector::rend

Returns a reverse iterator which points to the reverse end of the vector.

36 vector::reserve

Requests to reserve vector capacity be at least enough to contain n elements.

37 vector::resize

Changes the size of vector.

38 vector::shrink_to_fit

Requests the container to reduce it&-8217;s capacity to fit its size.

39 vector::size

Returns the number of elements present in the vector.

40 vector::swap

Exchanges the content of vector with contents of vector x.

Non-member overloaded functions

Sr.No. Method & Description
1 operator ==

Tests whether two vectors are equal or not.

2 operator !=

Tests whether two vectors are equal or not.

3 operator

Tests whether first vector is less than other or not.

4 operator =

Tests whether first vector is less than or equal to other or not.

5 operator >

Tests whether first vector is greater than other or not.

6 operator >=

Tests whether first vector is greater than or equal to other or not.

7 swap

Exchanges the contents of two vector.



Advertisements

The C Standard Library

C++ Library &-8211; Home

C++ Library &-8211; fstream>

C++ Library &-8211; iomanip>

C++ Library &-8211; ios>

C++ Library &-8211; iosfwd>

C++ Library &-8211; iostream>

C++ Library &-8211; istream>

C++ Library &-8211; ostream>

C++ Library &-8211; sstream>

C++ Library &-8211; streambuf>

C++ Library &-8211; atomic>

C++ Library &-8211; complex>

C++ Library &-8211; exception>

C++ Library &-8211; functional>

C++ Library &-8211; limits>

C++ Library &-8211; locale>

C++ Library &-8211; memory>

C++ Library &-8211; new>

C++ Library &-8211; numeric>

C++ Library &-8211; regex>

C++ Library &-8211; stdexcept>

C++ Library &-8211; string>

C++ Library &-8211; thread>

C++ Library &-8211; tuple>

C++ Library &-8211; typeinfo>

C++ Library &-8211; utility>

C++ Library &-8211; valarray>

C++ Library &-8211; array>

C++ Library &-8211; bitset>

C++ Library &-8211; deque>

C++ Library &-8211; forward_list>

C++ Library &-8211; list>

C++ Library &-8211; map>

C++ Library &-8211; queue>

C++ Library &-8211; set>

C++ Library &-8211; stack>

C++ Library &-8211; unordered_map>

C++ Library &-8211; unordered_set>

C++ Library &-8211; vector>

C++ Library &-8211; algorithm>

C++ Library &-8211; iterator>

C++ Programming Tutorial

C++ Useful Resources

C++ Discussion

UPSC IAS Exams Notes

Developer&-8217;s Best Practices

Questions and Answers

Effective Resume Writing

HR Interview Questions

Computer Glossary

Who is Who

C++ Library – unordered_set

C++ Library &-8211; unordered_set &-8211; this Article or News was published on this date:2019-05-12 18:21:54 kindly share it with friends if you find it helpful

C++ Library &-8211; unordered_set>


Advertisements


Introduction

It is an associative container that store unique elements in no particular order, and which allow for fast retrieval of individual elements based on their value.

Definition

Below is definition of std::unordered_set

template  class Key,                        
           class Hash = hashKey>,        
           class Pred = equal_toKey>,    
           class Alloc = allocatorKey>   
           > class unordered_set;

Parameters

  • Key − It defines the type of element.
  • Hash − It is a unary function object.
  • Pred − It is a binary predicate that takes two arguments of the same type as the elements and returns a bool.
  • Alloc − It defines the type of allowcater.

Member types

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

member type definition notes
key_type It is the first template parameter (Key)
value_type It is the first template parameter (Key) The same as key_type
hasher It is the second template parameter (Hash) defaults to: hashkey_type>
key_equal It is the third template parameter (Pred) defaults to: equal_tokey_type>
allocator_type It is the fourth template parameter (Alloc) defaults to: allocatorvalue_type>
reference Alloc::reference
const_reference Alloc::const_reference
pointer Alloc::pointer for the default allocator: value_type*
const_pointer Alloc::const_pointer for the default allocator: const value_type*
iterator a forward iterator to const value_type * convertible to const_iterator
const_iterator a forward iterator to const value_type *
local_iterator a forward iterator to const value_type * convertible to const_local_iterator
const_local_iterator a forward iterator to const value_type *
size_type an unsigned integral type usually the same as size_t
difference_type a signed integral type usually the same as ptrdiff_t

Member functions

Below is list of member functions

Sr.No. Method & Description
1 (constructor)

It constructs unordered_set.

2 (destructor)

It destroys unordered_set.

3 operator=

It is used to assign the content.

Capacity

Sr.No. Capacity & Description
1 empty

It is used to test whether container is empty.

2 size

It returns container size.

3 max_size

It returns maximum size.

Iterators

Sr.No. Iterators & Description
1 begin

It returns iterator to beginning.

2 end

It returns iterator to end.

3 cbegin

It returns const_iterator to beginning.

4 cend

It return const_iterator to end.

Element lookup

Sr.No. Element lookup & Description
1 find

It is used to get iterator to element.

2 count

It is used to count elements with a specific key.

3 equal_range

It is used to get range of elements with a specific key.

Modifiers

Sr.No. Modifiers & Description
1 emplace

It is used to construct and insert element.

2 emplace_hint

It is used to construct and insert element with hint.

3 insert

It is used to insert elements.

4 erase

It is used to erase elements.

5 clear

It is used to clear content.

6 swap

It is used to swap content.

Buckets

Sr.No. Buckets & Description
1 bucket_count

It returns number of buckets.

2 max_bucket_count

It returns maximum number of buckets.

3 bucket_size

It returns bucket size.

4 bucket

It locates element&-8217;s bucket.

Hash policy

Sr.No. Hash policy & Description
1 load_factor

It returns load factor.

2 max_load_factor

It is used to get or set maximum load factor.

3 rehash

It is used to set number of buckets.

4 reserve

It gives a request to capacity chage of backets

Observers

Sr.No. Observers & Description
1 hash_function

It is used to get hash function.

2 key_eq

It is used to get key equivalence predicate.

3 get_allocator

It is used to get allocator.

Sr.No. Non-member function overloads & Description
1 operators (unordered_set)

It is used to get hash function.

2 swap (unordered_set)

It exchanges contents of two unordered_set containers.

Predefined iterators

Sr.No. Non-member function overloads & Description
1 operators (unordered_set)

It is used to get hash function.

2 swap (unordered_set)

It exchanges contents of two unordered_set containers.



Advertisements

The C Standard Library

C++ Library &-8211; Home

C++ Library &-8211; fstream>

C++ Library &-8211; iomanip>

C++ Library &-8211; ios>

C++ Library &-8211; iosfwd>

C++ Library &-8211; iostream>

C++ Library &-8211; istream>

C++ Library &-8211; ostream>

C++ Library &-8211; sstream>

C++ Library &-8211; streambuf>

C++ Library &-8211; atomic>

C++ Library &-8211; complex>

C++ Library &-8211; exception>

C++ Library &-8211; functional>

C++ Library &-8211; limits>

C++ Library &-8211; locale>

C++ Library &-8211; memory>

C++ Library &-8211; new>

C++ Library &-8211; numeric>

C++ Library &-8211; regex>

C++ Library &-8211; stdexcept>

C++ Library &-8211; string>

C++ Library &-8211; thread>

C++ Library &-8211; tuple>

C++ Library &-8211; typeinfo>

C++ Library &-8211; utility>

C++ Library &-8211; valarray>

C++ Library &-8211; array>

C++ Library &-8211; bitset>

C++ Library &-8211; deque>

C++ Library &-8211; forward_list>

C++ Library &-8211; list>

C++ Library &-8211; map>

C++ Library &-8211; queue>

C++ Library &-8211; set>

C++ Library &-8211; stack>

C++ Library &-8211; unordered_map>

C++ Library &-8211; unordered_set>

C++ Library &-8211; vector>

C++ Library &-8211; algorithm>

C++ Library &-8211; iterator>

C++ Programming Tutorial

C++ Useful Resources

C++ Discussion

UPSC IAS Exams Notes

Developer&-8217;s Best Practices

Questions and Answers

Effective Resume Writing

HR Interview Questions

Computer Glossary

Who is Who

C++ Library – unordered_map

C++ Library &-8211; unordered_map &-8211; this Article or News was published on this date:2019-05-12 18:21:53 kindly share it with friends if you find it helpful

C++ Library &-8211; unordered_map>


Advertisements


Introduction to unordered_map

Unordered map is dictionary like data structure. It is a sequence of (key, value) pair, where only single value is associated with each unique key. It is often referred as associative array. It enables fast retrieval of individual elements based on their keys. It also implements the direct access operator(subscript operator[]) which allows for direct access of the mapped value using its key value as argument.

Unordered map does not sort its element in any particular order with respect to either their key or mapped values, instead organizes into buckets depending on their hash values to allow for fast access to individual elements directly by their key values.

Unordered map performs better than map while accessing individual elements by their keys. But for range iteration their performance is considerably low.

Definition

Below is definition of std::unordered_map from unordered_map> header file

template  class Key,
           class T,
           class Hash = hashKey>,
           class Pred = equal_toKey>,
           class Alloc = allocator pairconst Key,T> >
           > class unordered_map;

Parameters

    • Key − Type of the key.
    • T − Type of the mapped values.
    • Hash − A unary function object type which takes an object of type key type as argument and returns a unique value of type size_t based on it.
    • Pred − A binary predicate that which two arguments of the key type and returns a bool.
    • Alloc − Type of the allocator object.

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

Member types

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

Sr.No. Member types Definition
1 key_type Key (First parameter of the template)
2 mapped_type T (Second parameter of the template)
3 value_type pairconst key_type,mapped_type>
4 hasher The third template parameter (defaults to: hashkey_type>)
5 key_equal The fourth template parameter (defaults to: equal_tokey_type>)
6 allocator_type Alloc (Fifth parameter of the template)
7 reference value_type&
8 const_reference const value_type&
9 pointer allocator_traitsAlloc>::pointer
10 const_pointer allocator_traitsAlloc>::const_pointer
11 iterator A forward iterator to value_type value_type
12 const_iterator A forward iterator to const value_type value_type
13 local_iterator A forward iterator to value_type
14 const_local_iterator A forward iterator to const value_type
15 difference_type ptrdiff_t
16 size_type size_t

Functions from unordered_map>

Below is list of all methods from unordered_map> header.

Constructors

Sr.No. Method & Description
1 unordered_map::unordered_map default constructor

Constructs an empty unordered_map with zero elements.

2 unordered_map::unordered_map copy constructor

Constructs an unordered_map with copy of each elements present in existing unordered_map.

3 unordered_map::unordered_map move constructor

Constructs an unordered_map with the contents of other using move semantics.

4 unordered_map::unordered_map range constructor

Constructs an unordered_map with as many elements as in range of first to last.

5 unordered_map::unordered_map initializer_list constructor

Constructs an unordered_map from initialize list.

Destructor

Sr.No. Method & Description
1 unordered_map::~unordered_map

Destroys unordered_map object by deallocating it&-8217;s memory.

Member functions

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

Returns a reference to the mapped value associated with key k.

2 unordered_map::begin container iterator

Returns an iterator which refers to the first element of the map.

3 unordered_map::begin bucket iterator

Returns an iterator pointing to the first element in one of its buckets.

4 unordered_map::bucket

Returns the bucket number where element with key k is located.

5 unordered_map::bucket_count

Returns the number of buckets in unordered_map container.

6 unordered_map::bucket_size

Returns the number of elements presents in the nth bucket.

7 unordered_map::cbegin container iterator

Returns a constant iterator which refers to the first element of the unordered_map.

8 unordered_map::cbegin bucket iterator

Returns a constant iterator pointing to the first element in one of its buckets.

9 unordered_map::cend container iterator

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

10 unordered_map::cend bucket iterator

Returns a constant iterator which points to past-the-end element in one of its buckets.

11 unordered_map::clear

Destroys the unordered_map by removing all elements and sets the size of unordered_map to zero.

12 unordered_map::count

Returns the number of mapped values associated with key k.

13 unordered_map::emplace

Extends container by inserting new element.

14 unordered_map::emplace_hint

Inserts a new element in unordered_map using hint as a position for element.

15 unordered_map::empty

Tests whether unordered_map is empty or not.

16 unordered_map::end container iterator

Returns an iterator which points to past-the-end element in the unordered_map.

17 unordered_map::end bucket iterator

Returns an iterator which points to past-the-end element in one of its buckets.

18 unordered_map::equal

Returns range of elements that matches specific key.

19 unordered_map::erase position version

Removes single element of the unordered_map from position.

20 unordered_map::erase key version

Removes mapped value associated with key k.

21 unordered_map::erase range version

Removes range of element from the the unordered_map.

22 unordered_map::find

Finds an element associated with key k.

23 unordered_map::get_allocator

Returns an allocator associated with unordered_map.

24 unordered_map::hash_function

Calculates the hash function object used by the unordered_map container.

25 unordered_map::insert

Extends container by inserting new element in unordered_map.

26 unordered_map::insert move version

Extends container by inserting new element in unordered_map.

27 unordered_map::insert hint version

Extends conta iner by inserting new element in unordered_map.

28 unordered_map::insert move and hint version

Extends unordered_map by inserting new element.

29 unordered_map::insert range version

Extends container by inserting new elements in the unordered_map.

30 unordered_map::insert initializer_list version

Extends map by inserting new element from initializer list.

31 unordered_map::key_eq

Returns the function that compares keys for equality.

32 unordered_map::load_factor

Returns the current load factor of the unordered_map container.

33 unordered_map::max_bucket_count

Returns the maximum number of buckets that the unordered_map container can have.

34 unordered_map::max_load_factor get version

Returns the current maximum load factor for the unordered_map container.

35 unordered_map::max_load_factor set version

Assigns new load factor for the unordered_map container.

36 unordered_map::max_size

Returns the maximum number of elements can be held by unordered_map.

37 unordered_map::operator= copy version

Assigns new contents to the unordered_map by replacing old ones and modifies size if necessary.

38 unordered_map::operator= move version

Move the contents of one unordered_map into another and modifies size if necessary.

39 unordered_map::operator= initializer_list version

Copy elements from initializer list to unordered_map.

40 unordered_map::operator[]

If key k matches an element in the container, then method returns a reference to the element.

41 unordered_map::operator[] move version

If key k matches an element in the container, then method returns a reference to the element.

42 unordered_map::rehash

Sets the number of buckets in the container to n or more.

43 unordered_map::reserve

Sets the number of buckets in the container to the most appropriate to contain at least n elements.

44 unordered_map::size

Returns the number of elements present in the unordered_map.

45 unordered_map::swap

Exchanges the content of first unordered_map with another.

Non-member overloaded functions

Sr.No. Method & Description
1 unordered_map::operator==

Tests whether two unordered_maps are equal or not.

2 unordered_map::operator!=

Tests whether two unordered_maps are equal or not.

3 unordered_map::swap

Exchanges the content of first unordered_map with another.

Introduction to unordered_multimap

Unordered_multimap is dictionary like data structure. It is a sequence of (key, value) pair, where different elements can have equivalent keys. Elements with equivalent keys are grouped together in the same bucket and in such a way that an equal_range iterator can iterate through all of them.

Unordered_multimap does not sort its element in any particular order with respect to either their key or mapped values, instead organizes into buckets depending on their hash values to allow for fast access to individual elements directly by their key values.

Definition

Below is definition of std::unordered_multimap from unordered_map> header file

template  class Key, 
           class T,
           class Hash = hashKey>,
           class Pred = equal_toKey>,
           class Alloc = allocator pairconst Key,T> >
           > class unordered_multimap;

Parameters

  • Key − Type of the key.
  • T − Type of the mapped values.
  • Hash − A unary function object type which takes an object of type key type as argument and returns a unique value of type size_t based on it.
  • Pred − A binary predicate that which two arguments of the key type and returns a bool.
  • Alloc − Type of the allocator object.

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

Member types

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

Sr.No. Member types Definition
1 key_type Key (First parameter of the template)
2 mapped_type T (Second parameter of the template)
3 value_type pairconst key_type,mapped_type>
4 hasher The third template parameter (defaults to: hashkey_type>)
5 key_equal The fourth template parameter (defaults to: equal_tokey_type>)
6 allocator_type Alloc (Fifth parameter of the template)
7 reference value_type&
8 const_reference const value_type&
9 pointer allocator_traitsAlloc>::pointer
10 const_pointer allocator_traitsAlloc>::const_pointer
11 iterator A forward iterator to value_type value_type
12 const_iterator A forward iterator to const value_type value_type
13 local_iterator A forward iterator to value_type
14 const_local_iterator A forward iterator to const value_type
15 difference_type ptrdiff_t
16 size_type size_t

Functions from unordered_multimap>

Below is list of all methods from unordered_map> header.

Constructors

Sr.No. Method & Description
1 unordered_multimap::unordered_multimap() default constructor

Constructs an empty unordered_multimap with zero elements.

2 unordered_multimap::unordered_multimap() copy constructor

Constructs an unordered_multimap with copy of each elements present in existing unordered_multimap.

3 unordered_multimap::unordered_multimap() move constructor

Constructs an unordered_multimap with the contents of other using move semantics.

4 unordered_multimap::unordered_multimap() range constructor

Constructs an unordered_multimap with as many elements as in range of first to last.

5 unordered_multimap::unordered_multimap() initializer_list constructor

Constructs an unordered_multimap from initialize list.

Destructor

Sr.No. Method & Description
1 unordered_multimap::~unordered_multimap()

Destroys unordered_multimap object by deallocating it&-8217;s memory.

Member functions

Sr.No. Method & Description
1 unordered_multimap::begin() container iterator

Returns an iterator which refers to the first element of the unordered_mulitmap.

2 unordered_multimap::begin() bucket iterator

Returns an iterator pointing to the first element in one of its buckets.

3 unordered_multimap::bucket()

Returns the bucket number where element with key k is located.

4 unordered_multimap::bucket_count()

Returns the number of buckets present in unordered_multimap container.

5 unordered_multimap::bucket_size()

Returns the number of elements presents in the nth bucket.

6 unordered_multimap::cbegin() container iterator

Returns a constant iterator which refers to the first element of the unordered_multimap.

7 unordered_multimap::cbegin() bucket iterator

Returns a constant iterator pointing to the first element in one of its buckets.

8 unordered_multimap::cend() container iterator

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

9 unordered_multimap::cend() bucket iterator

Returns a constant iterator which points to past-the-end element in one of its buckets.

10 unordered_multimap::clear()

Destroys the unordered_multimap by removing all elements and sets the size of unordered_multimap to zero.

11 unordered_multimap::count()

Returns the number of mapped values associated with key k.

12 unordered_multimap::emplace()

Extends container by inserting new element.

13 unordered_multimap::emplace_hint()

Inserts a new element in a unordered_multimap using hint as a position for element.

14 unordered_multimap::empty()

Tests whether unordered_multimap is empty or not.

15 unordered_multimap::end() container iterator

Returns an iterator which points to past-the-end element in the unordered_multimap.

16 unordered_multimap::end() bucket iterator

Returns an iterator which points to past-the-end element in one of its buckets.

17 unordered_multimap::equal_range()

Returns range of elements that matches specific key.

18 unordered_multimap::erase() position version

Removes single element of the unordered_multimap from position.

19 unordered_multimap::erase() key version

Removes mapped value associated with key k.

20 unordered_multimap::erase() range version

Removes range of element from the the unordered_multimap.

21 unordered_multimap::find()

Finds an element associated with key k.

22 unordered_multimap::get_allocator()

Returns an allocator associated with unordered_multimap.

23 unordered_multimap::hash_function()

Calculates the hash function object used by the unordered_multimap container.

24 unordered_multimap::insert() value version

Extends container by inserting new element in unordered_multimap.

25 unordered_multimap::insert() move version

Extends unordered_multimap by inserting new element.

26 unordered_multimap::insert() hint version

Extends container by inserting new element in unordered_multimap.

27 unordered_multimap::insert() hint move version

Extends container by inserting new element in unordered_multimap by using move semantics.

28 unordered_multimap::insert() range version

Extends container by inserting new elements in the unordered_multimap.

29 unordered_multimap::insert() initializer_list version

Extends unordered_multimap by inserting new element from initializer list.

30 unordered_multimap::key_eq()

Returns the function that compares keys for equality.

31 unordered_multimap::load_factor()

Returns the current load factor of the unordered_multimap container.

32 unordered_multimap::max_bucket_count()

Returns the maximum number of buckets that the unordered_multimap container can have.

33 unordered_multimap::max_load_factor() get version

Returns the current maximum load factor for the unordered_multimap container.

34 unordered_multimap::max_load_factor() set version

Assigns new load factor for the unordered_multimap container.

35 unordered_multimap::max_size()

Returns the maximum number of elements can be held by unordered_multimap.

36 unordered_multimap::operator=() copy version

Assigns new contents to the unordered_multimap by replacing old ones and modifies size if necessary.

37 unordered_multimap::operator=() move version

Move the contents of one unordered_multimap into another and modifies size if necessary.

38 unordered_multimap::operator=() initializer_list version

Copy elements from initializer list to unordered_multimap.

39 unordered_multimap::rehash()

Sets the number of buckets in the container to n or more.

40 unordered_multimap::reserve()

Sets the number of buckets in the container to the most appropriate to contain at least n elements.

41 unordered_multimap::size()

Returns the number of elements present in the unordered_multimap.

42 unordered_multimap::swap()

Exchanges the content of first unordered_multimap with another.

Non-member overloaded functions

Sr.No. Method & Description
1 unordered_multimap::operator==()

Tests whether two unordered_multimaps are equal or not.

2 unordered_multimap::operator!=()

Tests whether two unordered_multimaps are equal or not.

3 unordered_multimap::swap()

Exchanges the content of first unordered_multimap with another.



Advertisements

The C Standard Library

C++ Library &-8211; Home

C++ Library &-8211; fstream>

C++ Library &-8211; iomanip>

C++ Library &-8211; ios>

C++ Library &-8211; iosfwd>

C++ Library &-8211; iostream>

C++ Library &-8211; istream>

C++ Library &-8211; ostream>

C++ Library &-8211; sstream>

C++ Library &-8211; streambuf>

C++ Library &-8211; atomic>

C++ Library &-8211; complex>

C++ Library &-8211; exception>

C++ Library &-8211; functional>

C++ Library &-8211; limits>

C++ Library &-8211; locale>

C++ Library &-8211; memory>

C++ Library &-8211; new>

C++ Library &-8211; numeric>

C++ Library &-8211; regex>

C++ Library &-8211; stdexcept>

C++ Library &-8211; string>

C++ Library &-8211; thread>

C++ Library &-8211; tuple>

C++ Library &-8211; typeinfo>

C++ Library &-8211; utility>

C++ Library &-8211; valarray>

C++ Library &-8211; array>

C++ Library &-8211; bitset>

C++ Library &-8211; deque>

C++ Library &-8211; forward_list>

C++ Library &-8211; list>

C++ Library &-8211; map>

C++ Library &-8211; queue>

C++ Library &-8211; set>

C++ Library &-8211; stack>

C++ Library &-8211; unordered_map>

C++ Library &-8211; unordered_set>

C++ Library &-8211; vector>

C++ Library &-8211; algorithm>

C++ Library &-8211; iterator>

C++ Programming Tutorial

C++ Useful Resources

C++ Discussion

UPSC IAS Exams Notes

Developer&-8217;s Best Practices

Questions and Answers

Effective Resume Writing

HR Interview Questions

Computer Glossary

Who is Who