forked from Bhupesh-V/30-seconds-of-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b50dc9b
commit 45dcacd
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# crbegin | ||
|
||
**Description :** | ||
Get a const_reverse_iterator pointing at the last element of the container. This is useful | ||
when wanting a read-only iterator to iterate a container in reverse order. | ||
|
||
**Example :** | ||
```cpp | ||
//Run Code To Demonstrate use of set.size() | ||
#include<iostream> | ||
#include<set> | ||
|
||
int main() { | ||
// Create a set object holding integers | ||
std::set<int> mySet{ 3, 1, 5, 2, 4 }; | ||
|
||
// Get a const_reverse_iterator pointing to the last element | ||
std::set<int>::reverse_iterator r_it = mySet.crbegin(); | ||
|
||
// Iterate through the const_reverse_iterator | ||
for (; r_it != mySet.crend(); ++r_it){ | ||
std::cout << *r_it << std::endl; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
``` | ||
|
||
**[See Sample code](../snippets/set/crbegin.cpp)** | ||
**[Run Code](https://ideone.com/ccq58H)** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Follow the Style Guide while submitting code PR. | ||
// Style Guide => https://github.com/Bhupesh-V/30-Seconds-Of-STL/blob/master/CONTRIBUTING.md/#Style Guide | ||
/* | ||
Author : Cameron Bradley | ||
Date : 11/10/2020 | ||
Time : 12:32 | ||
Description : Get a const reverse iterator pointing at the last element of the container | ||
*/ | ||
#include<iostream> | ||
#include<set> | ||
|
||
int main() { | ||
// Create a set object holding integers | ||
std::set<int> mySet{ 3, 1, 5, 2, 4 }; | ||
|
||
// Get a const_reverse_iterator pointing to the last element | ||
std::set<int>::reverse_iterator r_it = mySet.crbegin(); | ||
|
||
// Iterate through the const_reverse_iterator | ||
for (; r_it != mySet.crend(); ++r_it) { | ||
std::cout << *r_it << std::endl; | ||
} | ||
|
||
return 0; | ||
} |