Boost logo

Boost Users :

From: Michael W Daniels (daniels_at_[hidden])
Date: 2005-03-10 22:15:08


In experimenting with the new BOOST_FOREACH header, I'm getting the compile
error (MSVC 7.1) below with this code. The documentation for BOOST_FOREACH
says:

>The support for STL containers is very general; anything that looks like
>an STL container counts. If it has nested iterator and const_iterator
>types and begin() and end() member functions, BOOST_FOREACH will
>automatically know how to iterate over it.

I've checked, and the hashed_array_tree class does have nested iterator and
const_iterator types, as well as begin() and end() member functions. (It's
originally from www.cphstl.dk, but that site no longer provides the code.)

Replacing hashed_array_tree with vector gets rid of the error, so there's
obviously something I need to fix in the hashed_array_tree. How do I figure
out what that is, though?

Any help will be greatly appreciated.

===code===
#include <memory>
#include <iostream>

#include "foreach.hpp"
#include "math_utils.hpp"
#include "hashed_array_tree.hpp"
#include "hat_iterator.hpp"

using namespace std;
using namespace boost;
using namespace cphstl;

class A {
public:
   int foo;
};

void test() {
   const hashed_array_tree<const A*>* Ahat = new hashed_array_tree<const A*>();
   BOOST_FOREACH(const A* curA, *Ahat) cout << curA->foo;
}
======

==error==
e:\Projects\gidlp\fsparser\foreach.hpp(455) : error C2440: 'return' :
cannot convert from 'const std::allocator<_Ty>::value_type' to
'boost::iterator_reference<Iterator>::type'
         with
         [
             _Ty=const A *
         ]
         and
         [
             Iterator=boost::range_const_iterator<cphstl::hashed_array_tree<const
A *>>::type
         ]
         Conversion loses qualifiers
         e:\Projects\gidlp\fsparser\test2.cpp(20) : see reference to
function template instantiation 'boost::iterator_reference<Iterator>::type
boost::for_each::deref<cphstl::hashed_array_tree<T>,boost::mpl::true_>(boost::for_each::static_any_t,boost::for_each::container<cphstl::hashed_array_tree<T>,C>)'
being compiled
         with
         [
             Iterator=boost::range_const_iterator<cphstl::hashed_array_tree<const
A *>>::type,
             T=const A *,
             C=boost::mpl::true_
         ]
======

-- 
Michael W. Daniels        | Choreography is its own reward.
daniels_at_[hidden]      | Some things are done only for the sake
Doctoral Candidate        | of form. Don't fight it by looking for
Department of Linguistics | substance in everything. 

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net