Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:16:04+00:00 2026-06-07T15:16:04+00:00

I tried to use BOOST_FOREACH inside a template function with a custom, but type

  • 0

I tried to use BOOST_FOREACH inside a template function with a custom, but type parameter independent iterator. I get 4-5 errors suggesting that my iterator class is not well defined as an iterator.

Rewriting the loop without BOOST_FOREACH, or “un-templatizing” the function makes the errors go away.

Is this a known limitation of BOOST_FOREACH?

EDIT.

Sorry. Some code:

template <class T>
T fun()
{
    T result(0.0);

    BOOST_FOREACH(const math::IntegerVector &v, math::IntegerVectorRange(math::IntegerVector(2 , 2 ,2)))
    {
        // Do stuff.
    }

    return result;
}

The IntegerVector* types are well defined and work fine outside templates. Also they are NOT dependent on T.

The complete errors are:

make[1]: Entering directory `/home/panayk/Workspace/petros-game'
Making all in src/c++
make[2]: Entering directory `/home/panayk/Workspace/petros-game/src/c++'
depbase=`echo fluid/Tracer.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
    /bin/bash ../../libtool --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I../..   -I/usr/include/python2.7 -I/usr/include -O2 -I/usr/include/python2.7 -MT fluid/Tracer.lo -MD -MP -MF $depbase.Tpo -c -o fluid/Tracer.lo fluid/Tracer.cc &&\
    mv -f $depbase.Tpo $depbase.Plo
libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I../.. -I/usr/include/python2.7 -I/usr/include -O2 -I/usr/include/python2.7 -MT fluid/Tracer.lo -MD -MP -MF fluid/.deps/Tracer.Tpo -c fluid/Tracer.cc  -fPIC -DPIC -o fluid/.libs/Tracer.o
In file included from /usr/include/boost/iterator/iterator_categories.hpp:15:0,
                 from /usr/include/boost/iterator/detail/facade_iterator_category.hpp:7,
                 from /usr/include/boost/iterator/iterator_facade.hpp:14,
                 from ./math/Vector.h:5,
                 from ./fluid/Tracer.h:4,
                 from fluid/Tracer.cc:1:
/usr/include/boost/mpl/eval_if.hpp: In instantiation of 'boost::mpl::eval_if<mpl_::bool_<false>, boost::range_const_iterator<math::IntegerVectorRange>, boost::range_mutable_iterator<math::IntegerVectorRange> >':
/usr/include/boost/foreach.hpp:364:13:   instantiated from 'boost::foreach_detail_::foreach_iterator<math::IntegerVectorRange, mpl_::bool_<false> >'
make[2]: Leaving directory `/home/panayk/Workspace/petros-game/src/c++'
./fluid/InterpolatorGrid.h:45:3:   instantiated from here
make[1]: Leaving directory `/home/panayk/Workspace/petros-game'
/usr/include/boost/mpl/eval_if.hpp:38:31: error: no type named 'type' in 'boost::mpl::eval_if<mpl_::bool_<false>, boost::range_const_iterator<math::IntegerVectorRange>, boost::range_mutable_iterator<math::IntegerVectorRange> >::f_ {aka struct boost::range_mutable_iterator<math::IntegerVectorRange>}'
In file included from fluid/Tracer.cc:3:0:
./fluid/InterpolatorGrid.h: In member function 'T fluid::InterpolatorGrid::interpolate(const std::vector<std::vector<std::vector<T> > >&, const RealVector&) const':
./fluid/InterpolatorGrid.h:45:3: error: no matching function for call to 'begin(const boost::foreach_detail_::auto_any_base&, boost::foreach_detail_::type2type<math::IntegerVectorRange, mpl_::bool_<false> >*, boost::enable_if_c<true, boost::mpl::and_<boost::mpl::not_<boost::foreach::is_noncopyable<math::IntegerVectorRange> >, boost::foreach::is_lightweight_proxy<math::IntegerVectorRange>, mpl_::bool_<true>, mpl_::bool_<true>, mpl_::bool_<true> > >::type*&)'
./fluid/InterpolatorGrid.h:45:3: note: candidates are:
/usr/include/boost/foreach.hpp:657:1: note: template<class T, class C> boost::foreach_detail_::auto_any<typename boost::foreach_detail_::foreach_iterator<T, C>::type> boost::foreach_detail_::begin(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, C>*, mpl_::true_*)
/usr/include/boost/foreach.hpp:665:1: note: template<class T, class C> boost::foreach_detail_::auto_any<typename boost::foreach_detail_::foreach_iterator<T, C>::type> boost::foreach_detail_::begin(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, C>*, mpl_::false_*)
/usr/include/boost/foreach.hpp:676:1: note: template<class T> boost::foreach_detail_::auto_any<typename boost::foreach_detail_::foreach_iterator<T, mpl_::bool_<true> >::type> boost::foreach_detail_::begin(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, mpl_::bool_<true> >*, bool*)
/usr/include/boost/foreach.hpp:686:1: note: template<class T, class C> boost::foreach_detail_::auto_any<T*> boost::foreach_detail_::begin(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T*, C>*, mpl_::true_*)
./fluid/InterpolatorGrid.h:45:3: error: no matching function for call to 'end(const boost::foreach_detail_::auto_any_base&, boost::foreach_detail_::type2type<math::IntegerVectorRange, mpl_::bool_<false> >*, boost::enable_if_c<true, boost::mpl::and_<boost::mpl::not_<boost::foreach::is_noncopyable<math::IntegerVectorRange> >, boost::foreach::is_lightweight_proxy<math::IntegerVectorRange>, mpl_::bool_<true>, mpl_::bool_<true>, mpl_::bool_<true> > >::type*&)'
./fluid/InterpolatorGrid.h:45:3: note: candidates are:
/usr/include/boost/foreach.hpp:697:1: note: template<class T, class C> boost::foreach_detail_::auto_any<typename boost::foreach_detail_::foreach_iterator<T, C>::type> boost::foreach_detail_::end(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, C>*, mpl_::true_*)
/usr/include/boost/foreach.hpp:705:1: note: template<class T, class C> boost::foreach_detail_::auto_any<typename boost::foreach_detail_::foreach_iterator<T, C>::type> boost::foreach_detail_::end(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, C>*, mpl_::false_*)
/usr/include/boost/foreach.hpp:716:1: note: template<class T> boost::foreach_detail_::auto_any<typename boost::foreach_detail_::foreach_iterator<T, mpl_::bool_<true> >::type> boost::foreach_detail_::end(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, mpl_::bool_<true> >*, bool*)
/usr/include/boost/foreach.hpp:726:1: note: template<class T, class C> boost::foreach_detail_::auto_any<int> boost::foreach_detail_::end(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T*, C>*, mpl_::true_*)
./fluid/InterpolatorGrid.h:45:3: error: no matching function for call to 'deref(const boost::foreach_detail_::auto_any_base&, boost::foreach_detail_::type2type<math::IntegerVectorRange, mpl_::bool_<false> >*)'
./fluid/InterpolatorGrid.h:45:3: note: candidate is:
/usr/include/boost/foreach.hpp:765:1: note: template<class T, class C> typename boost::foreach_detail_::foreach_reference::type boost::foreach_detail_::deref(boost::foreach_detail_::auto_any_t, boost::foreach_detail_::type2type<T, C>*)
make[2]: *** [fluid/Tracer.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Etc. This is too much for me to decipher, but IntegerVectorRange::begin() is there and returns a const_iterator. So is IntegerVectorRange::end().

EDIT2 (IntegerVectorRange stuff)

class IntegerVectorIterator
: public boost::iterator_facade
<
    IntegerVectorIterator,
    const IntegerVector,
    boost::forward_traversal_tag
>
{
private:
    IntegerVector current;
    const IntegerVector start, limit;

    void increment();
    bool equal(const IntegerVectorIterator& other) const;
    const IntegerVector &dereference() const;

public:
    IntegerVectorIterator(const IntegerVector &start,
                          const IntegerVector &limit);
    IntegerVectorIterator(const IntegerVector &current,
                          const IntegerVector &start,
                          const IntegerVector &limit);

    friend class boost::iterator_core_access;
};

class IntegerVectorRange
{
private:
    const IntegerVector start, limit;
    const IntegerVectorIterator end_it;
public:
    IntegerVectorRange(IntegerVector limit);
    IntegerVectorRange(IntegerVector start, IntegerVector limit);

    typedef IntegerVectorIterator const_iterator;

    const_iterator begin() const;
    const const_iterator &end() const;
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:16:07+00:00Added an answer on June 7, 2026 at 3:16 pm

    Dummying up the missing classes, GCC doesn’t like it: http://ideone.com/3O3OB. Clang++ compiles it just fine. So, I’d guess you’ve got a compiler bug, or maybe a bug in all the #ifdefs in boost/foreach.hpp

    Particularly telling is this part of the instantiation backtrace:

    eval_if<bool_<false>, range_const_iterator<...>, range_mutable_iterator<...> >
    

    suggesting that whatever mechanism BOOST_FOREACH uses to determine if you’re mutable iterating or const iterating has gotten the answer wrong this time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to use an image file in my HTML template. But when I
I tried to use the following function in order to set the div's position
I tried to use Hibernate Envers to log the entity histroy. but failed. My
I tried to use object expression to extend the IDelegateEvent, but in fsi there
I tried to use Boost library but I failed, see my code: #include listy.h
I tried to use boost library in 64 bit mode of VS2008 but I'm
I wanted to use boost::thread in my program, but get the following compiler error
I tried to use Cleaver, that is PhoneGap / Cordova as a component of
I tried to use AsyncProcessor in test scenario, expecting only one message to run
I tried to use this snippet from the Soundcloud API: <script src=http://connect.soundcloud.com/sdk.js> <script> SC.initialize({

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.