Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-03-17 17:00:33


Hi Steven,

I've fixed the problem with is_convertible... as per Dave's suggested fix
in a private email.

There is also one other problem... though it probably won't show up with
Borland. With KAI C++, I also get an error at the
iterator_adaptor::operator[] because the return type is
value_type=Abstract. I don't see this problem with g++. I'm not sure it
should be a problem... if you don't use operator[]. However, if you did
want to use operator[] this would certainly be a problem.

To open up an old smelly can of worms... Dave, do you think this is a flaw
in using value_type as the return type for operator[]?

-Jeremy

On Fri, 16 Mar 2001, Steven Kirk wrote:

steven> Am I doing something wrong here? I'm trying to create a
steven> projection iterator that returns a reference to the object
steven> pointed to by a map's mapped_type:
steven>
steven> --
steven> #include <boost/iterator_adaptors.hpp>
steven> #include <map>
steven>
steven> class Abstract {
steven> public:
steven> virtual void example() = 0;
steven> int data;
steven> };
steven>
steven> typedef std::map<int, Abstract*> AbstractMap;
steven>
steven> struct GetReference {
steven> typedef Abstract result_type;
steven> typedef AbstractMap::value_type argument_type;
steven> Abstract &operator()(argument_type &a) const { return *a.second; }
steven> };
steven>
steven> int main(int argc, char* argv[])
steven> {
steven> AbstractMap v;
steven>
steven> boost::projection_iterator_generator<GetReference,
steven> AbstractMap::iterator>::type i;
steven>
steven> return 0;
steven> }
steven> --
steven>
steven> The problem arises because the reference I'm returning is an abstract type.
steven> I get the following errors on Borland C++ (and get similar ones on GCC):
steven>
steven> --
steven> [C++ Error] conversion_traits.hpp(108): E2352 Cannot create instance of
steven> abstract class 'Abstract'
steven> [C++ Error] conversion_traits.hpp(108): E2353 Class 'Abstract' is abstract
steven> because of 'Abstract::example() = 0'
steven> [C++ Error] ITERATOR_ADAPTORS.HPP(672): E2352 Cannot create instance of
steven> abstract class 'Abstract'
steven> [C++ Error] ITERATOR_ADAPTORS.HPP(672): E2353 Class 'Abstract' is abstract
steven> because of 'Abstract::example() = 0'
steven> [C++ Error] Unit1.cpp(23): E2450 Undefined structure
steven> 'boost::iterator_adaptor<__rwstd::__rb_tree<int,std::pair<const int,Abstract
steven> *>,__rwstd::__select1st<std::pair<const int,Abstract
steven> *>,int>,std::less<int>,std::allocator<std::pair<const int,Abstract *> >
steven> >::iterator,boost::projection_iterator_policies<GetReference>,Abstract,boost
steven> ::detail::default_argument,boost::detail::default_argument,boost::detail::de
steven> fault_argument,boost::detail::default_argument>'
steven> [C++ Error] Unit1.cpp(23): E2449 Size of 'i' is unknown or zero
steven> [C++ Error] Unit1.cpp(23): E2450 Undefined structure
steven> 'boost::iterator_adaptor<__rwstd::__rb_tree<int,std::pair<const int,Abstract
steven> *>,__rwstd::__select1st<std::pair<const int,Abstract
steven> *>,int>,std::less<int>,std::allocator<std::pair<const int,Abstract *> >
steven> >::iterator,boost::projection_iterator_policies<GetReference>,Abstract,boost
steven> ::detail::default_argument,boost::detail::default_argument,boost::detail::de
steven> fault_argument,boost::detail::default_argument>'
steven> --
steven>
steven> Can anyone help?
steven>
steven>
steven> List-Unsubscribe: <mailto:boost-unsubscribe_at_[hidden]>
steven>
steven>
steven> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
steven>
steven>
steven>

----------------------------------------------------------------------
 Jeremy Siek www: http://www.lsc.nd.edu/~jsiek/
 Ph.D. Candidate email: jsiek_at_[hidden]
 Univ. of Notre Dame work phone: (219) 631-3906
----------------------------------------------------------------------


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk