Search
 
SCRIPT & CODE EXAMPLE
 

CPP

vector and algorithm

#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

template<typename T> ostream & print(const T & start, const T & end)
{
    T tmp = start;
    for(; tmp != end; ++tmp)
    {
        cout<< *tmp<< " ";
    }
    return cout;
}
class A
{
public:
    int a;
public:
    A(int a):a(a) {}
};

ostream & operator<<(ostream & c, const A & o)
{
    c<<o.a;
    return c;
}

void fill (const int table[], unsigned size, vector<A*> & v)
{
    for(unsigned i = 0; i < size; ++i)
    {
        v.push_back(new A(table[i]));            //LINE I
    }
}

void del(A * p)
{
    delete p;
}
int main()
{
    int tab[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    vector<A*> v1;
    fill(tab, 10, v1);

    print(v1.rbegin(), v1.rend())<<endl;        //LINE II
    for_each(v1.begin(), v1.end(), del);
    return 0;
}

//will compile and run successfully
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ stack 
Cpp :: how to print double value up to 9 decimal places in c++ 
Cpp :: increment integer 
Cpp :: print float up to 3 decimal places in c++ 
Cpp :: sort an array using stl 
Cpp :: c to assembly mips converter 
Cpp :: Types of Triangles Based on Angles in c++ 
Cpp :: c++ how to use and or in if 
Cpp :: properties of loop in c++ and how it works 
Cpp :: TCA9548 I2CScanner Arduino 
Cpp :: cpp get keystroke in console only 
Cpp :: sjfoajf;klsjflasdkfjk;lasjfjajkf;dslafjdjalkkkjakkkkkkkkkkkkkkkkfaWZdfbhjkkkk gauds 
Cpp :: hackerearth questions siemens 
Cpp :: Hash Sort in C++ 
Cpp :: estimateaffine3d example c++ 
Cpp :: transform c++ 
Cpp :: ue4 c++ bool to text 
Cpp :: how to get max grade c++ 
Cpp :: 2000pp pp play osu std 
Cpp :: shrek c++ 
Cpp :: inorder to postorder converter online 
Cpp :: how to adjust and delete memory in c, c++ 
Cpp :: warning in range-based for loop in C++. How to resolve it in vscode? 
Cpp :: Marin and Photoshoot codeforces solution in c++ 
Cpp :: cf 633b trivial problem explanation 
Cpp :: python pour débutant 
Cpp :: C++ Features 
Cpp :: 123213 
Cpp :: operator using 
Cpp :: c++ multiplication table rows and columns 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =