|
Boost : |
From: Joaquín Mª López Muñoz (joaquin_at_[hidden])
Date: 2007-09-13 06:25:35
John Maddock ha escrito:
> Joaquín Mª López Muñoz wrote:
> > If you only want the predicate for displaying purposes, maybe you can
> > use something like this:
> >
> > template<typename T,std::size_t Size>
> > struct is_complete:boost::mpl::bool_<Size>{};
> >
> > BOOST_MPL_ASSERT((is_complete<foo,sizeof(foo)>));
>
> No that doesn't do it: you never get as far as the MPL error messages 'cos
> the sizeof(foo) fails to compile (this is what I'm using already to generate
> an error BTW).
Oh, certainly, you're right, applying sizeof() to an incomplete type is illegal, sorry
for not thinking about it hard enough. Funny thing is that in GCC 3.2 sizeof()
of an incomplete type evaluates to 0, so that
struct foo;
BOOST_MPL_ASSERT((is_complete<foo,sizeof(foo)>));
actually gets to the MPL error msg, yielding
is_complete.cpp:11: `sizeof' applied to incomplete type `foo'
is_complete.cpp:11: conversion from `mpl_::failed************is_complete<foo,
0>::************' to non-scalar type `mpl_::assert<false>' requested
is_complete.cpp:11: enumerator value for `mpl_assertion_in_line_11' not integer
constant
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk