Boost logo

Boost :

Subject: Re: [boost] [metaparse] performance comparisons?
From: Roland Bock (rbock_at_[hidden])
Date: 2015-06-07 14:40:56


On 2015-06-07 11:41, Evgeny Panasyuk wrote:
> 07.06.2015 12:07, Roland Bock пишет:
>
>> However, this is limited in the way that the type cannot be based on a
>> literal outside a struct/class. There also is a macro that can be
>> employed to create such types, e.g:
>>
>> SQLPP_ALIAS_PROVIDER(hello);
>>
>> static_assert(
>> std::is_same<hello_t::_alias_t,
>> sqlpp::char_sequence<'h', 'e', 'l', 'l', 'o',
>> '\000'>>::value,
>> "");
>>
>>
>> The MACRO cannot be called in a function, though, since local classes
>> must not have static members.
>
> Following code works OK:
>
> int main()
> {
> struct specific_compiletime_string
> {
> static constexpr const char *value()
> {
> return "abc";
> }
> };
> static_assert(specific_compiletime_string::value()[0] == 'a', "");
> // passes!
> }
>
> And you can get char sequence in following way:
> https://github.com/panaseleus/ctte/blob/master/proof_of_concept/proof_of_concept.cpp#L82-L86
>
Very nice, indeed!

Using a lambda, I can then do:

#define MAKE_CHAR_SEQUENCE(name) \
  []() \
  { \
    struct _intern \
    { \
      static constexpr const char* value() \
      { \
        return #name; \
      } \
    }; \
                                                  \
    return make_string<_intern, sizeof(#name)>{}; \
  }()

int main()
{
  auto x = MAKE_CHAR_SEQUENCE(delta);
  static_assert(
      std::is_same<
          decltype(x),
          sqlpp::char_sequence<'d', 'e', 'l', 't', 'a', '\000'>>::value,
      "");
}

(code attached)

Cool, I'll use that. It will allow users to define/use aliases in-place.

But: Lamda expressions cannot live in unevaluated code. Thus

using X = decltype(MAKE_CHAR_SEQUENCE(delta));

is illegal :-(

>
>> Thus, while I assume that it is faster than what happens inside the
>> MPLLIBS_STRING (haven't measured it), its use is more limited, too.
>
> As I understand, complexity of MPLLIBS_STRING comes from fact that it
> can be passed immediately as template argument.
>
I guess so, too.

MAKE_CHAR_SEQUENCE can be used as a function argument at least :-)




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