Objectives are:
#include<iostream>
#include<xperimental/scope/scope.h++>
int* test(){
int* n = new int(100);
auto cleanup = xperimental::make_scope_exit([&n]()mutable{ delete n; n=nullptr; });
std::cout<< "m = " << *m << "\n";
return n;
}// deletes the pointer when it goes out of scope
int main(){
int* m = test(); // Runtime error
}
Output:
n = 100
xperimental::from is applicable of any primitive data-types: int , float, std::string and xperimental datastructures like: xperimental::array of any data-type, xperimental::filter and xperimental::transform can take Lambda expression and Callable object that creates objects if there is no further pipe after that otherwise return data. Returned result is xperimental::array<int>
#include<iostream>
#include<xperimental/scope/scope.h++>
int* test(){
int* n = new int(100);
auto cleanup = xperimental::cleanup(n);
std::cout<< "n = " << *n << "\n";
return n;
}// deletes the pointer when it goes out of scope
int main(){
int* m = test(); // Runtime error
}
Output:
n = 100
xperimental::from is applicable of any primitive data-types: int , float, std::string and xperimental datastructures like: xperimental::array of any data-type, xperimental::filter and xperimental::transform can take Lambda expression and Callable object that creates objects if there is no further pipe after that otherwise return data. Returned result is xperimental::array<int>
#include<iostream>
#include<xperimental/scope/smart_ptr.h++>
int main(){
auto ptr = xperimental::make_smart_ptr(new int(100));
std::cout<< "value = " << ptr << "\n";
ptr = 20;
std::cout<< "value = " << ptr << "\n";
++ptr;
std::cout<< "value = " << ptr << "\n";
}// deletes the pointer when it goes out of scope
Output:
value = 100
value = 20
value = 21
xperimental::from is applicable of any primitive data-types: int , float, std::string and xperimental datastructures like: xperimental::array of any data-type, xperimental::filter and xperimental::transform can take Lambda expression and Callable object that creates objects if there is no further pipe after that otherwise return data. Returned result is xperimental::array<int>