Boost logo

Boost :

From: Ralf W. Grosse-Kunstleve (rwgk_at_[hidden])
Date: 2003-06-07 07:50:16


--- Douglas Gregor <gregod_at_[hidden]> wrote:

Hi Doug,

> If you could figure out what alignment value you're trying to get a type for
> it would help greatly. One way you could do it would be to replace the
> static assertion lines with something that will halt the compile and give
> back the Align value in an error message, e.g.,

Thanks a lot for your message!

> // somewhere
> template<bool DontPrintIt, std::size_t Align> struct maybe_print_align {
> typedef void type; }
> template<std::size_t Align> struct maybe_print_align<false, Align> {};
>
> // instead of the static asserts:
> typedef typename maybe_print_align<(found >= Align), Align>::type foobar;
>
> Note that when those static asserts fail, it means that you aren't getting
> back a type with the right alignment.

That's a cool trick and it works great. I've expanded your templates
to also print the value of the "found" constant:

template<bool DontPrintIt, std::size_t Align, std::size_t Found> struct
maybe_print_align { typedef void type; };
template<std::size_t Align, std::size_t Found> struct maybe_print_align<false,
Align, Found> {};

typedef typename maybe_print_align<(found >= Align), Align, found>::type
foobar;

Here is the error:

/var/tmp/mac/boost/boost/type_traits/type_with_alignment.hpp:120:
error: no type named `type' in `boost::maybe_print_align<false, 8, 4>'

The full error message is here:

http://cci.lbl.gov/~rwgk/tmp/mac_os_10_alignment_problem

FYI: In the meantime we've found out that the PowerPC doesn't have
strict alignment requirements (but unaligned access may be associated
with performance penalties). After a discussion with David Abrahams
I've disabled the static assertions in type_with_alignment.hpp:

#if !(defined(__APPLE__) && defined(__MACH__) && defined(__GNUC__))
    BOOST_STATIC_ASSERT(found >= Align);
    BOOST_STATIC_ASSERT(found % Align == 0);
#endif

Ralf

__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk