Re: [boost] How do you make MPL-compatible template meta-functions?

Daryle Walker escribió:
On Jul 9, 2008, at 3:02 AM, joaquin@tid.es wrote:
[...]
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?
Because integral_c (and all other integral constant types in Boost.MPL) evaluates to itself, that is, it has the form: template<typename T, T N>struct integral_c { typedef integral_c<T,N> type; ... };
And which way is best (if they're not equally good, and without a better third alternative)?
I don't think it makes any difference in compile times or otherwise, but deriving from integral_c is terser and more MPL-idiomatic. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (1)
-
joaquin@tid.es