- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
reference_wrapper in C++
In C++ the reference_wrapper is a class template that helps by wrapping a reference in a copy constructible and copy assignable object of type T. The instances of std::reference_wrapper are basically objects, but they can be converted into T&. So we can use as argument with the functions that take the underlying type by reference.
Example Code
#include <iostream> #include <functional> using namespace std; int main () { char a = 'h', b = 'e', c = 'l', d = 'l', e = 'o' , f = 'W', g = 'o', h = 'r', i = 'l', j = 'd'; reference_wrapper<char> ref[] = {a, b, c, d, e, f, g, h, i, j}; //creating reference array for (char& s : ref) cout << s; cout <<endl; return 0; }
Output
soumyadeep@soumyadeep-VirtualBox:~$ ./a.out helloWorld soumyadeep@soumyadeep-VirtualBox:~$
Advertisements