Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-09-05 20:08:25


Faheem Mitha <faheem_at_[hidden]> writes:

> Hi,
>
> The following bit of code using Boost Function compiles fine with gcc
> 3.3 or later, but has problems with the Intel C++ compiler version
> 9.1, which produces the following error message.
>
> Is this a compiler bug, or is there something wrong with the code?

Looks like a compiler bug.

> If the former, I'd be grateful for suggestions of a workaround

Maybe

      boost::function<int()> choice(&rchoice<dim>);

or

      boost::function<int()> choice(rchoice<dim>);

or

       int (*pf)() = &rchoice<dim>;
       boost::function<int()> choice(pf);
       
or

       int (*pf)() = rchoice<dim>;
       boost::function<int()> choice(pf);
       
> Note that the corresponding version with no templates compiles without
> problems.
>
> **************************************************************************
>
> icpc -o foo.o -c -Wall -Werror -g -wd383,810,981,1418 cxxlib-icc
> -DBOOST_RAND -I/usr/local/include/boost-1_33_1 \foo.cpp
>
> foo.cpp(12): error: no operator "=" matches these operands operand
> types are: boost::function<int (), std::allocator<void>> =
> <unknown-type>
> choice = &rchoice<dim>;
> ^
> *************************************************************
> #include <boost/function.hpp>
>
> template<int dim>
> int rchoice()
> {
> return 1;
> }
>
> template<int dim> int foo(void)
> {
> boost::function<int ()> choice;
> choice = &rchoice<dim>;
> return choice();
> }
>
> int main()
> {
> return foo<2>();
> }
> ***************************************************************

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net