Boost logo

Boost :

Subject: Re: [boost] [metaparse] Practical usefulness
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2015-06-03 11:39:01


Abel Sinkovics wrote:
> This approach to write a type-safe printf displays the characters
> one-by-one on an output stream. The printf library in Mpllibs does the
> validation at compile-time and calls the "unsafe" printf at runtime (and
> has therefore no runtime overhead).

Well that's assuming that printf() is efficient at runtime.
I would like to hope that

  string s = "hello" + t + "world";

would be more efficient than

  string s = wrapper_around_printf_returning_string("hello%sworld",t.c_str());

If it isn't, we're in trouble :-)

This reminds me of a discussion on this list back in 2008 where
I was investigating fast ways of checking whether a character is in
a compile-time set of characters:

  http://article.gmane.org/gmane.comp.lib.boost.devel/171117

In effect, I implement a template like

  is_any_of<'a','e','i','o','u'>(c)

or better

  is_any_of<"aeiou">(c)

to compute

  return c=='a' || c=='e' || c=='i' || c=='o' || c=='u';

In that thread, I demonstrated that this was faster than looping
over the characters at run-time:

  bool is_any_of(const char* chars, char c) { return strchr(chars,c); }

The challenge is to instead convert it to something that does
O(log N) comparisons, rather than O(N) i.e.

  if (c < 'i') return is_any_of<'a','e'>(c);
  else return is_any_of<'i','o','u'>(c);

Does this have any relevance to Metaparse? I'm not sure. I think
the hard part of this is the "meta code generation", not the "meta
parsing". I mention it because of the string-to-char-pack stuff.

Regards, Phil.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk