 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
                    