std::copy to std::cout for std::pair

前端 未结 10 646
耶瑟儿~
耶瑟儿~ 2020-12-04 20:08

I have next code:

#include 
#include 
#include 
#include 

//namespace std
//{

std::ostream&         


        
10条回答
  •  温柔的废话
    2020-12-04 21:09

    What you want is a transforming iterator. This kind of iterator wraps another iterator, forwards all positioning methods like operator++ and operator==, but redefines operator* and operator->.

    Quick sketch :

    template  
    struct transformingIterator : private ITER {
        transformingIterator(ITER const& base) : ITER(base) {}
        transformingIterator& operator++() { ITER::operator++(); return *this; }
        std::string operator*() const
        {
            ITER::value_type const& v = ITER::operator*();
            return "[" + v->first +", " + v->second + "]";
        }
    ...
    

提交回复
热议问题