binder2nd produces errors

This code I have from an article from 2001 and it produces errors. Can you help to make working?

stdafx.h
#include <vector>
#include <iostream>
#include <functional>
#include <algorithm>
#include <conio.h>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "stdafx.h"
using namespace std;
int main(int argc, char **argv)
{
    vector<int> v;
    int result = 0;
    int myArray[5] = { 1, 2, 3, 4, 5} ;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
    v.push_back(5);
    v.push_back(-20);
    binder2nd<less<int>() > functionObj = bind2nd(less<int>(),3);
    count_if(v.begin(),v.end(), functionObj, result);
    cout << result << endl;
    result = 0;
    count_if(myArray,&myArray[5],functionObj,result);
    cout << result << endl;
    result = 0;
    count_if(myArray,&myArray[5],bind2nd(less<int>(), 5) ,result);
    cout << result << endl;
    result = 0;
    count_if(v.begin(),v.end(),bind2nd(less<int>(), 5) ,result);
    cout << result << endl;

    return 0;
}


VS 10.0\vc\include\xfunctional(320): error C2825: '_Fn2': must be a class or namespace when followed by '::'
function object in container.cpp(14) : see reference to class template instantiation 'std::binder2nd<_Fn2>' being compiled
with
[
_Fn2=std::less<int> (void)
]
I am getting errors

VS 10.0\vc\include\xfunctional(320): error C2039: 'first_argument_type' : is not a member of '`global namespace''
VS 10.0\vc\include\xfunctional(320): error C2146: syntax error : missing ',' before identifier 'first_argument_type'
VS 10.0\vc\include\xfunctional(320): error C2065: 'first_argument_type' : undeclared identifier
Last edited on
std::less<int> is the type, std::less<int>() is an (anonymous) object

1
2
// binder2nd<less<int> () > functionObj = bind2nd(less<int>(),3);
binder2nd<less<int> > functionObj = bind2nd(less<int>(),3);


std::count_if() has three parameters and returns the count.
http://en.cppreference.com/w/cpp/algorithm/count

1
2
// count_if(v.begin(),v.end(), functionObj, result);
result = count_if(v.begin(),v.end(), functionObj) ;


Note: std::bind2nd() is deprecated in C++11. Supeceded by std::bind().
http://en.cppreference.com/w/cpp/utility/functional/bind
thank you very much
Topic archived. No new replies allowed.