[Iterator] zip iterator with std::tuple or std::pair
Hello, as far as I understand the zip_iterator is compatible also with STL tuple and pair. However, when I try to create a zip_iterator with std::pair it fails to compile. Here, a simple test code: #include <vector> #include <utility> #include <boost/iterator/zip_iterator.hpp> int main () { std::vector<int> v(4); boost::make_zip_iterator(std::make_pair(v.begin(), v.begin())); return 0; } compiled with gcc 4.9.2 and boost 1.62 returns me (tested also with 1.63): In file included from /software/boost-1.62/include/boost/iterator/zip_iterator.hpp:26:0, from test.cpp:3: /software/boost-1.62/include/boost/mpl/at.hpp: In instantiation of ‘struct boost::mpl::at_c<std::pair<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<int*, std::vector<int>
, 0l>’: /software/boost-1.62/include/boost/iterator/zip_iterator.hpp:180:17: required from ‘struct boost::iterators::detail::zip_iterator_base<std::pair<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<int*, std::vector<int>
’ /software/boost-1.62/include/boost/iterator/zip_iterator.hpp:237:9: required from ‘class boost::iterators::zip_iterator<std::pair<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<int*, std::vector<int> ’ test.cpp:8:64: required from here /software/boost-1.62/include/boost/mpl/at.hpp:42:8: error: no class template named ‘apply’ in ‘struct boost::mpl::at_impl<boost::mpl::non_sequence_tag>’ struct at_c ^ In file included from test.cpp:3:0: /software/boost-1.62/include/boost/iterator/zip_iterator.hpp: In instantiation of ‘struct boost::iterators::detail::zip_iterator_base<std::pair<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<int*, std::vector<int> ’: /software/boost-1.62/include/boost/iterator/zip_iterator.hpp:237:9: required from ‘class boost::iterators::zip_iterator<std::pair<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<int*, std::vector<int> ’ test.cpp:8:64: required from here /software/boost-1.62/include/boost/iterator/zip_iterator.hpp:180:17: error: no type named ‘type’ in ‘struct boost::mpl::at_c<std::pair<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<int*, std::vector<int> , 0l>’ >::type difference_type; ^ /software/boost-1.62/include/boost/iterator/zip_iterator.hpp:198:11: error: no type named ‘type’ in ‘struct boost::mpl::at_c<std::pair<__gnu_cxx::__normal_iterator<int*, std::vector<int> >, __gnu_cxx::__normal_iterator<int*, std::vector<int> , 0l>’ > type;
I get a similar results for std::tuple compiled c++11 enabled gcc. I did not find any solution, except a 3 year old patch, which is said to be applied to the boost::iterator library. Any suggestions? Best regards, Matthias
Thank you! It works! Am 2017-03-23 14:50, schrieb Michel Morin via Boost-users:
Matthias Wohlgemuth wrote:
as far as I understand the zip_iterator is compatible also with STL tuple and pair.
Try #include <boost/fusion/adapted/std_pair.hpp> or #include <boost/fusion/adapted/std_tuple.hpp> .
Regards, Michel _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- Matthias Wohlgemuth Arbeitsgruppe Prof. Dr. Roland Mitric Lehrstuhl für Theoretische Chemie Institut für Physikalische und Theoretische Chemie Julius-Maximilians Universität Würzburg Emil-Fischer-Straße 42 97074 Würzburg Tel: +49-931-31-88862 Mobil: +49-151-50678023 Mail: matthias.wohlgemuth@uni-wuerzburg.de
Try #include <boost/fusion/adapted/std_pair.hpp> or #include <boost/fusion/adapted/std_tuple.hpp>
Does the community think it's reasonable that `boost::zip_iterator` should automatically support `std::tuple` when c++11 or better is detected? It seems to me that this would be less surprising and encourage more use of the (fantastic) zip_iterator. On 23 March 2017 at 14:50, Michel Morin via Boost-users < boost-users@lists.boost.org> wrote:
Matthias Wohlgemuth wrote:
as far as I understand the zip_iterator is compatible also with STL tuple and pair.
Try #include <boost/fusion/adapted/std_pair.hpp> or #include <boost/fusion/adapted/std_tuple.hpp> .
Regards, Michel _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Matthias Wohlgemuth
-
Michel Morin
-
Richard Hodges