Boost logo

Boost :

Subject: Re: [boost] compile time parser generator
From: Ábel Sinkovics (abel_at_[hidden])
Date: 2012-01-09 14:19:09


> From: Fernando Pelliccioni
>> A little code improvement
>> template<typename ArrayType, size_t N>
>> constexpr ArrayType nth( const ArrayType (&s)[N], int n )
>> {
>> return n>= N ? 0 : s[n];
>> }
> Hmmm, now that I think of it:
> int S[] = {1, 1, 2, 3, 5, 8};
> some_template<nth<size_of(S)>(S, 3)>
> is pretty nice to have in TMP too.
> Thanks,
> Luke

I made an implementation of it part of the compile-time parsing library
(metaparse) on github. Its purpose is to simplify the definition of
boost::mpl::string values the following way:

instead of boost::mpl::string<'hell','o wo','rld'>
you can write _S("hello world")

It has an "nth" (I called it array_at there) constexpr function and a
metafunction building the mpl::string. Using a helper metafunction it
converts string literals of any length (up to
MPLLIBS_METAPARSE_STRING_MAX_LENGTH) to boost::mpl::string. It uses a
helper metafunction to avoid appending 0 characters at the end when the
string literal is shorter than the max length. Implementation:
It contains Fernando's improvement to the code as well.


Boost list run by bdawes at, gregod at, cpdaniel at, john at