Boost C++ Libraries: Ticket #7503: for_each does not compile with g++-4.7.1 https://svn.boost.org/trac10/ticket/7503 <p> Hello, </p> <p> The following code works fine with g++-4.4 and can not compile with g++-4.7.1. </p> <p> #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;type_traits&gt; #include &lt;typeinfo&gt; </p> <p> #include &lt;boost/fusion/include/map.hpp&gt; #include &lt;boost/fusion/include/filter_if.hpp&gt; #include &lt;boost/fusion/include/for_each.hpp&gt; </p> <p> namespace fusion = boost::fusion; </p> <p> template&lt;typename Key_Base_T, typename Pair_T&gt; struct is_same_key: public std::is_same&lt;Key_Base_T, typename Pair_T::first_type&gt; {}; </p> <p> struct print_ftor { </p> <blockquote> <p> template&lt;typename Key_T, typename Value_T&gt; inline void operator()(const boost::fusion::pair&lt;Key_T, Value_T&gt;&amp; pair) const { </p> <blockquote> <p> std::cout &lt;&lt; "type: " &lt;&lt; typeid(Key_T).name() &lt;&lt; ", value: " &lt;&lt; pair.second &lt;&lt; std::endl; </p> </blockquote> <p> } </p> </blockquote> <p> }; </p> <p> int main () { </p> <blockquote> <p> typedef fusion::map&lt; fusion::pair&lt;int, char&gt;, </p> <blockquote> <p> fusion::pair&lt;double, std::string&gt; &gt; </p> </blockquote> <p> map_type; </p> </blockquote> <blockquote> <p> map_type map_sequence( fusion::make_pair&lt;int&gt;('X'), </p> <blockquote> <p> fusion::make_pair&lt;double&gt;("Men") ); </p> </blockquote> </blockquote> <blockquote> <p> fusion::for_each( fusion::filter_if&lt; is_same_key&lt; double, boost::mpl::_1&gt; &gt;(map_sequence), </p> <blockquote> <p> print_ftor()); </p> </blockquote> </blockquote> <blockquote> <p> return 0; </p> </blockquote> <p> } </p> <p> The error which the compiler produces is: </p> <p> g++-4.7 -o test -std=c++0x -Wall -pedantic -I/home/veso/boost_1_52_0_beta1 main.c++ main.c++: In instantiation of ‘struct is_same_key&lt;double, mpl_::arg&lt;1&gt; &gt;’: /home/veso/boost_1_52_0_beta1/boost/fusion/algorithm/iteration/detail/for_each.hpp:32:9: required from ‘void boost::fusion::detail::for_each_linear(const First&amp;, const Last&amp;, const F&amp;, mpl_::false_) [with First = boost::fusion::filter_iterator&lt;boost::mpl::inherit2&lt;boost::fusion::forward_traversal_tag, boost::fusion::associative_tag&gt;, boost::fusion::basic_iterator&lt;boost::fusion::map_iterator_tag, boost::fusion::map&lt;boost::fusion::pair&lt;int, char&gt;, boost::fusion::pair&lt;double, std::basic_string&lt;char&gt; &gt; &gt;::category, const boost::fusion::map&lt;boost::fusion::pair&lt;int, char&gt;, boost::fusion::pair&lt;double, std::basic_string&lt;char&gt; &gt; &gt;, 0&gt;, boost::fusion::basic_iterator&lt;boost::fusion::map_iterator_tag, boost::fusion::map&lt;boost::fusion::pair&lt;int, char&gt;, boost::fusion::pair&lt;double, std::basic_string&lt;char&gt; &gt; &gt;::category, const boost::fusion::map&lt;boost::fusion::pair&lt;int, char&gt;, boost::fusion::pair&lt;double, std::basic_string&lt;char&gt; &gt; &gt;, 2&gt;, is_same_key&lt;double, mpl_::arg&lt;1&gt; &gt; &gt;; Last = boost::fusion::filter_iterator&lt;boost::mpl::inherit2&lt;boost::fusion::forward_traversal_tag, boost::fusion::associative_tag&gt;, boost::fusion::basic_iterator&lt;boost::fusion::map_iterator_tag, boost::fusion::map&lt;boost::fusion::pair&lt;int, char&gt;, boost::fusion::pair&lt;double, std::basic_string&lt;char&gt; &gt; &gt;::category, const boost::fusion::map&lt;boost::fusion::pair&lt;int, char&gt;, boost::fusion::pair&lt;double, std::basic_string&lt;char&gt; &gt; &gt;, 2&gt;, boost::fusion::basic_iterator&lt;boost::fusion::map_iterator_tag, boost::fusion::map&lt;boost::fusion::pair&lt;int, char&gt;, boost::fusion::pair&lt;double, std::basic_string&lt;char&gt; &gt; &gt;::category, const boost::fusion::map&lt;boost::fusion::pair&lt;int, char&gt;, boost::fusion::pair&lt;double, std::basic_string&lt;char&gt; &gt; &gt;, 2&gt;, is_same_key&lt;double, mpl_::arg&lt;1&gt; &gt; &gt;; F = print_ftor; mpl_::false_ = mpl_::bool_&lt;false&gt;]’ /home/veso/boost_1_52_0_beta1/boost/fusion/algorithm/iteration/detail/for_each.hpp:42:9: required from ‘void boost::fusion::detail::for_each_dispatch(Sequence&amp;, const F&amp;, Tag) [with Sequence = const boost::fusion::filter_view&lt;const boost::fusion::map&lt;boost::fusion::pair&lt;int, char&gt;, boost::fusion::pair&lt;double, std::basic_string&lt;char&gt; &gt; &gt;, is_same_key&lt;double, mpl_::arg&lt;1&gt; &gt; &gt;; F = print_ftor; Tag = boost::mpl::inherit2&lt;boost::fusion::forward_traversal_tag, boost::fusion::associative_tag&gt;]’ /home/veso/boost_1_52_0_beta1/boost/fusion/algorithm/iteration/detail/for_each.hpp:132:9: required from ‘void boost::fusion::detail::for_each(Sequence&amp;, const F&amp;, mpl_::false_) [with Sequence = const boost::fusion::filter_view&lt;const boost::fusion::map&lt;boost::fusion::pair&lt;int, char&gt;, boost::fusion::pair&lt;double, std::basic_string&lt;char&gt; &gt; &gt;, is_same_key&lt;double, mpl_::arg&lt;1&gt; &gt; &gt;; F = print_ftor; mpl_::false_ = mpl_::bool_&lt;false&gt;]’ /home/veso/boost_1_52_0_beta1/boost/fusion/algorithm/iteration/for_each.hpp:49:9: required from ‘typename boost::enable_if&lt;boost::fusion::traits::is_sequence&lt;Sequence&gt;, void&gt;::type boost::fusion::for_each(const Sequence&amp;, const F&amp;) [with Sequence = boost::fusion::filter_view&lt;const boost::fusion::map&lt;boost::fusion::pair&lt;int, char&gt;, boost::fusion::pair&lt;double, std::basic_string&lt;char&gt; &gt; &gt;, is_same_key&lt;double, mpl_::arg&lt;1&gt; &gt; &gt;; F = print_ftor; typename boost::enable_if&lt;boost::fusion::traits::is_sequence&lt;Sequence&gt;, void&gt;::type = void]’ main.c++:33:19: required from here main.c++:13:8: error: no type named ‘first_type’ in ‘struct mpl_::arg&lt;1&gt;’ make: <strong>* [all] Error 1 </strong></p> <p> For the test I used Debian stable with g++-4.7 installed from the backport repository. </p> <p> The bug appears with boost versions 1.42, 1.51, 1.51beta1 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7503 Trac 1.4.3 veso <vveesskkoo@…> Sat, 13 Oct 2012 21:43:31 GMT attachment set https://svn.boost.org/trac10/ticket/7503 https://svn.boost.org/trac10/ticket/7503 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">g4.7bug.zip</span> </li> </ul> Ticket Joel de Guzman Mon, 15 Oct 2012 05:34:54 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7503#comment:1 https://svn.boost.org/trac10/ticket/7503#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Better wrap your expression in an mpl::lambda to avoid eager evaluation (typename Pair_T::first_type). Here's how you do it: </p> <blockquote> <p> typedef is_same_key&lt; double, boost::mpl::_1&gt; expr; typedef boost::mpl::lambda&lt;expr&gt;::type func; fusion::for_each( fusion::filter_if&lt;func&gt;(map_sequence), print_ftor()); </p> </blockquote> <p> See <a class="ext-link" href="http://www.mywikinet.com/mpl/paper/html/lambda.html"><span class="icon">​</span>http://www.mywikinet.com/mpl/paper/html/lambda.html</a> for details. </p> Ticket