Logo

Programming-Idioms

History of Idiom 165 > diff from v38 to v39

Edit summary for version 39 by programming-idioms.org:
[Cpp] Variable name items. No comments in snippet. No sample value.

Version 38

2019-09-09, 09:06:40

Version 39

2019-09-09, 09:13:49

Idiom #165 Last element of list

Assign to variable x the last element of list items.

Idiom #165 Last element of list

Assign to variable x the last element of list items.

Imports
#include<vector>
Imports
#include<vector>
Code
std::vector<int> numbers;
auto last = numbers.crend() != numbers.crbegin() ? *numbers.crbegin() : -1;
Code
std::vector<int> items;
auto last = items.crend() != items.crbegin() ? *items.crbegin() : -1;
Comments bubble
Use iterators to iterate through containers
Comments bubble
Use iterators to iterate through containers