Boost logo

Boost Users :

Subject: Re: [Boost-users] another metaprogramming question
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-03-13 16:36:50


AMDG

Noah Roberts wrote:
> This seems to me like it should work. Yet the check() call resolves,
> without error, to the first one...which should cause an error and
> trigger SFINAE. Can anyone help me figure out what gives?
>
> Compiler is MSVC++ 8. Normally the SFINAE stuff works so I'm betting
> on my mistake this time.
>
> Basically I need to check it the metafunction meta<T> returns
> something. If it does then the object is a record. If it doesn't
> then it is not.

What do you mean by "returns something"?
meta<T>::type always exists, so SFINAE doesn't apply.

> template < typename RECORD >
> struct meta
> {
> struct type;
> };
>
> <snip>
>
> struct test { typedef boost::mpl::vector< int, double > fields; };

Would this work:

BOOST_MPL_HAS_XXX_TRAITS_DEF(fields);
template<typename RECORD>
struct field_is_sequence : boost::mpl::is_sequence<typename
RECORD::fields> {};
template<typename RECORD>
struct meta : boost::mpl::and_<has_fields<RECORD>,
field_is_sequence<RECORD> > {};

> int main()
> {
> // output is 1\n1\n.
> std::cout << is_record_check<test>::value << std::endl;
> std::cout << is_record_check<int>::value << std::endl;

meta<int>::type exists, and since only a pointer to
it is used it isn't instantiated.

> // meta<int>::type x; - yet this will cause compilation error.

Now meta<int>::type is instantiated, so we get a compilation error.

In Christ,
Steven Watanabe


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