Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-04-09 09:06:50


From: "Doug Gregor" <gregod_at_[hidden]>

> I would like to solicit input from those interested in any_function,
> especially regarding the interface & semantics. Barring major
> omissions/oversights/etc, I'll be requesting a formal review within a few
> days.

Interface:

* I propose to rename any_function to just 'boost::function'. :-)
* The numbered variants (function0, function1, etc) are quite handy for
defining interfaces, since if you maintain a library that defines

void f(boost::function<X, Y> const & g);

and you compile against, say, boost 1.23.0 (where boost::function has 7
template parameters) but your users compile against boost 1.23.2, where
boost::function has 10 template parameters, their program won't link. This
can be solved by defining boost::function0, boost::function1, and so on, so
the library function would be

void f(boost::function1<X, Y> const & g);

and boost::function<R, A1, ..., AN> would be an alias for
boost::functionN<...> (no template typedefs, but a public inheritance would
probably suffice.)

Implementation:

This program:

#include <iostream>

#include <boost/any_function.hpp>

int f()
{
 return 0;
}

int main()
{
 boost::any_function<int> F(f);

 std::cout << F();

 return 0;
}

does not compile with MSVC 7.0 beta 1 (strange)

C:\Projects\include\boost\any_function.hpp(505) : error C2667:
'boost::detail::has_empty_target' : none of 7 overloads have a best
conversion

[...]

C:\Projects\testbed\testbed.cpp(19) : see reference to function template
instantiation
'boost::any_function<R,T1,T2,T3,T4,T5,T6>::any_function<R,T1,T2,T3,T4,T5,T6>
(const Functor)' being compiled
        with
        [
            R=int,
            T1=boost::detail::unusable,
            T2=boost::detail::unusable,
            T3=boost::detail::unusable,
            T4=boost::detail::unusable,
            T5=boost::detail::unusable,
            T6=boost::detail::unusable,
            Functor=int (*)(void)
        ]

and Intel C++ 5.0 (stranger still)

C:\PROJECTS\INCLUDE\boost/any_function.hpp(309) : error: non-integral
operation not allowed in nontype template argument
                           (count_used_args<T1, T2, T3, T4, T5, T6>::value +
                                                                           ^

--
Peter Dimov
Multi Media Ltd.

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