pstade

PrevUpHomeNext

Workarounds

pstade::result_of
detect_result_type.hpp
deduced_form
DEFER
CONST

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 const-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 a POD template as the target function.
[Note] Note

If you already use Boost1.35 and don't pass a const-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
  • <pstade/result_of.hpp>
Valid expressions

Valid expression

Semantics

pstade::result_of

boost::result_of with some workaround.

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.

Valid expressions

Valid expression

Semantics

#include <pstade/detect_result_type.hpp>

A msvc workaround for BOOST_MPL_HAS_XXX_TRAIT_DEF

Preconditions
  • <pstade/detect_result_type.hpp> must be included before any Boost headers.
Description

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

Header
  • <pstade/egg/deduced_form.hpp>
Valid expressions

Valid expression

Semantics

deduced_form

A type

Example

struct little_foo
{
    1typedef deduced_form call_strategy;

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

    2template<class Result, class A1>
    Result call(boost::type<Result>, A1 &a1) const
    {
        return a1;
    }

    template<class Result, class A1>
    Result call(boost::type<Result>, A1 const &a1) const
    {
        return a1;
    }
};

typedef function<little_foo> T_foo;

1

This enables the workaround.

2

Result is given with the first argument using boost::type.

[Note] Note

You can also use Boost.EnableIf instead.

See also
Description

Under msvc-8.0, boost::mpl::apply<PlaceholderExpression,..> randomly fails at the instantiation process in boost::result_of. So that, deferred that depends on boost::mpl::apply needs a workaround.

Header
  • <pstade/egg/deferred.hpp>
Valid expressions

Valid expression

Semantics

PSTADE_EGG_DEFER((Lam))

deferred<Lam>::type with some workaround.

PSTADE_EGG_DEFER_BY((Lam), _Stg)

deferred<Lam, _Stg>::type with some workaround.

Preconditions
  • This macro is placed in non-deduced context, meaning that you can't add typename to this macro.
  • The corresponding semantics is a valid expression.
See also
Description

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

[Note] Note

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
  • <pstade/egg/const.hpp>
Valid expressions

Valid expression

Semantics

PSTADE_EGG_CONST((F), obj) = init;

F const obj = init;

Preconditions
  • F is a POD type which is not cv-qualified.
  • This macro is placed in namespace scope.
  • The corresponding semantics is a valid expression.
Example
PSTADE_EGG_CONST((T_foo), foo) = &foo_impl;
See also
  • ...
Copyright 2007 Shunsuke Sogame

PrevUpHomeNext