Logo

Programming-Idioms

History of Idiom 165 > diff from v35 to v36

Edit summary for version 36 by Dango:
New Cpp implementation by user [Dango]

Version 35

2019-07-13, 14:55:12

Version 36

2019-09-06, 11:18:09

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>
Code
// create list of numbers
std::vector<int> numbers{ 1,2,3,4,5,6 };
auto last = numbers.crend() != numbers.crbegin() ? *numbers.crbegin() : -1;
Comments bubble
Use iterators to iterate through containers