Boost logo

Boost :

From: Doug Gregor (gregod_at_[hidden])
Date: 2001-03-28 12:03:52

On Wednesday 28 March 2001 02:59, you wrote:
> 1. I have just downloaded the most recent version of any_function, which
> documentation says it compiles under bcc 5.5.1, but it doesn't! The
> following simple code fails to compile:
> #include <boost/any_function.hpp>
> void foo(int) {}
> int main()
> {
> boost::any_function<void, int> v;
> v = foo;
> }
> The problem seems to be in using enums for constants in various places.
> Consider:
> template<int i> struct I { enum { val = i }; };
> template<int i> struct V {};
> template<int i>
> struct S {
> enum { val = I<i>::val };
> typedef V<val> type; // 1
> };
> Given this declarations, bcc thinks that S<23>::type is ... V<0>! This is
> cleary bug, which affects any_function.hpp. I'm not sure if it can be
> workarounded, leaving enums, but one can change val to static const int
> member, and change line #1 to
> typedef V<int(S::val)> type;
> This will work. I actully wonder why enum is used for const values. Is
> there any other compiler that has problems with static const ints?

Sorry, foolish oversight on my part. BOOST_STATIC_CONSTANT is meant to deal
with this (MSVC is one of the compilers that can handle enums but not static
const ints).

> 2. I found explicit ctor of any_function not very good idea.
> - It adds no safety at all, but is a big encumbrance.
> - Is it reasonable to make ctor explicit while permitting assigment
> without explicit conversion? Don't you think that if conversion of type
> A to type B is considered dangerous, then both marked lines should not
> compile?
> struct S {
> S();
> S(const B& b) : b(b) {};
> B b;
> };
> A a;
> S s1(a); //*
> S s2;
> s2.b = a; //*

Thank you for noticing this, I'd forgotten. In a prior incarnation of
any_function, I had been running into compiler problems with non-explicit
constructors of the form:

template<typename T> class_name(T);

However, this does not appear to be the case currently, and it makes no sense
to disallow implicit conversions to any_function.

I've uploaded an updated version of any_function with the
BOOST_STATIC_CONSTANT fix and with implicit conversions from any function
Simple test programs run properly on VC++ 6, BC++ 5.5.1, GCC-2.95.2, GCC-3.1
(prerelease), and Comeau 4.2.44b3.

The newest version is available at:

Finally, I'll be leaving town Friday and won't be back for a week, so I
apologize in advance if bug reports for any_function go untouched.


Boost list run by bdawes at, gregod at, cpdaniel at, john at