Boost C++ Libraries

PrevUpHomeNext

Workarounds

result_of_
detect_result_type.hpp
CONST
OVERLOADED

Egg provides some workaround utilities.

Description

boost::result_of has some problems especially under Boost1.34 or below:

  • boost::result_of can't take a cv-qualified function pointer as the target function.
  • Under msvc-7.1 or msvc-8.0 with Boost1.34 or below, boost::result_of can't take POD template as the target function.

So that, Egg provides its own "result_of" with slightly different name.

[Caution] Caution

If you already use Boost1.35 and don't pass a cv-qualified function pointer, you don't need this workaround.

[Note] Note

The former bug can probably be worked around by applying a patch to Boost.ResultOf.

Header
  • <boost/egg/result_of.hpp>
Valid expressions

Valid expression

Semantics

result_of_

boost::result_of with some workaround.

See also
Description

BOOST_MPL_HAS_XXX_TRAIT_DEF, which Boost.ResultOf and Boost.Lambda depend on, sometimes fails to work under the msvc compilers. When you see a weird error message such that "nested sig template is undefined" or "nested result template is undefined", use this header.

[Note] Note

This bug can probably be worked around by applying a patch to Boost.Lambda and Boost.ResultOf.

Header
  • <boost/egg/detect_result_type.hpp>
Valid expressions

Valid expression

Semantics

#include <boost/egg/detect_result_type.hpp>

Turns on the workaround.

Preconditions
  • <boost/egg/detect_result_type.hpp> must be included before any Boost headers.
See also
Description

When you define a Function Object in namespace scope, GCC might show unused variable warnings without this macro.

[Tip] Tip

Strictly speaking, a const-qualified object in namespace scope incurs ODR(One Definition Rule) violation. Though a conforming workaround is found, even GCC can't do the right thing around address constant expression. Anyway, it is unlikely for this violation to cause significant problem.

Header
  • <boost/egg/const.hpp>
Valid expressions

Valid expression

Semantics

BOOST_EGG_CONST((F), obj) = init;

F const obj = init;

Preconditions
  • F is POD which is not cv-qualified.
  • This macro is placed in namespace scope.
Example
BOOST_EGG_CONST((T_foo), foo) = &foo_impl;
Description

Under GCC 3.4.x, when you overload call in Little Function with the same arity, the following workaround is needed to disambiguate overload resolution.

Header
  • <boost/egg/overloaded.hpp>
Valid expressions

Valid expression

Semantics

BOOST_EGG_OVERLOADED_PREAMBLE()

Turns on the workaround.

BOOST_EGG_OVERLOADED(R)

Helps overload resolution.

Preconditions
  • BOOST_EGG_OVERLOADED_PREAMBLE() is placed first in Little Function.
  • BOOST_EGG_OVERLOADED(R) is placed first in parameter list of every call.
  • R is return type of call.
Example

struct little_foo
{
    BOOST_EGG_OVERLOADED_PREAMBLE() 1

    template<class Me, class A1>
    struct apply
    {
        typedef A1 &type;
    };

    template<class Re, class A1>
    Re call(BOOST_EGG_OVERLOADED(Re) A1 &a1) const 2
    {
        return a1;
    }

    template<class Re, class A1>
    Re call(BOOST_EGG_OVERLOADED(Re) A1 const &a1) const
    {
        return a1;
    }
};

1

Egg turns on the workaround if this macro is found.

2

Notice there is no trailing comma.

See also

PrevUpHomeNext