C++ Lambda Expressions Throwing an Exception

Description

C++ Lambda Expressions Throwing an Exception

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

using namespace std;

void ProcessVector(vector<int>& vect)
{
    sort(vect.begin(), vect.end(),[](int S1, int S2) throw(out_of_range)
         {//from ww w. ja v  a  2  s. c  o m
                 if (S1 > 100 || S2 > 100)
                    throw new out_of_range("Value over 100");

             return S1 < S2;
         });

    for_each(vect.begin(), vect.end(),
             [](int x) throw() {cout << x << endl;});
}

int main()
{
    vector<int> myV;
    myV.push_back(11);
    myV.push_back(2);
    myV.push_back(33);
    myV.push_back(4);

    //myV.push_back(101);

    ProcessVector(myV);
}



PreviousNext

Related