|
Boost : |
From: Vladimir Prus (ghost_at_[hidden])
Date: 2001-03-28 02:59:33
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?
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; //*
-- Regards, Vladimir
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk