Skip to content
This repository was archived by the owner on Oct 27, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required (VERSION 3.1.0)
project(rvalue_refs)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 11)

add_executable(rvalue_refs rvalue_refs.cpp)
56 changes: 56 additions & 0 deletions rvalue_refs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector<int> retVector (const vector<int>& v, int dataToAppnd)
{
vector<int> new_vec;
for (const auto& itr : v) {
new_vec.push_back(itr);
}
new_vec.push_back(dataToAppnd);

return new_vec;
}

vector<int> demoRvalRef (vector<int> v )
{
return v;
}

int main()
{
vector<int> v = {1, 2, 3};
int append = 4;

std::cout << "Value of v is " << std::endl;
for (auto it = v.begin() - 1; it != v.end()-1; it++) {
std::cout << v[*it] << " ";
}

std::cout << std::endl << std::endl;
v = retVector(v, append);

std::cout << "Vector returned is " << std::endl;
for (auto it = v.begin() - 1; it != v.end()-1; it++) {
std::cout << v[*it] << " ";

}
std::cout << std::endl << std::endl;


append = 5;
v = demoRvalRef(retVector(v, append));

std::cout << "Rval Ref Vector returned is " << std::endl;
for (auto it = v.begin() - 1; it != v.end()-1; it++) {
std::cout << v[*it] << " ";

}
std::cout << std::endl << std::endl;


return 0;
}