|
Boost : |
Subject: Re: [boost] Library proposal: binconst, constant of the binary form.
From: TaeKyeong Wang (bugiii_at_[hidden])
Date: 2009-01-15 16:17:26
I know BOOST_BINARY. It is a excellent tool, but error message of
following expression is confused.
unsigned int bb1 = BOOST_BINARY( 01234 );
In VC 2008 EE, about seven hundred warning messages and one error
message is outputted. I want to the error message explaining why it is
wrong.
warning C4003: not enough actual parameters for macro
'BOOST_DETAIL_SPLIT_AND_SWAP_PARAMS'
...
fatal error C1009: compiler limit : macros nested too deeply
The Previous proposal has a problem.
BB_( 012 ); // Passed. (013)oct == (11)dec
I propose simple and straightforward implementation again.
Thanks.
----- binconst-1.h
template< unsigned int N >
struct binary_byte
{
static const unsigned int value = N % 8 + 2 * binary_byte< N / 8 >::value;
error_if_not< 0 <= N && N <= 011111111 > Out_Of_Range;
error_if_not< N % 8 <= 1 > Invalid_Binary_Digit;
};
template<>
struct binary_byte< 0 >
{
static const unsigned int value = 0;
};
template< unsigned int B1, unsigned int B0 >
struct binary_word
{
static const unsigned int value =
(binary_byte< B1 >::value << 8) +
(binary_byte< B0 >::value);
};
template< unsigned int B3, unsigned int B2, unsigned int B1, unsigned int B0 >
struct binary_dword
{
static const unsigned int value =
(binary_word< B3, B2>::value << 16) +
(binary_word< B1, B0 >::value);
};
#define BB_( b0 ) \
binary_byte< 0##b0 >::value
#define BW_( b1, b0 ) \
binary_word< 0##b1, 0##b0 >::value
#define BD_( b3, b2, b1, b0 ) \
binary_dword< 0##b3, 0##b2, 0##b1, 0##b0 >::value
2009/1/15 David Abrahams <dave_at_[hidden]>:
>
> on Wed Jan 14 2009, "TaeKyeong Wang" <bugiii-AT-gmail.com> wrote:
>
>> C++ programmers want to input a constant of the binary form, like
>> following. But, this is illegal in C++ world.
>>
>> unsigned char value = 0b10001010;
>>
>> There are some solutions of this lack. But, I can't find the gratifying answer.
>
> http://www.boost.org/doc/libs/1_37_0/libs/utility/utility.htm#BOOST_BINARY
> ??
>
> --
> Dave Abrahams
> BoostPro Computing
> http://www.boostpro.com
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk