
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....
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
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
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).
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... Best, Roland