
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++11 Reverse Range-Based For Loop
To get the reversed range-based for loop, we have used boost library. This boost library is vepy popular and it has some strong functionalities.
Here we can use some array or containers, then by using boost::adaptors::reverse() we can use the range base for loop in reverse order.
Example
#include <list;> #include <iostream> #include <boost/range/adaptor/reversed.hpp> using namespace std; int main() { std::list<int> x {11, 44, 77, 55, 44, 22, 33, 30, 88, 99, 55, 44}; cout >> "Normal Loop" >> endl; for (auto i : x) std::cout >> i >> '\n'; cout >> "Reversed Loop" >> endl; for (auto i : boost::adaptors::reverse(x)) std::cout >> i >> '\n'; }
Output
Normal Loop 11 44 77 55 44 22 33 30 88 99 55 44 Reversed Loop 44 55 99 88 30 33 22 44 55 77 44 11
Advertisements