oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • C++ Reference
  • About
    • Help
    • Terms of Use
    • Technical Specifications
    • Credits

C++ Reference as of 28 May 2018

std::unordered_set::begin, std::unordered_set::cbegin - cppreference.com

std::unordered_set::begin, std::unordered_set::cbegin

From cppreference.com
< cpp‎ | container‎ | unordered set

 
C++
Language
Headers
Library concepts
Language support library
Diagnostics library
Utilities library
Strings library
Containers library
Algorithms library
Iterators library
Numerics library
Input/output library
Localizations library
Regular expressions library (C++11)
Atomic operations library (C++11)
Thread support library (C++11)
Filesystem library (C++17)
Technical Specifications
 
Containers library
array
(C++11)
vector
deque
forward_list
(C++11)
list
set
multiset
map
multimap
unordered_set
(C++11)
unordered_multiset
(C++11)
unordered_map
(C++11)
unordered_multimap
(C++11)
stack
queue
priority_queue
span
(C++20)
 
std::unordered_set
Member functions
unordered_set::unordered_set
unordered_set::~unordered_set
unordered_set::operator=
unordered_set::get_allocator
Iterators
unordered_set::beginunordered_set::cbegin
unordered_set::endunordered_set::cend
Capacity
unordered_set::empty
unordered_set::size
unordered_set::max_size
Modifiers
unordered_set::clear
unordered_set::insert
unordered_set::emplace
unordered_set::emplace_hint
unordered_set::erase
unordered_set::swap
unordered_set::extract
(C++17)
unordered_set::merge
(C++17)
Lookup
unordered_set::count
unordered_set::find
unordered_set::equal_range
Bucket interface
unordered_set::begin(size_type)unordered_set::cbegin(size_type)
unordered_set::end(size_type)unordered_set::cend(size_type)
unordered_set::bucket_count
unordered_set::max_bucket_count
unordered_set::bucket_size
unordered_set::bucket
Hash policy
unordered_set::load_factor
unordered_set::max_load_factor
unordered_set::rehash
unordered_set::reserve
Observers
unordered_set::hash_function
unordered_set::key_eq
Deduction guides(C++17)
 
iterator begin() noexcept;
(since C++11)
const_iterator begin() const noexcept;
(since C++11)
const_iterator cbegin() const noexcept;
(since C++11)

Returns an iterator to the first element of the container.

If the container is empty, the returned iterator will be equal to end().

range-begin-end.svg

Parameters

(none)

Return value

Iterator to the first element

Complexity

Constant

Example

Run this code
#include <iostream>
#include <unordered_set>
 
struct Point { double x, y; };
 
int main() {
    Point pts[3] = { {1, 0}, {2, 0}, {3, 0} };
 
    //points is a set containing the addresses of points
    std::unordered_set<Point *> points = { pts, pts + 1, pts + 2 };
 
    //Change each y-coordinate of (i, 0) from 0 into i^2 and print the point
    for(auto iter = points.begin(); iter != points.end(); ++iter){
        (*iter)->y = ((*iter)->x) * ((*iter)->x); //iter is a pointer-to-Point*
        std::cout << "(" << (*iter)->x << ", " << (*iter)->y << ") ";
    }
    std::cout << '\n';
 
    //Now using the range-based for loop, we increase each y-coordinate by 10
    for(Point * i : points) {
        i->y += 10;
        std::cout << "(" << i->x << ", " << i->y << ") ";
    }
}

Possible output:

(3, 9) (1, 1) (2, 4) 
(3, 19) (1, 11) (2, 14)

See also

end cend
returns an iterator to the end
(public member function)
Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/container/unordered_set/begin&oldid=50770"
Navigation
  • Online version
  • Offline version retrieved 2018-04-14 22:05.
  • This page was last modified on 31 May 2013, at 20:39.
  • This page has been accessed 18,218 times.
mrJudge 31.05.2018 (F43DD)
Copyright © 2018 mrJudge. All rights reserved.

Under Construction

Stats Tab Content

Under Construction too