|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-01-09 08:44:17
Terje Slettebø <tslettebo_at_[hidden]> writes:
>>From: "Hartmut Kaiser" <hartmutkaiser_at_[hidden]>
>
>> David Abrahams wrote:
>>
>> > > // The following expands to
>> > > //
>> > > // typedef char (&sizeN_t)[N];
>> > > //
>> > > // for N = 1..BOOST_MAX_SIZETYPE_COUNT
>> > > #define SIZETYPE(z, n, nil) \
>> > > typedef char (&size ## n ## _t)[n]; \
>> > > /**/
>> >
>> > Careful; isn't the symbol "_t" reserved to the implementation
>> > in this context?
>>
>> The purpose of the macros was to generate a couple of
>> typedef char (&sizeN_t)[N]; // for N=1..MAX
>> Statements, so _t is never seen by the compiler.
>>
>> But anyway the solution proposed by Paul is cleaner, so I vote for it.
>
>>From Paul's posting:
>
>> You can achieve the effect you want easily:
>>
>> template<int I> struct size_descriptor {
>> typedef char (& type)[I];
>> };
>>
>> typedef size_descriptor<1>::type yes_type;
>> typedef size_descriptor<2>::type no_type;
>>
>> ...or something similar, which solves the problem once and for all.
>
> Looks good. What should we call it? size_descriptor, like here?
I already have such a metafunction in Boost.Python. It's called
"char_array", since after all that's what it produces.
boost/boost/python/detail/char_array.hpp
-- David Abrahams dave_at_[hidden] * http://www.boost-consulting.com Boost support, enhancements, training, and commercial distribution
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk