I have this Functor:
typedef std::vector < std::string > String_vec;
typedef std::vector < String_vec > StrVec_vec;
class Compare : public std::unary_func tion<String_vec , void>
{
public:
StrVec_vec myData;
Compare(StrVec_ vec const& data) : myData(data) {}
void operator() (const String_vec& data) const
{
StrVec_vec datax = myData;
std::pair<StrVe c_vec::iterator , StrVec_vec::ite rator > range =
std::equal_rang e(datax.begin() , datax.myData.en d(), data,
DataCompare());
}
};
This one above compiles fine (Visual Studio 7.0), but the assignment of
myData to datax seems a waste, and I would rather have it this way:
.....
void operator() (const String_vec& data) const
{
std::pair<StrVe c_vec::iterator , StrVec_vec::ite rator > range =
std::equal_rang e(myData.begin( ), myData.myData.e nd(), data,
DataCompare()); // I access myData directly in the loop instead of first
assigning it to datax and then using datax in the loop
}
......
BUT this last variant does not compile ??????????????? ???? (Error message
"..... cannot convert parameter 1 from 'const std::vector<_Ty ,
_Ax>::const_ite rator' to 'std::vector<_T y, _Ax>::_Tptr .............")
Anyone got a clue why myData variable is OK as an assignment to a temporary,
and this temporary is OK in the loop, while myData is not OK in the loop?
This does not make sense to me!
RCS
typedef std::vector < std::string > String_vec;
typedef std::vector < String_vec > StrVec_vec;
class Compare : public std::unary_func tion<String_vec , void>
{
public:
StrVec_vec myData;
Compare(StrVec_ vec const& data) : myData(data) {}
void operator() (const String_vec& data) const
{
StrVec_vec datax = myData;
std::pair<StrVe c_vec::iterator , StrVec_vec::ite rator > range =
std::equal_rang e(datax.begin() , datax.myData.en d(), data,
DataCompare());
}
};
This one above compiles fine (Visual Studio 7.0), but the assignment of
myData to datax seems a waste, and I would rather have it this way:
.....
void operator() (const String_vec& data) const
{
std::pair<StrVe c_vec::iterator , StrVec_vec::ite rator > range =
std::equal_rang e(myData.begin( ), myData.myData.e nd(), data,
DataCompare()); // I access myData directly in the loop instead of first
assigning it to datax and then using datax in the loop
}
......
BUT this last variant does not compile ??????????????? ???? (Error message
"..... cannot convert parameter 1 from 'const std::vector<_Ty ,
_Ax>::const_ite rator' to 'std::vector<_T y, _Ax>::_Tptr .............")
Anyone got a clue why myData variable is OK as an assignment to a temporary,
and this temporary is OK in the loop, while myData is not OK in the loop?
This does not make sense to me!
RCS
Comment