
Boost : 
From: Daryle Walker (darylew_at_[hidden])
Date: 20080709 04:40:25
On Jul 9, 2008, at 3:02 AM, joaquin_at_[hidden] wrote:
> Daryle Walker escribió:
>> Here's what I'm trying (to redo integer_test.cpp)
> [...]
>> BOOST_STATIC_ASSERT
>> ( (boost::is_same<distinct_integral_bit_counts,
>> boost::mpl::list_c<int, 8, 16, 32, 64> >) );
>> }
>>
> I think there are two problems with this:
>
> 1. You're passing a *type* (boost::is_same<...>) to
> BOOST_STATIC_ASSERT
> when you should be passing a numeric contanst. Append ::value to
> the type.
Can't believe I missed that....
> 2. Even with the correction above the thing won't work because
> is_same<T,Q> checks
> for strict equality of the types T and Q; in your case
> distinct_integral_bit_counts
> is *not* the same type as boost::mpl::list_c<...>, but only has the
> same components.
> You can use boost::mpl::equal to test this:
>
> BOOST_STATIC_ASSERT
> ( (boost::mpl::equal<distinct_integral_bit_counts,
> boost::mpl::list_c<int, 8, 16, 32> >::value) );
> }
>
> Other than that, your type_to_digit_count is perfectly lambda
> cabable AFAICS. HTH,
Thanks. I switched to mpl::equal and it compiled. I later switched
to BOOST_MPL_ASSERT. (Remember to take _out_ the "::value" part!) I
originally had the "integral_c" part of "type_to_digit_count" as a
member called "type," instead of as a base class, then I switched
back and forth. Both ways work. Why is that? And which way is best
(if they're not equally good, and without a better third alternative)?
//==============================
// New type list: integral type > (wrapped) number of bits
// Should the "integral_c" part be a base class or direct member?
template < typename T >
struct type_to_digit_count //: integral_c<int,
std::numeric_limits<T>::digits>
{ typedef integral_c<int, std::numeric_limits<T>::digits> type; };
typedef boost::mpl::transform<distinct_unsigned_types,
type_to_digit_count<boost::mpl::_1> >::type
distinct_integral_bit_counts;
BOOST_MPL_ASSERT( (boost::mpl::equal<distinct_integral_bit_counts,
boost::mpl::list_c<int, 8, 16, 32, 64> >) );
//==============================
 Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk