Subject: Re: [boost] [metaparse] performance comparisons?
From: Evgeny Panasyuk (evgeny.panasyuk_at_[hidden])
Date: 2015-06-07 13:23:12


07.06.2015 18:51, Roland Bock:
> On 2015-06-07 12:40, 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);
>>
>> By the way, I saw sqlpp11 earlier, and I think that alias/field
>> provider is a useful meta-programming tool on it's own.
>> https://github.com/rbock/sqlpp11/blob/master/include/sqlpp11/alias_provider.h#L33-L48
>>
>>
>> For example it can be used in transformation of vector of structs into
>> structs of vectors - such macro would provide names for fields in
>> synthesized struct of references.
>>
>> Perhaps it could be embedded by default into
>> BOOST_FUSION_DEFINE_STRUCT and others.
>>
>>
>> Also I think following template intrinsic can be useful addition to
>> C++ ISO:
>>
>> template<char...> struct names_provider;
>>
>> Which would be automatically specialized by compiler on usage, for
>> example something like:
>>
>> template<>
>> struct names_provider<'f', 'o', 'o'>
>> {
>> template<typename T>
>> struct field
>> {
>> T foo;
>> };
>> template<typename F>
>> struct method
>> {
>> template<typename ...Ts>
>> auto foo(Ts... args)
>> {
>> return F{}(args...);
>> }
>> };
>> // ...
>> };
>
> Right, I use this in sqlpp11 and sqlpp11-connector-stl (an experimental
> SQL interface to vectors or other containers).

sqlpp11 uses a bit different thing - it generates special name_t struct
which has inside "field" provider and name stored as compile-time string.
Here I am talking about mapping from compile-time string to "field"
provider.

>> With help of such intrinsic it is possible to parse string with some
>> EDSL at compile time, and based only on this generate all required
>> structures defined by language embedded in string.
> It is still a PITA with the inheritance required to turn such things
> into members of a struct.
>
> I presented an idea of how to do this with much less pain here:
>
> https://groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/hYh3hWB0mwg/mDgCErbUXbMJ

As I understand you proposed here name/identifier literal, which of
course is useful thing, but here specifically I am talking about mapping
from compile-time string to field provider.

That would enable following use-case:

generate_struct_t<CT_STRING(R"(
struct
{
  2: i32 id,
  1: string name
}
)")> value;
value.id = 11;
value.name = "abc";

Metafunction generate_struct_t accepts EDSL compile-time string, parses
it, extracts compile-time substrings "id" and "name", uses
names_provider<'i', 'd'> and names_provider<'n','a','m','e'> to get
field providers, gathers them to one struct and returns it's type.

Best Regards,
Evgeny Panasyuk