|
Boost : |
Subject: Re: [boost] [mpl] has_function
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2010-04-02 15:18:34
Hello,
On Sun, Mar 28, 2010 at 3:10 PM, Lorenzo Caminiti <lorcaminiti_at_[hidden]> wrote:
> 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.
I was able to get around this problem by always passing the 2nd
parameter using member() without using the default parameter 0 -- see
code below.
1) This does not give the GCC "default parameter not yet parsed" error
(it compiles fine on both GCC and MVSC).
2) This can be used either at namespace or at class scope (while
BOOST_MPL_HAS_TEMPLATE_XXX_TRAIT_DEF() cannot be used at class scope).
3) Should Boost.MPL consider using a similar technique to allow to use
BOOST_MPL_HAS_TEMPLATE_XXX_TRAIT_DEF() within class scope?
// Check if class T has a member named name (using SFINAE).
// Must use internal symbols for T and U to aovid name clashes at
class scope.
template<class contract_T_>
class has_contract_f_ {
typedef char yes;
typedef char (&no)[2];
static contract_T_* object();
// Using default param 0 instead of member() does not work on GCC.
template<class contract_U_)>
static typename contract_U_::name* member(contract_U_*);
static int member(...);
template<contract_U_>
static yes tester(contract_U_*, typename contract_U_::name*);
static no tester(...);
public:
static const bool value =
sizeof(tester(object(), member(object()))) == sizeof(yes);
typedef boost::mpl::bool_<value> type;
};
Thanks to everyone for your suggestions on this!
Lorenzo
P.S. I am not sure the GCC "default parameter not yet parsed" error I
got is compliant with ISO C++ standard (because of
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21903 and because the code
with the default parameter 0 compiles just fine under MSVC).
Therefore, I submitted a GCC ticket on this
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43561.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk