Boost logo

Boost :

From: Arun Sivaramakrishnan (aruns_at_[hidden])
Date: 2001-02-13 08:36:38

----- Original Message -----
From: "Doug Gregor" <gregod_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Sunday, January 21, 2001 8:10 AM
Subject: [boost] any_function ("Callback" library)
> I've tested it on MSVC++ 6.0sp4 and GCC 2.95.2. The only difference is in
> initialization:
> any_function<int, int, int> f1 = plus<int>(); // 1
> any_function<int, int, int> f2 (plus<int>()); // 2
> VC++ can handle 2 but not 1; GCC can handle 1 but not 2 :)

Here are a few of my observations on any_function lib.
*Isn't VC++ is right in rejecting 1 (given that the constructor has the
explict keyword)
*Copy Constructor (atleast in VC++ ) is never called :the templated function
is called instead
for example
 typedef any_function<int, int, int> tf1;
  tf1 f1(plus<int>()); //4
  tf1 f1_1(f1); //5
  5 calls the tenplated constructor and not tf1::tf1(const tf1&)
*also for assignment operator the templated cousin is called instead of
tf1::operator=(const tf1&)

To make 5 work, we could do something similar to what was done in
the class boost::any.
A MSVC_INCLUDE(template<>) could be added to the copy constructor.
and the assigment operator
But, VC++ also requires that we change the argument in
template<typename Functor>
  explicit any_function(Functor f)


template<typename Functor>
  explicit any_function(const Functor& f)

    template<typename Functor>
    any_function& operator=(Functor f)


    template<typename Functor>
    any_function& operator=(const Functor& f)

Is this change acceptable?.

PS: I have the attached the code with the changes.

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