views:

181

answers:

3

I have made big mistake. It is about vector.

    #include <iostream>
    #include <ostream>
    #include <string>
    #include <vector>
    #include <functional>
    #include <algorithm>

    using namespace std;
    int main() {
        vector<int,greater<int>>v;
        v.push_back(11);
        v.push_back(22);
        v.push_back(33);
        v.push_back(44);
        v.push_back(55);
        v.push_back(66);
        v.push_back(77);
        v.erase(remove_if(v.begin(),v.end(),
                          [](int e) {  return e %2==1;}),v.end());

        for (auto i=v.begin();i!=v.end();++i) {
            cout<<*i<<endl;
        }
        v.clear();
        return 0;
    }

The errors are:

1>------ Build started: Project: map_implementation, Configuration: Debug Win32 ------
1>Build started 8/9/2010 10:26:11 AM.
1>InitializeBuildStatus:
1>  Touching "Debug\map_implementation.unsuccessfulbuild".
1>ClCompile:
1>  map_implementation.cpp
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(421): error C2903: 'rebind' : symbol is neither a class template nor a function template
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(481) : see reference to class template instantiation 'std::_Vector_val<_Ty,_Alloc>' being compiled
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>          c:\users\david\documents\visual studio 2010\projects\map_implementation\map_implementation\map_implementation.cpp(12) : see reference to class template instantiation 'std::vector<_Ty,_Ax>' being compiled
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(421): error C2039: 'rebind' : is not a member of 'std::greater<_Ty>'
1>          with
1>          [
1>              _Ty=int
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(421): error C2143: syntax error : missing ';' before '<'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(421): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(421): error C2039: 'other' : is not a member of '`global namespace''
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(421): error C2238: unexpected token(s) preceding ';'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(462): error C2653: '_Alty' : is not a class or namespace name
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(462): error C2146: syntax error : missing ';' before identifier 'size_type'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(462): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(462): error C2602: 'std::_Vector_val<_Ty,_Alloc>::size_type' is not a member of a base class of 'std::_Vector_val<_Ty,_Alloc>'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(462) : see declaration of 'std::_Vector_val<_Ty,_Alloc>::size_type'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(462): error C2868: 'std::_Vector_val<_Ty,_Alloc>::size_type' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(463): error C2653: '_Alty' : is not a class or namespace name
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(463): error C2146: syntax error : missing ';' before identifier 'difference_type'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(463): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(463): error C2602: 'std::_Vector_val<_Ty,_Alloc>::difference_type' is not a member of a base class of 'std::_Vector_val<_Ty,_Alloc>'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(463) : see declaration of 'std::_Vector_val<_Ty,_Alloc>::difference_type'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(463): error C2868: 'std::_Vector_val<_Ty,_Alloc>::difference_type' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(464): error C2653: '_Alty' : is not a class or namespace name
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(464): error C2146: syntax error : missing ';' before identifier 'pointer'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(464): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(464): error C2602: 'std::_Vector_val<_Ty,_Alloc>::pointer' is not a member of a base class of 'std::_Vector_val<_Ty,_Alloc>'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(464) : see declaration of 'std::_Vector_val<_Ty,_Alloc>::pointer'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(464): error C2868: 'std::_Vector_val<_Ty,_Alloc>::pointer' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(465): error C2653: '_Alty' : is not a class or namespace name
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(465): error C2146: syntax error : missing ';' before identifier 'const_pointer'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(465): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(465): error C2602: 'std::_Vector_val<_Ty,_Alloc>::const_pointer' is not a member of a base class of 'std::_Vector_val<_Ty,_Alloc>'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(465) : see declaration of 'std::_Vector_val<_Ty,_Alloc>::const_pointer'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(465): error C2868: 'std::_Vector_val<_Ty,_Alloc>::const_pointer' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(466): error C2653: '_Alty' : is not a class or namespace name
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(466): error C2146: syntax error : missing ';' before identifier 'reference'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(466): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(466): error C2602: 'std::_Vector_val<_Ty,_Alloc>::reference' is not a member of a base class of 'std::_Vector_val<_Ty,_Alloc>'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(466) : see declaration of 'std::_Vector_val<_Ty,_Alloc>::reference'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(466): error C2868: 'std::_Vector_val<_Ty,_Alloc>::reference' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(467): error C2653: '_Alty' : is not a class or namespace name
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(467): error C2146: syntax error : missing ';' before identifier 'const_reference'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(467): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(467): error C2602: 'std::_Vector_val<_Ty,_Alloc>::const_reference' is not a member of a base class of 'std::_Vector_val<_Ty,_Alloc>'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(467) : see declaration of 'std::_Vector_val<_Ty,_Alloc>::const_reference'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(467): error C2868: 'std::_Vector_val<_Ty,_Alloc>::const_reference' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(468): error C2653: '_Alty' : is not a class or namespace name
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(468): error C2146: syntax error : missing ';' before identifier 'value_type'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(468): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(468): error C2602: 'std::_Vector_val<_Ty,_Alloc>::value_type' is not a member of a base class of 'std::_Vector_val<_Ty,_Alloc>'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(468) : see declaration of 'std::_Vector_val<_Ty,_Alloc>::value_type'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(468): error C2868: 'std::_Vector_val<_Ty,_Alloc>::value_type' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(473): error C2146: syntax error : missing ';' before identifier '_Alval'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(473): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(473): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(485): error C2039: '_Alty' : is not a member of 'std::_Vector_val<_Ty,_Alloc>'
1>          with
1>          [
1>              _Ty=int,
1>              _Alloc=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(485): error C2146: syntax error : missing ';' before identifier '_Alloc'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(485): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(485): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(487): error C2146: syntax error : missing ';' before identifier 'allocator_type'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(487): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(487): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(488): error C2825: 'std::vector<_Ty,_Ax>::_Alloc': must be a class or namespace when followed by '::'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(488): error C2039: 'size_type' : is not a member of '`global namespace''
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(488): error C2146: syntax error : missing ';' before identifier 'size_type'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(488): error C2602: 'std::vector<_Ty,_Ax>::size_type' is not a member of a base class of 'std::vector<_Ty,_Ax>'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(488) : see declaration of 'std::vector<_Ty,_Ax>::size_type'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(488): error C2868: 'std::vector<_Ty,_Ax>::size_type' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(489): error C2825: 'std::vector<_Ty,_Ax>::_Alloc': must be a class or namespace when followed by '::'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(489): error C2039: 'difference_type' : is not a member of '`global namespace''
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(489): error C2146: syntax error : missing ';' before identifier 'difference_type'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(489): error C2602: 'std::vector<_Ty,_Ax>::difference_type' is not a member of a base class of 'std::vector<_Ty,_Ax>'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(489) : see declaration of 'std::vector<_Ty,_Ax>::difference_type'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(489): error C2868: 'std::vector<_Ty,_Ax>::difference_type' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(490): error C2825: 'std::vector<_Ty,_Ax>::_Alloc': must be a class or namespace when followed by '::'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(490): error C2039: 'pointer' : is not a member of '`global namespace''
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(490): error C2146: syntax error : missing ';' before identifier 'pointer'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(490): error C2602: 'std::vector<_Ty,_Ax>::pointer' is not a member of a base class of 'std::vector<_Ty,_Ax>'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(490) : see declaration of 'std::vector<_Ty,_Ax>::pointer'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(490): error C2868: 'std::vector<_Ty,_Ax>::pointer' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(491): error C2825: 'std::vector<_Ty,_Ax>::_Alloc': must be a class or namespace when followed by '::'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(491): error C2039: 'const_pointer' : is not a member of '`global namespace''
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(491): error C2146: syntax error : missing ';' before identifier 'const_pointer'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(491): error C2602: 'std::vector<_Ty,_Ax>::const_pointer' is not a member of a base class of 'std::vector<_Ty,_Ax>'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(491) : see declaration of 'std::vector<_Ty,_Ax>::const_pointer'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(491): error C2868: 'std::vector<_Ty,_Ax>::const_pointer' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(492): error C2825: 'std::vector<_Ty,_Ax>::_Alloc': must be a class or namespace when followed by '::'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(492): error C2039: 'reference' : is not a member of '`global namespace''
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(492): error C2146: syntax error : missing ';' before identifier 'reference'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(492): error C2602: 'std::vector<_Ty,_Ax>::reference' is not a member of a base class of 'std::vector<_Ty,_Ax>'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(492) : see declaration of 'std::vector<_Ty,_Ax>::reference'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(492): error C2868: 'std::vector<_Ty,_Ax>::reference' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(493): error C2825: 'std::vector<_Ty,_Ax>::_Alloc': must be a class or namespace when followed by '::'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(493): error C2039: 'const_reference' : is not a member of '`global namespace''
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(493): error C2146: syntax error : missing ';' before identifier 'const_reference'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(493): error C2602: 'std::vector<_Ty,_Ax>::const_reference' is not a member of a base class of 'std::vector<_Ty,_Ax>'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(493) : see declaration of 'std::vector<_Ty,_Ax>::const_reference'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(493): error C2868: 'std::vector<_Ty,_Ax>::const_reference' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(494): error C2825: 'std::vector<_Ty,_Ax>::_Alloc': must be a class or namespace when followed by '::'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(494): error C2039: 'value_type' : is not a member of '`global namespace''
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(494): error C2146: syntax error : missing ';' before identifier 'value_type'
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(494): error C2602: 'std::vector<_Ty,_Ax>::value_type' is not a member of a base class of 'std::vector<_Ty,_Ax>'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\vector(494) : see declaration of 'std::vector<_Ty,_Ax>::value_type'
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>c:\program files\microsoft visual studio 10.0\vc\include\vector(494): error C2868: 'std::vector<_Ty,_Ax>::value_type' : illegal syntax for using-declaration; expected qualified-name
1>          with
1>          [
1>              _Ty=int,
1>              _Ax=std::greater<int>
1>          ]
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:02.31
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
+1  A: 

An iterator to a map points to an std::pair<key, value> type. In your case, it's an std::pair<int, std::string>. In your lambda, the first parameter should be this pair type, and you should check it's first member for the key of that entry.

dauphic
+1  A: 

Each element of the map is std::pair<int,string> and not a simple int. Hence your lambda function should take this pair as the parameter.

Naveen
A: 

The predicate for remove_if receives an element from the map, which, in your case, is an std::pair< int, std::string >. So your lambda function should look like this:

[]( map<int, string, greater<int> >::value_type e ){ return (e.first % 2) != 0; }

You should also be able to use

[]( auto e ){ return (e.first % 2) != 0; )
Praetorian