Dynamic Polymorphism with Metaclasses and Code Injection - Sy Brand - CppCon 2020

Поделиться
HTML-код
  • Опубликовано: 22 дек 2024

Комментарии • 23

  • @dekadebashish
    @dekadebashish 3 года назад +8

    The initial vtable implementation is what I was looking for. Thank you for such a great talk.

    • @CppCon
      @CppCon  3 года назад

      Great to hear!

  • @dgkimpton
    @dgkimpton 4 года назад +9

    What a fantastic talk. I love the fact that you were able to pull together all these concepts into a single extremely useful scenario, present it in all in less than an hour, and leave me drooling about the future possibilities.
    I'm not sure whether to be super excited about the future or super frustrated that we don't have these things yet. Metaclasses are just fantastic, code injection is killer, and with static reflection will do a lot to eliminate macros (finally). Some of the syntax is just gnarly, I guess that's the price of backwards compatibility, but the final result is so expressive and awesome.
    Anyway, thank you so much for sharing this talk, great food for thought.

  • @robrick9361
    @robrick9361 5 месяцев назад +1

    Is the block evaluation consteval valid in C++20?

  • @klaus13337
    @klaus13337 4 года назад +1

    Animal a = Cat{}; a.Speak();.... "I am a Miezekatze!"
    Awesome, great talk! I never really thought about making something like this work using modern C++.

  • @TNothingFree
    @TNothingFree 3 года назад +4

    Good thing C++ is keeping up with the best practices.
    Meta infromation with static compilation would result in very efficient generic code.
    I just hope it would be readable as well :D

  • @adamodimattia
    @adamodimattia 7 месяцев назад

    Dynamic polymorphism personified!🎉

  • @relegarum
    @relegarum 4 года назад +3

    Amazing talk, Sy! One of the most inspiring ones at cppcon this year!

  • @Swedishnbkongu
    @Swedishnbkongu 3 года назад

    I've often thought to myself value semantics are fine with runtime polymorphism if child classes do not introduce extra state. Then the slicing doesn't matter, and the vtable pointer is copied. Any disagreements?

  • @foible2085
    @foible2085 4 года назад

    How would the compiler be able to use in-place storage for the concrete type? Since there can be arbitrarily many concrete types, would the compiler need to enumerate all instantiations before deciding on the in-place storage size? It seems like another language feature would be needed to achieve this? I guess there can be a predetermined size specified and just compiler error if it doesn't fit? The SBO is a cool idea.

    • @HasanKamalAlDeen
      @HasanKamalAlDeen 3 года назад +1

      Late to the party but you got it in that last sentence. Sy described a storage-policy based setup, where you feed the metaclass what kind of storage policy you're looking for (code for that wasn't shown, presumably because this is still early days). The storage policy would indicate to the metaclass how you want concrete classes to be stored and he showed 3 examples:
      1. Remote storage: always allocate the concrete type on the heap
      2. SBO storage: specify a fixed size at the time of definition of the interface (eg when `animal` is defined); any concrete class that fits into the SBO would be copied into it, any larger type would be heap allocated
      3. Local storage only: specify a fixed size at the time of definition of the interface (eg when `animal` is defined); concrete classes are _always_ copied into the local buffer. If an attempt is made to copy-in a concrete type that is too large for the buffer, a compiler error is emitted
      All 3 of these approaches perform the work on assignment / construction of the object, meaning that the compiler never has to enumerate classes to identify success / failure cases.

  • @jmparis83
    @jmparis83 4 года назад +1

    Mind blowing ! Great talk, thanks!

  • @rolandschulz6811
    @rolandschulz6811 4 года назад +2

    Links to libraries: github.com/boost-ext/te#similar-libraries

  • @OperationDarkside
    @OperationDarkside 4 года назад +1

    I really want some of this to make general serialization possible. Web development with C++ isn't really a nice experience atm.

  • @jhbonarius
    @jhbonarius 4 года назад

    Note: if you replace the std::cout code in your godbolt example with printf, you don't get this huge ostream assembly... The copy constructor is not working though godbolt.org/z/KoxraP

  • @ihormay3418
    @ihormay3418 4 года назад

    Great talk! Really enjoyed the material

  • @jhbonarius
    @jhbonarius 4 года назад +1

    These structures seem so re-usable, that IMHO they should be part of a standard library. (When reflection becomes part of the standard)

  • @rinkaenbyou4816
    @rinkaenbyou4816 3 года назад

    1:07 "Perks of virtual conferences"

  • @larssamsung3033
    @larssamsung3033 3 года назад +3

    One has to hate macros A LOT to think that code is nicer.

  • @joesilver75
    @joesilver75 4 года назад

    great talk

  • @LDdrums20
    @LDdrums20 3 года назад

    So this is basically c++ wanting to be c#. Am I getting it wrong?

  • @stephenjames2951
    @stephenjames2951 4 года назад

    Null it is the nothing we spend too much time caring about.