Boost::any and boost::lambda with std::find_if

M

Misiu

Hello everybody,

How to avoid using struct IsDataType for comparison for find_if
algorithm but use something like that what is now commented out in the
code below?

Regards,
Misiu

template<typename T>
struct IsDataType
{
bool operator() (const boost::any& operand)
{
return (operand.type() ==
typeid(boost::shared_ptr<DataDistributor<T> >));
}
};

template<typename T>
static DataDistributor<T>* GetDataDistributor()
{
std::list<boost::any>::iterator iter =
std::find_if(m_distrubutors.begin(), m_distrubutors.end(),
IsDataType<T>());

//error C2248: 'type_info::type_info' : cannot access private member
//declared in class 'type_info' boost\tuple\detail\tuple_basic.hpp 477

// std::find_if(m_distrubutors.begin(), m_distrubutors.end(),
// boost::lambda::bind(&boost::any::type, _1) ==
// typeid(boost::shared_ptr<DataDistributor<T> >));
....
}
 
M

Mathias Gaunard

Misiu said:
Hello everybody,

How to avoid using struct IsDataType for comparison for find_if
algorithm but use something like that what is now commented out in the
code below?

You should ask on the boost mailing list.
 
S

Sylvester Hesp

Misiu said:
Hello everybody,

How to avoid using struct IsDataType for comparison for find_if algorithm
but use something like that what is now commented out in the code below?

Regards,
Misiu

template<typename T>
struct IsDataType
{
bool operator() (const boost::any& operand)
{
return (operand.type() ==
typeid(boost::shared_ptr<DataDistributor<T> >));
}
};

template<typename T>
static DataDistributor<T>* GetDataDistributor()
{
std::list<boost::any>::iterator iter =
std::find_if(m_distrubutors.begin(), m_distrubutors.end(),
IsDataType<T>());

//error C2248: 'type_info::type_info' : cannot access private member
//declared in class 'type_info' boost\tuple\detail\tuple_basic.hpp 477
// std::find_if(m_distrubutors.begin(), m_distrubutors.end(),
// boost::lambda::bind(&boost::any::type, _1) ==
// typeid(boost::shared_ptr<DataDistributor<T> >));
...
}

You can't copy-construct a type_info structure. You'll need boost::ref.

- Sylvester
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top