|
Boost : |
Subject: Re: [boost] [mpl] has_function
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2010-03-28 15:10:30
On Sun, Mar 28, 2010 at 10:44 AM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
> Okay. You might look at how
> https://svn.boost.org/trac/boost/ticket/861
> solves the problem.
Indeed BOOST_MPL_HAS_TEMPLATE_XXX_TRAIT_DEF() does what I need but I
still get the same "default parameter not yet parsed" error if I use
this macro at *class* scope -- see below.
The Boost.MPL doc indicates this macro should be used at namespace
scope (and that works just fine). However, I need to use it to declare
the metafunction at class scope -- is there a way to do that?
For simplicity, here I am using BOOST_MPL_HAS_XXX_TRAIT_DEF() and I
have remove the `Z` template parameter of `contract_f_`. If the macro
was to work at class scope than I would use
`BOOST_MPL_HAS_TEMPLATE_XXX_TRAIT_DEF()` from the Boost.MPL path
indicated by Steven in order to support the `Z` template parameter.
$ g++ -Wall -Werror test/noinherit/07.cpp
test/noinherit/07.cpp: In instantiation of const bool
z::has_contract_f_<x, mpl_::bool_<false> >::value:
test/noinherit/07.cpp:17: instantiated from z::has_contract_f_<x,
mpl_::bool_<false> >
test/noinherit/07.cpp:22: instantiated from here
test/noinherit/07.cpp:17: error: the default argument for parameter 1
of static char (& z::has_contract_f_<T,
fallback_>::gcc_3_2_wknd::test(const volatile
boost::mpl::aux::type_wrapper<U>*,
boost::mpl::aux::type_wrapper<typename U::contract_f_>*))[2] [with U =
x, T = x, fallback_ = mpl_::bool_<false>] has not yet been parsed
// File test/noinherit/07.cpp
#include <boost/mpl/has_xxx.hpp>
#include <iostream>
struct x {
virtual void f() {}
struct contract_f_ {};
};
struct y {
void g() {}
struct contract_g_ {};
};
struct z: x, y {
BOOST_MPL_HAS_XXX_TRAIT_DEF(contract_f_)
void f() {}
struct contract_f_ {};
static const bool bx = has_contract_f_<x>::value;
static const bool by = has_contract_f_<y>::value;
};
int main() {
std::cout << z::bx << std::endl;
std::cout << z::by << std::endl;
return 0;
}
Thanks,
Lorenzo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk