|
Boost : |
From: Daryle Walker (darylew_at_[hidden])
Date: 2008-07-09 02:09:11
Here's what I'm trying (to redo integer_test.cpp):
//==============================
#include <boost/config.hpp>
#include <boost/limits.hpp>
#include <boost/integral_c.hpp>
#include <boost/mpl/list.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/static_assert.hpp>
#include <boost/type_traits.hpp>
#include <climits>
namespace
{
// List all the conventional integral types, without the ones
that are like
// a strong-typedef of a lower type
typedef boost::mpl::list<unsigned char
#if USHRT_MAX > UCHAR_MAX
, unsigned short
#endif
#if UINT_MAX > USHRT_MAX
, unsigned int
#endif
#if ULONG_MAX > UINT_MAX
, unsigned long
#endif
#if defined(BOOST_HAS_LONG_LONG) && ((ULLONG_MAX > ULONG_MAX) ||
(ULONGLONG_MAX > ULONG_MAX))
, boost::ulong_long_type
#elif defined(BOOST_HAS_MS_INT64) && (0xFFFFFFFFFFFFFFFFui64 >
ULONG_MAX)
, unsigned __int64
#endif
> distinct_unsigned_types;
typedef boost::mpl::transform<distinct_unsigned_types,
boost::make_signed<boost::mpl::_1> >::type distinct_signed_types;
// New type list: integral type -> (wrapped) number of bits
template < typename T >
struct type_to_digit_count
: boost::mpl::integral_c<int, std::numeric_limits<T>::digits>
{
};
typedef boost::mpl::transform<distinct_unsigned_types,
type_to_digit_count<boost::mpl::_1> >::type
distinct_integral_bit_counts;
BOOST_STATIC_ASSERT
( (boost::is_same<distinct_integral_bit_counts,
boost::mpl::list_c<int, 8, 16, 32, 64> >) );
}
//==============================
I originally did not have that last line there with the
"BOOST_STATIC_ASSERT," but I put it in after some errors when doing a
compiler-sanity check while coding. I cleaned up the other errors,
but the compiler complains that the first argument of "is_same," i.e.
"distinct_integral_bit_counts," is an invalid template argument. I
don't think my definition of "type_to_digit_count" is lambda-safe,
like "make_signed" is. How do I get it that way? (Or is the problem
in the definition of "distinct_integral_bit_counts"?)
-- 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