T
Tigera
Hi!
I'm new to TR1, and I am trying to use the lambda library to simplify
finding a specific object within a vector. I'm using gcc-4.0.1, and I
can't figure out what namespace the placeholder for a variable (the
function object var) is in. Here is an abridged example of what I'm
trying to do:
#include <algorithm>
#include <tr1/functional>
using std::tr1:laceholder::_1;
using std::tr1:laceholder::var;
//I don't know what to use for var in std::tr1!
struct MyStruct
{
MyClass* occupant;
};
class MySystem
{
private:
vector<MyStruct> m_system;
public:
int FindByPointer(MyClass* target)
//Find the index of the target in the vector
{
return std::distance(m_system.begin(),
std::find_if(m_system.begin(), m_system.end(), (_1).occupant ==
var(target)));
}
};
Unfortunately, I receive errors when this code compiles, mentioning
that there is no occupant member in std::tr1:laceholder::_1, and that
var hasn't been declared.
Would someone please tell me:
1. How do I refer to a member/property of a user-defined class when
using _1?
2. What namespace contains the "var" functor?
Thanks for your help!
I'm new to TR1, and I am trying to use the lambda library to simplify
finding a specific object within a vector. I'm using gcc-4.0.1, and I
can't figure out what namespace the placeholder for a variable (the
function object var) is in. Here is an abridged example of what I'm
trying to do:
#include <algorithm>
#include <tr1/functional>
using std::tr1:laceholder::_1;
using std::tr1:laceholder::var;
//I don't know what to use for var in std::tr1!
struct MyStruct
{
MyClass* occupant;
};
class MySystem
{
private:
vector<MyStruct> m_system;
public:
int FindByPointer(MyClass* target)
//Find the index of the target in the vector
{
return std::distance(m_system.begin(),
std::find_if(m_system.begin(), m_system.end(), (_1).occupant ==
var(target)));
}
};
Unfortunately, I receive errors when this code compiles, mentioning
that there is no occupant member in std::tr1:laceholder::_1, and that
var hasn't been declared.
Would someone please tell me:
1. How do I refer to a member/property of a user-defined class when
using _1?
2. What namespace contains the "var" functor?
Thanks for your help!