Re: [Boost-bugs] [Boost C++ Libraries] #3270: Ambiguous conversion, even though no conversion exists

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #3270: Ambiguous conversion, even though no conversion exists
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-07-18 10:37:40

#3270: Ambiguous conversion, even though no conversion exists
 Reporter: Olaf Lenz <lenzo@…> | Owner: dgregor
     Type: Bugs | Status: new
Milestone: Boost 1.40.0 | Component: function
  Version: Boost 1.39.0 | Severity: Problem
 Keywords: |

Comment(by lenzo@…):

 Replying to [comment:1 steven_watanabe]:
> Any type can be converted to a boost::function.
> The declaration of the conversion always exists,
> which is all that the compiler checks for in overload
> resolution. The conversion doesn't compile unless
> the type has a function call operator.

 That is a pity. Then I guess there is no way to make it work.

> > I think that this can be considered a bug. Or what else can I do in
 this case?
> Did you really intend to make the overload for A const
> and the overload for boost::function non-const?

 Indeed, that is what I wanted. Probably I should introduce the actual
 application: I'm having a (self-written) container class "Set", which
 provides internal iterators, i.e. a method "foreach", which is overloaded
 in several ways. Here, T is the type of the contained objects.

 class Set {
   virtual foreach(boost:function< void (T) >);
   virtual foreach(boost:function< void (const T) >) const ;
   virtual foreach(Computer);
   virtual foreach(ConstComputer) const;

 where Computer and ConstComputer are defined as follows:

 class Computer {
   virtual void prepare();
   virtual void apply(T);
   virtual void finalize();

 class ConstComputer {
   virtual void prepare();
   virtual void apply(const T);
   virtual void finalize();

 The idea is that it is possible to use foreach with an arbitrary function,
 or with an object of type "Computer", which provides the methods prepare()
 and finalize() to be called before and after the loop. To be able to loop
 over a constant container of constant objects, it would be nice to be able
 to use a ConstComputer.
 Unfortunately, this is where the code fails. Also, it looks as though
 there is no way round it other than to use two functions. Or is there?

 Best regards

Ticket URL: <>
Boost C++ Libraries <>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:00 UTC