|
Boost : |
From: rogeeff (rogeeff_at_[hidden])
Date: 2002-02-11 18:18:26
I can't seems to make Projection Iterator to work with ptr_fun.
Here is modified example on projection iterator:
#include <boost/config.hpp>
#include <list>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <string>
#include <functional>
#include <boost/iterator_adaptors.hpp>
struct personnel_record {
personnel_record( std::string n, int id ) : m_name(n), m_ID(id) {}
std::string m_name;
int m_ID;
};
const std::string&
select_name( const personnel_record& r )
{
return r.m_name;
}
int main(int, char*[])
{
std::list<personnel_record> personnel_list;
personnel_list.push_back(personnel_record("Barney", 13423));
personnel_list.push_back(personnel_record("Fred", 12343));
personnel_list.push_back(personnel_record("Wilma", 62454));
personnel_list.push_back(personnel_record("Betty", 20490));
std::copy( boost::make_projection_iterator( personnel_list.begin(),
std::ptr_fun( select_name ) ),
boost::make_projection_iterator( personnel_list.end(),
std::ptr_fun( select_name ) ),
std::ostream_iterator<std::string>( std::cout, "\n" ) );
std::cout << std::endl;
return 0;
}
Any ideas?
Gennadiy.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk