#ranges — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #ranges, aggregated by home.social.
-
Why planning reforms have people concerned about the Waitākere Ranges and development https://www.byteseu.com/1989008/ #about #and #concerned #development #dirga #have #NewZealand #people #Planning #ranges #reforms #the #waitkere #why
-
https://www.europesays.com/fr/862071/ Faites ceci avant le 15 avril pour éviter que les mites ne dévorent vos pulls d’hiver fraîchement rangés #«Le #15 #avant #avril #Business #ceci #d'hiver #devorent #Économie #Economy #éviter #faites #FR #fraichement #France #les #mites #ne #pour #pulls #que #ranges #vos
-
Встреча ISO C++ в Софии: С++26 и рефлексия
Привет! На связи Антон Полухин из техплатформы городских сервисов Яндекса, и сейчас я расскажу о софийской встрече Международного комитета по стандартизации языка программирования C++, в которой принимал активное участие. Это была последняя встреча, на которой новые фичи языка, с предодобренным на прошлых встречах дизайном, ещё могли попасть в C++26. И результат превзошёл все ожидания: compile-time-рефлексия рефлексия параметров функций аннотации std::optional<T&> параллельные алгоритмы Об этих и других новинках расскажу в посте
https://habr.com/ru/companies/yandex/articles/920470/
#c++29 #с++29 #c++26 #с++26 #с++ #c++ #reflection #constexpr #exception #simd #safety #security #undefined_behavior #annotations #parallel_programming #executor #executors #ranges #coroutines
-
C++OnSea 2025 SESSION ANNOUNCEMENT: Safe and Readable Code: Monadic Operations in C++23 by @asperamanca
https://cpponsea.uk/2025/session/safe-and-readable-code-monadic-operations-in-cpp23
Register now at https://cpponsea.uk/tickets/
-
Tanzania's President Boosts Minimum Wage by 35.1%, Now Ranges from $137 to $186 #EastAfrica #Boosts #minimum #President #Ranges #Tanzanias #wage
https://tinyurl.com/2b7xdcwk -
Reverse Iterations
Sometimes, we all need a way to iterate over a container in the opposite direction. There are several ways to reverse-iterate a container, and in this article, we’ll explore them.
Index Iteration
Probably the simplest way, taken from C is to iterate using an index location:
for (int64_t index = ssize(container) - 1; index >= 0; --index) { // do something with `container[index]`}This way is highly not recommended as it might lead to infinite loops if done incorrectly (for example by using
uint64_torsize_tfor the index type), and you can find more issues with this way in some previous articles about iterators in this blog.Reverse Iterators
Another way to iterate a container is by using reverse iterators (
rbegin()andrend()):for (auto it = container.rbegin(); it != container.rend(); ++it) { // do something with `*it`}This is a more recommended way, but it might be a little bit frustrating compared to a regular for-range loop:
for (auto elem : container) { /*do something with `elem`*/ }The closest way to this method using the standard (before C++20) is:
std::for_each(container.rbegin(), container.rend(), [](auto elem) { // so something with `elem`});Ranges (C++20)
If you are using the ranges library, or using at least C++20, you can use the following method to iterate a container in reverse order:
for (auto elem : container | std::views::reverse) { // do something with `elem`}Custom Reverse Container View
Another way to use the for-range loop (even if you don’t use C++20 or the ranges library), is to create your own container mask, to modify the behavior of the
begin()andend()functions:template <typename T>class reverse_view {public: reverse_view(T& cont) : container(&cont) {} typename T::reverse_iterator begin() { return container->rbegin(); } typename T::reverse_iterator end() { return container->rend(); } private: T* container;};Then, you’ll be able to use it like that:
std::vector<int> container = {1, 2, 3, 4, 5};for (int elem : reverse_view(container)) { std::cout << elem << ", ";}More Ways
I hope you learned something new, and feel free to share in the comments if you know other ways to reverse-iterate over a container.
#advanced #C_ #c11 #c14 #c17 #c20 #containers #Intermediate #Iterators #ranges #reverse #reverseIterators