CppCon 2016: 'C++14 Reflections Without Macros, Markup nor External Tooling..'

preview_player
Показать описание


C++ was lacking the reflections feature for a long time. But a new metaprogramming trick was discovered recently: we can get some information about POD structure by probing it's braced initializes. Combining that trick with variadic templates, constexpr functions, implicit conversion operators, SFINAE, decltype and integral constants we can count structure's fields and even deduce type of each field.

Now the best part: everything works without any additional markup nor macros typically needed to implement reflections in C++.


Antony Polukhin
Yandex
Hi, I'm Antony Polukhin, the author of Boost.TypeIndex and Boost.DLL libraries; maintainer of the Boost.LexicalCast, Boost.Any, Boost.Variant and Boost.Conversion libraries. I'm also the author of of the "Boost C++ Application Development Cookbook"


*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

This talk should be re-titled "punishing your compiler with witchcraft". I can't wait to start playing with this. :)

PROMuffy
Автор

This is the sickest c++ talk I've seen in forever.
never apologize for saying "tuple" instead of "toople"

RyanHaining
Автор

This video is really making me look forward to Jai and its introspection and other metaprogramming features.

derstreber
Автор

Witchery! Most vile!

But seriously, compilers deserve this abuse for not giving us proper reflection.

Автор

That's some bad-azz coding!
I did this sort of stuff for Objective-C and Smalltalk - both of which were much better geared towards "universal serialization" and "proxy objects" and so on.
I can use this. :)

MordachaiWolf
Автор

I'm feeling insecure about my C++ understanding right now :)

hippob
Автор

51:34The guy was born with a built-in C++ compiler.

pyajudeme
Автор

Just the ability to figure out the number of fields is enough for me...

kwanarchive
Автор

I would hate to debug this magic... :D

peppybocan
Автор

need to SFINAE your operator... Otherwise other writes in the same scope as your using namespace pod_ops; (say a std::string), you hit a hard error with your static_assert

connorhorman
Автор

Is there any way to use this technique to get to the names of the fields in the struct? So that I could iterate through all the fields and print the name/value pairs?

jonathanschell
Автор

Seriously, how do you get to this level? x_x I watched it all and I already know I will not get this stuff even if I watch this after 20 years xD

MarcusAseth
Автор

I do agree with statements below that this is slightly bit over complicated - and yes, I would not like to debug it as well.

I have wrote my own "demo" for C++ reflection - some initial design idea written here:


But I'm not using any simpler approach - I'm heavily misusing define's - which I not pretty solution either.

I suspect that if we could convert C++ into scriptable language ( So you can compile and execute it on fly ) - then we could use C++ to generate C++ code for C++ reflection - then 3-rd party language would not be needed at all.

Currently I suspect it's either C++ template magic or C++ preprocessor magic or Qt's MOC magic or even C# (as script) for C++ code generation - no simple solution.

But I suspect that C++ as scripting language could be next step where compilers could go.
C++ reflection is something we can reach with our code ?

tpikaro
Автор

The ubiq struct was always the same but upgraded or are different structs? ubiq_constructor and ubiq_val looks almost the same

Narblo
Автор

you can learn a thing or two here .... ;)

baumstamp
Автор

This is fucking annoyingly complicated, just make Qt the standard C++ library and drop this fucking bullshit.

paulfunigga