I am struggling to find out why I can't get transform to work with a template class.
Here's a simplified version of the template class :
template<typename T>
class base
{
public :
base() : all_() {}
~base() {}
public:
bool add(T t)
{
typename vector<T>::iterator itr
= lower_bound(all_.begin(), all_.end(), t);
if ( itr == all_.end() || *itr != t )
{
all_.push_back(t);
cout << "ok" << endl;
return true;
}
cout << "failed" << endl;
return false;
}
static bool addTo(base<T> *c, T t)
{
return c->add(t);
}
private :
vector<T> all_;
};
And this is where I am trying to use transform to capture all the bool output from the add member function :
main()
{
base<int> test;
vector<bool> results;
vector<int> toAdd;
toAdd.push_back(10);
toAdd.push_back(11);
toAdd.push_back(10);
transform( toAdd.begin(), toAdd.end(),
back_inserter(results),
bind1st( (bool(*)(base<int>*,int))base<int>::addTo, &test ) );
}
The aim is to insert each member of the toAdd container suing the either base::add or base::addTo, and capture the bool results in the vector results