Embracing (and also Destroying) Variant Types Safely - Andrei Alexandrescu - CppCon 2021

Поділитися
Вставка
  • Опубліковано 28 жов 2024

КОМЕНТАРІ • 53

  • @Cookipolation
    @Cookipolation 2 роки тому +97

    Alexandrescu is one of my favorite stand up comedians, in part because he mixes in some of the best c++ content out there

    • @shoulderstack5527
      @shoulderstack5527 2 роки тому +4

      Have you seen Stroustrup? He uses a dead-pan delivery, never laughs at all, like he is dead serious. Even off-stage he never drops the illusion... genius.

    • @a314
      @a314 2 роки тому

      @@shoulderstack5527 That's being 'narcistic', not 'genius'. Modesty and humility is equally important to be a genius. Einstein was a 'genius'.

    • @vimfrw
      @vimfrw 2 роки тому +3

      I (re)watch his talks whenever I need a doze of intellectual laughter ;)

    • @origamibulldoser1618
      @origamibulldoser1618 2 роки тому +1

      That's an odd requirement for genius. I thought it was simply doing ingenious things.

  • @a314
    @a314 2 роки тому +18

    Brilliant talk. I have watched all the talks by Andrei online over the last 2 decades or so. Brilliant, fun filled man. It's kinda nostalgic to see him in grey hair. Wish him all health and long life!

  • @embeddor3023
    @embeddor3023 2 роки тому +18

    Andrei always makes the best talks at cppcon

  • @victornoagbodji
    @victornoagbodji 2 роки тому +8

    Always a pleasure to listen to Andrei talk. Thanks for sharing 😊

    • @CppCon
      @CppCon  2 роки тому +2

      Glad you enjoyed it!

  • @Snarwin
    @Snarwin 2 роки тому +6

    10:47 I think this is the most important takeaway from this talk-"static for needed for simple implementation". All of the clever implementation techniques discussed in the latter part of the talk are, essentially, workarounds for the fact that C++ does not have a "static for" loop.

    • @shipweck6253
      @shipweck6253 3 місяці тому

      what is a "static for"? can someone tell me the name of the talk where he mentioned this?

  • @LogicEu
    @LogicEu 2 роки тому +8

    This guy just keeps impressing me, great talk!

  • @robertjmccabe
    @robertjmccabe 2 роки тому +7

    Very intelligent and enjoyable talk

  • @Lalasoth
    @Lalasoth 2 роки тому +5

    He always has such interesting videos. Always learn from him.

    • @CppCon
      @CppCon  2 роки тому +2

      Glad you like them!

  • @mr_vazovski
    @mr_vazovski 2 роки тому +4

    This talk is outstanding!

  • @rhubarbjin
    @rhubarbjin 2 роки тому +5

    16:11 "Voldemort types" is my new favorite way to refer to lambda expressions. XD

  • @yoscot629
    @yoscot629 2 роки тому +1

    first(...)! great talk! perhaps instead of the member unsigned d_active, a call to variant.set sets the pointer to the destructor (so no array lookup at destruciton time, but still a function indirection overhead) and d_active can be inferred from that. not a good bargain if set/get used often though.

  • @FruchteisMitErdbeer
    @FruchteisMitErdbeer Рік тому

    Nice, I actually got directly to use the ideas from this talk at work. I didn't know you could split explicitly specified and deduced arguments into two distinct packs. That makes implementing something I thought impossible actually quite easy.

  • @userrand4900
    @userrand4900 Рік тому +2

    The example in slide 24 is broken. This was asked by a member of the audience and a non explanation was provided by the presenter.
    int b = f(1,2.5)
    Given that Ts have to be explicitly specified it will be empty in this case, and Us will always be empty due to the way matching rules work, the only way to make this work is by explicitly specifying Ts to capture all of the arguments except the last one (or not specifying it if it's empty as is the case with the first example). So
    int b = f(1, 2.5) would work and deduce as
    int f(Ts ..., Us ..., T) [with Ts = {int}; Us = {}; T = double]

  • @ShtacketT
    @ShtacketT 2 роки тому +6

    There is a 3rd thing one can do with packs: get it's length with sizeof...(Ts)

  • @Денис-ь8ь7с
    @Денис-ь8ь7с Рік тому

    Great talk, I like watching such subtleties are being described. By the way it seems there is a mistake about function parameters order, it can be detected at 27:41. In fact, the "3" will go to "Ts". In order to put it to U (and "2" to "Ts"), the function parameters should be declared as follows: f(T, Ts& ... , U). And this cooresponds to that whai is being said about the third line (the presented example can not be compiled because "4" is being bound to double)
    upd: found this issue in older comments

  • @AminAramoon
    @AminAramoon 2 роки тому +3

    great talk!

  • @userrand4900
    @userrand4900 Рік тому

    One slide 37:
    constexpr size_t m = lo + (hi - lo) / 2;
    if (n < m) {
    destroyLog(n, p);
    } else if (n > m) {
    If n < m is indeed true, the check for (lo ==m) should technically not be needed? Is it there just because the expansion is done at compile time ? In general can someone explain why we need the checks as part of the template parameters?

  • @bryankreinhart
    @bryankreinhart 10 місяців тому

    Right at the beginning, when comparing the elements of arrays to see if they are equal, before even looking at the indices of the arrays to compare, it is more efficient to compare the _sizes_ of the arrays (or vectors). If the arrays/vectors are 10 ,12 and 2 elements, then there is no point comparing the elements vertically as you know they are not equal before comparing the values at the indices. If the arrays/vectors have the same number of elements, then you can go and iterate over the index and compare the values.
    ~(EDIT: corrected typos)

  • @mijstonen
    @mijstonen 2 роки тому +2

    I deeply admire Andrei, for his C++ insights and his humor ;-) , thanks Andrei , you are (also) a great speaker. @0:20:00 you Andrei talk about adding type sequence to the standard, but .... couldn''t we consider std::tuple being such "type sequence" and shouldn't we consider lips alike operations (head,.cons,....) to be applied to a tuple ? What are your (or anyone else) thoughts about it ? Please comment.

    • @DreyriRS
      @DreyriRS 2 роки тому +3

      the way tuple is implemented involves a lot of template instantiations, either O(n) or O(logn) depending on the implementation, so it's a very heavy solution. On the other hand a type_sequence is only a single instantiation

    • @ultradude5410
      @ultradude5410 Рік тому +1

      @@DreyriRS Plus, you can construct a type_sequence, and pass it around as a value. Comes in handy if a pack *has* to be deduced.

    • @skyeplus
      @skyeplus Рік тому

      Tuple is too heavy. A lot of people, unfortunately use uninstantiated tuples to manipulate sequences of types. Yeah, there is also a necessity for type_container for a single type.

    • @thelatestartosrs
      @thelatestartosrs 11 місяців тому

      type_sequence has no storage it is a compile time construct, tuple is meant to be instanciated as an object eventually, it wouldnt respect the SRP to use tuple instead of type_sequence for this task.

  • @mujjingun
    @mujjingun 2 роки тому +5

    This man is a comedian!

  • @Bolpat
    @Bolpat 2 роки тому +4

    There’s an error on slide 19, also the explanation is wrong. On the last line, there is
     f(1, 2, 3, "4"); _// Ts = _
    The comment is correct, the instantiation of _f_ makes _Ts_ as mentioned. But _f_ “reverses” _U_ and _Ts._ The argument 2 binds to _U_ (which, correctly stated, must always be deduced), i.e. _U_ = *int.* Arguments 3 and "4" go to *const* _Ts_ & … which is ( *const int* &, *const double* & ). And "4" cannot bind to *double.*

  • @AllothTian
    @AllothTian 2 роки тому +1

    Not that C++ makes this easy but wouldn't the ideal solution at the end be to sort all types according to trivial destructibility so their indices are all grouped, then do one of 3 things at compile time: 1. Eliminate the destructor if all types are trivially destructible. 2. If you have mixed destructors, emit a single branch with a constant value and branch into the jump table if the value index is inside the range of types with destructors. 3. Eliminate the branch from (2) if all types have non-trivial destructors.

  • @skyeplus
    @skyeplus Рік тому +1

    28:00 - is there a error in slide, was it meant to be f(T, const Ts&..., U)?

    • @thelatestartosrs
      @thelatestartosrs 11 місяців тому

      it seems so, the shown code does not compile and T, Ts, u compiles

  • @AG-ld6rv
    @AG-ld6rv 2 роки тому +6

    This guy was supposed to be a comedian. Good technical side too.

  • @johnmcleodvii
    @johnmcleodvii 9 місяців тому

    While hash rable lookups can be lineaer (depending on implementation), creating the hash table can get expensive. All is fine until you have a collision. At that point, you have some choices in implementation.
    Option 1 (bad) is to scan to the next hole. This makes lookups as long as linear as well as inserts being linear. Ehen spaces run out, you will need to increase the size of yhe hash table anyway.
    Option 2. Buckets. Create a bucket to hold multiple values that hash the same. Now, you have options on how to implement this bucket. But be earned, for large enough n the runtime devolves to ehatever the bucket algorithm is. Why add the extra complexity?
    Option 3. Increase the size of the hash table. This will cause a rehash of every rntry already in the hash table. Be warned that only by doubling the size of the hash table at each increase can the amortized insert time be kept to ln(n) per insert. Constant size increases amortize to linear time per insert.
    Hash tables are also typically quite sparse when the first collision occurs.
    My takeaway is that hash tables work well for moderate size data sets where the size of the data set is fairly well known in advance.

  • @wotcherfaz
    @wotcherfaz 2 роки тому +1

    So, Andrei, what's your code going to DO when the next compiler obeys subtley different semantics about 'what expansions are allowed', and where/when the expansions are allowed... ? Scary. (Re. approx 12:45).

  • @programmingeverything
    @programmingeverything 2 роки тому +1

    around 17:30 who was the person who answered, where Andrei said he knows it because he wrote his own compiler?

  • @TheOnlyAndreySotnikov
    @TheOnlyAndreySotnikov 2 роки тому

    Slide 19 is incorrect. It won't even compile. It should be "int f(T, const Ts&..., U);"

  • @johndubchak
    @johndubchak 8 місяців тому

    Inverse Factory Method = Converse Factory Method...just a wording substitution that seems more clear and intuitive.

  • @q_rsqrt5140
    @q_rsqrt5140 2 роки тому

    Can someone elaborate on this kinds idea?

  • @userrand4900
    @userrand4900 2 роки тому

    The github link points to 2020, should point to 2021 instead to get the slides

  • @userrand4900
    @userrand4900 2 роки тому +1

    There is a typo in slide 19, "U" should be the last function argument, i.e. it should be int f(T, const Ts&..., U)

    • @daniilgavrilikhin34
      @daniilgavrilikhin34 2 роки тому

      It's not a typo. U can't be deduced, if its the parameter after pack. Actually, compiler will give you an error for this declaration

  • @themeeman
    @themeeman 2 роки тому +2

    Decent talk, took quite a while to get to the actual point though

  • @mark_fi
    @mark_fi Рік тому

    Damn. Wish I could just write everything in Rust. :D

  • @tatoute1
    @tatoute1 2 роки тому +4

    After 30+y of C++ practice, I'm forced to says that C++ is going to crumble under it's own weight.

  • @zxuiji
    @zxuiji Рік тому

    What a convoluted mess, just stick to C where everything is already properly defined, changes to expected behaviour are extremely rare, if you don't understand C then you don't know how to programme to begin with, you only understand the wrappers