|
Boost : |
Subject: Re: [boost] [metaparse] Practical usefulness
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2015-06-02 18:18:07
christophe.j.henry_at_[hidden] wrote:
> I feel I have to slightly steer the review in
> the right (IMO) direction, which means in the direction where the review is
> based on the quality of the library and documentation, not on pure
> formalities.
I agree with your steering direction.
So let me ask a question: how useful is this library in practice,
beyond "toy examples"?
Was this library developed with a real application, i.e. use in
a product, as its motivation, or was it written to test the
limits of what is possible using metaprogramming?
My first reaction to the library was "cool!". My second reaction
was "it's a toy to demonstrate metaprogramming". Then I saw the
printf() example and my third (and for now final!) though is that,
yes, this could be useful.
In another thread, Peter Dimov asked about getting char packs from
string literals. It seems to me that if we had that then we
could implement printf() without needing a "parser library" at
all:
template <char c1, char... c>
class formatter
{
public:
template <typename... ARGS>
void operator()(ARGS... args...) {
std::cout << c1;
formatter<c...>()(args...);
}
};
template <char... c>
class formatter<'%','d',c...>
{
public:
template <typename... ARGS>
void operator()(int i, ARGS... args...) {
std::cout << i;
formatter<c...>()(args...);
}
};
template <char c1>
class formatter<c1>
{
public:
void operator()() {
std::cout << c1;
}
};
int main()
{
formatter<'h','e','l','l','o','%','d','!'>()(42);
}
So maybe all that I really want is the preprocessor magic to turn
string literals into something that's more useful at compile time.
Or a language feature to do that.
Or maybe somehow constexpr can do it all for me. Anyone have a
constexpr implementation of printf()?
Hmm.
Cheers, Phil.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk