我是否需要std :: vector <custom>?</custom>的自定义迭代器

时间:2013-12-06 18:41:06

标签: c++ vector iterator

以下代码收到编译错误:

const D_Value_BufRef_Vec& values = records.at(record_type);

// return begin/end zip iterators for traversing field:value list.
return std::make_pair(
          boost::make_zip_iterator(  
                       boost::make_tuple(fields.begin(), 
                                 values.begin())
                       ),
          boost::make_zip_iterator(
                       boost::make_tuple(fields.end(), 
                                 values.end())
                       )
          );    // <-- Line 752

字段std::vector<string>std::vector<MemRef>。以前,std::vector<string>并且编译正常。 MemRef是替换string的自定义类。

错误是:

In file included from /usr/include/boost/tuple/tuple.hpp:33,
                 from /mxhome/charrison/git/sdcore/libs/CommUtils/include/Block.h:20,
                 from ./c/Block.cpp:1:
/usr/include/boost/tuple/detail/tuple_basic.hpp: In constructor 'boost::tuples::cons<HT, boost::tuples::null_type>::cons(const boost::tuples::cons<HT2, boost::tuples::null_type>&) [with HT2 = __gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, HT = __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >]':
/usr/include/boost/tuple/detail/tuple_basic.hpp:373:   instantiated from 'boost::tuples::cons<HT, TT>::cons(const boost::tuples::cons<HT2, TT2>&) [with HT2 = __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, TT2 = boost::tuples::cons<__gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type>, HT = __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, TT = boost::tuples::cons<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::tuples::null_type>]'
/usr/include/boost/tuple/detail/tuple_basic.hpp:635:   instantiated from 'boost::tuples::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::tuple(const boost::tuples::cons<HT2, TT2>&) [with U1 = __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, U2 = boost::tuples::cons<__gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type>, T0 = __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, T1 = __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, T2 = boost::tuples::null_type, T3 = boost::tuples::null_type, T4 = boost::tuples::null_type, T5 = boost::tuples::null_type, T6 = boost::tuples::null_type, T7 = boost::tuples::null_type, T8 = boost::tuples::null_type, T9 = boost::tuples::null_type]'
/usr/include/boost/iterator/zip_iterator.hpp:488:   instantiated from 'boost::zip_iterator<IteratorTuple>::zip_iterator(const boost::zip_iterator<OtherIteratorTuple>&, typename boost::enable_if_convertible<OtherIterator, Iterator>::type*) [with OtherIteratorTuple = boost::tuples::tuple<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, IteratorTuple = boost::tuples::tuple<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>]'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h:107:   instantiated from 'std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U1 = boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, _U2 = boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, _T1 = boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, _T2 = boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >]'
./c/Block.cpp:752:   instantiated from here
/usr/include/boost/tuple/detail/tuple_basic.hpp:451: error: no matching function for call to '__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::__normal_iterator(const __gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >&)'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_iterator.h:686: note: candidates are: __gnu_cxx::__normal_iterator<_Iterator, _Container>::__normal_iterator(const _Iterator&) [with _Iterator = std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, _Container = std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >]
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_iterator.h:683: note:                 __gnu_cxx::__normal_iterator<_Iterator, _Container>::__normal_iterator() [with _Iterator = std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, _Container = std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >]
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_iterator.h:669: note:                 __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::__normal_iterator(const __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&)

偶尔出现“iterator”这个词,我想知道编译器是否不知道如何处理values.begin().end()。如果这是问题,我不明白为什么计算std::vector<string>.end()与计算std::vector<MemRef>.end()有任何不同。如果迭代器是一个抽象指针,只需要是可解除引用和可递增的,那么需要了解存储在std::vector中的特定内容需要多少?

另一方面,该错误消息可能比我看到的更多: - /

更新1: @ MikeSeymour的建议我发现封闭函数被声明为返回

std::pair< boost::zip_iterator< 
    boost::tuple< 
        std::vector<string>::iterator, 
        std::vector<string>::iterator >  // should be vector<MemRef> !!
    > ,
    boost::tuple< 
        std::vector<string>::iterator, 
        std::vector<string>::iterator >  // should be vector<MemRef> !! 
    > 
>

如上所述纠正向量后,我仍然收到错误:

In file included from /usr/include/boost/tuple/tuple.hpp:33,
                 from /mxhome/charrison/git/sdcore/libs/CommUtils/include/Block.h:20,
                 from ./c/Block.cpp:1:
/usr/include/boost/tuple/detail/tuple_basic.hpp: In constructor 'boost::tuples::cons<HT, boost::tuples::null_type>::cons(const boost::tuples::cons<HT2, boost::tuples::null_type>&) [with HT2 = __gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, HT = __gnu_cxx::__normal_iterator<MemRef*, std::vector<MemRef, std::allocator<MemRef> > >]':
/usr/include/boost/tuple/detail/tuple_basic.hpp:373:   instantiated from 'boost::tuples::cons<HT, TT>::cons(const boost::tuples::cons<HT2, TT2>&) [with HT2 = __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, TT2 = boost::tuples::cons<__gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type>, HT = __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, TT = boost::tuples::cons<__gnu_cxx::__normal_iterator<MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type>]'
/usr/include/boost/tuple/detail/tuple_basic.hpp:635:   instantiated from 'boost::tuples::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::tuple(const boost::tuples::cons<HT2, TT2>&) [with U1 = __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, U2 = boost::tuples::cons<__gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type>, T0 = __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, T1 = __gnu_cxx::__normal_iterator<MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, T2 = boost::tuples::null_type, T3 = boost::tuples::null_type, T4 = boost::tuples::null_type, T5 = boost::tuples::null_type, T6 = boost::tuples::null_type, T7 = boost::tuples::null_type, T8 = boost::tuples::null_type, T9 = boost::tuples::null_type]'
/usr/include/boost/iterator/zip_iterator.hpp:488:   instantiated from 'boost::zip_iterator<IteratorTuple>::zip_iterator(const boost::zip_iterator<OtherIteratorTuple>&, typename boost::enable_if_convertible<OtherIterator, Iterator>::type*) [with OtherIteratorTuple = boost::tuples::tuple<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, IteratorTuple = boost::tuples::tuple<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>]'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_pair.h:107:   instantiated from 'std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U1 = boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, _U2 = boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, _T1 = boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, _T2 = boost::zip_iterator<boost::tuples::tuple<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<MemRef*, std::vector<MemRef, std::allocator<MemRef> > >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >]'
./c/Block.cpp:752:   instantiated from here
/usr/include/boost/tuple/detail/tuple_basic.hpp:451: error: no matching function for call to '__gnu_cxx::__normal_iterator<MemRef*, std::vector<MemRef, std::allocator<MemRef> > >::__normal_iterator(const __gnu_cxx::__normal_iterator<const MemRef*, std::vector<MemRef, std::allocator<MemRef> > >&)'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_iterator.h:686: note: candidates are: __gnu_cxx::__normal_iterator<_Iterator, _Container>::__normal_iterator(const _Iterator&) [with _Iterator = MemRef*, _Container = std::vector<MemRef, std::allocator<MemRef> >]
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_iterator.h:683: note:                 __gnu_cxx::__normal_iterator<_Iterator, _Container>::__normal_iterator() [with _Iterator = MemRef*, _Container = std::vector<MemRef, std::allocator<MemRef> >]
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_iterator.h:669: note:                 __gnu_cxx::__normal_iterator<MemRef*, std::vector<MemRef, std::allocator<MemRef> > >::__normal_iterator(const __gnu_cxx::__normal_iterator<MemRef*, std::vector<MemRef, std::allocator<MemRef> > >&)

0 个答案:

没有答案