STL_ ассоциативные контейнеры и_итераторы (1114991), страница 2
Текст из файла (страница 2)
end () , ostream_iterator < double >( cout , ’\ n ’ ));http://compscicenter.ru20/23STL: ассоциативные контейнеры и итераторыКак написать свой итератор# include < iterator >template< class Category ,class T ,// iterator::iterator_category// iterator::value_typeclass Distance = ptrdiff_t , // iterator::difference_typeclass Pointer = T * ,// iterator::pointerclass Reference = T &// iterator::reference> class iterator ;struct MyIterator: std :: iterator < bidirectional_iterator_tag , Person >{// ++, --, ...};http://compscicenter.ru21/23STL: ассоциативные контейнеры и итераторыФункторы и предикаты∙ Функтор — класс, объекты которого ведут себя какфункции, т.е.
имеет перегруженные operator()∙ Предикат — функтор возвращающий bool.Функторы в стандартной библиотеке:1. less, greater, less_equal, greater_equal,not_equal_to, equal_to2. minus, plus, divides, modulus, multiplies3. logical_not, logical_and, logical_or4. mem_fun, mem_fun_ref, ptr_fun5.
bind1st, bind2nd, not1, not2map < int , string , greater < int > > m ;bind2nd ( less < int >() ,10);bind1st ( modulus < size_t > , 1024);not1 ( logical_not < bool >());http://compscicenter.ru22/23STL: ассоциативные контейнеры и итераторыКак написать свой функтор# include < functional >template < class Arg , class Result >struct unary_function {typedef Arg argument_type ;typedef Result result_type ;};template < class Arg1 , class Arg2 , class Result >struct binary_functio n {typedef Arg1 f i r s t _ a r g u m e n t _ t y p e ;typedef Arg2 s e c o n d _ a r g u m e n t _ t y p e ;typedef Result result_type ;};struct MyFunctor : binary_function < int , double , size_t >{size_t operator ()( int i , double d ) {...}};http://compscicenter.ru23/23.