L
Lycan. Mao..
Hello, I'm trying to write a function adapter object, but it fails
with the above information. Can you help me.
template <typename _Predicate>
struct Unary_negate {
typedef typename _Predicate::argument_type argument_type;
typedef typename _Predicate::return_type return_type;
_Predicate pred_;
explicit
Unary_negate(const _Predicate& p) : pred_(p) {};
bool operator() (const argument_type& x) const
{return !pred_(x);}
};
and then:
struct Equal4
: Unary_function<int, bool>
{
bool operator() (const int i)
{
return (i == 4);
}
};
then I use them like this:
STLite::find_if(p.begin(), p.end(), Unary_negate<Equal4>(Equal4()));
You see, I rewrite the find_if and iterators and Unary_function, but
they are almost the same like the STL ones.
then, as a result of compiling, I get:
functor.hpp: In member function `typename
_Adaptable_predicate::return_type
STLite::Unary_negate<_Adaptable_predicate>:perator()(int) const
[with _Adaptable_predicate = Equal4]':
algorithm.hpp:20: instantiated from `_Input_iterator
STLite::find_if(_Input_iterator, _Input_iterator, _Predicate) [with
_Input_iterator = Node_list_iterator<int, Node<int>, int*, int&>,
_Predicate = STLite::Unary_negate<Equal4>]'
main.cpp:100: instantiated from here
functor.hpp:50: error: passing `const Equal4' as `this' argument of
`bool Equal4:perator()(int)' discards qualifiers
At first, I think it's my fault when copying the STL, but I test like
this:
struct Equal4_wrap {
typedef int arg;
typedef bool ret;
Equal4 pred_;
explicit Equal4_wrap(const Equal4& p) : pred_(p) {}
ret operator() (const int& i) {return !pred_(i);}
};
which I think exactly the same as the instantialized one of
Unary_negate, and it works well, really.
I'm confused, I hope some one can help. Thank you very much!
Mao..
with the above information. Can you help me.
template <typename _Predicate>
struct Unary_negate {
typedef typename _Predicate::argument_type argument_type;
typedef typename _Predicate::return_type return_type;
_Predicate pred_;
explicit
Unary_negate(const _Predicate& p) : pred_(p) {};
bool operator() (const argument_type& x) const
{return !pred_(x);}
};
and then:
struct Equal4
: Unary_function<int, bool>
{
bool operator() (const int i)
{
return (i == 4);
}
};
then I use them like this:
STLite::find_if(p.begin(), p.end(), Unary_negate<Equal4>(Equal4()));
You see, I rewrite the find_if and iterators and Unary_function, but
they are almost the same like the STL ones.
then, as a result of compiling, I get:
functor.hpp: In member function `typename
_Adaptable_predicate::return_type
STLite::Unary_negate<_Adaptable_predicate>:perator()(int) const
[with _Adaptable_predicate = Equal4]':
algorithm.hpp:20: instantiated from `_Input_iterator
STLite::find_if(_Input_iterator, _Input_iterator, _Predicate) [with
_Input_iterator = Node_list_iterator<int, Node<int>, int*, int&>,
_Predicate = STLite::Unary_negate<Equal4>]'
main.cpp:100: instantiated from here
functor.hpp:50: error: passing `const Equal4' as `this' argument of
`bool Equal4:perator()(int)' discards qualifiers
At first, I think it's my fault when copying the STL, but I test like
this:
struct Equal4_wrap {
typedef int arg;
typedef bool ret;
Equal4 pred_;
explicit Equal4_wrap(const Equal4& p) : pred_(p) {}
ret operator() (const int& i) {return !pred_(i);}
};
which I think exactly the same as the instantialized one of
Unary_negate, and it works well, really.
I'm confused, I hope some one can help. Thank you very much!
Mao..