CppCon 2016: Marshall Clow “STL Algorithms - why you should use them, and how to write your own"

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ต.ค. 2016
  • CppCon.org
    -
    Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/cppcon/cppcon2016
    -
    One of the most powerful features of the C++ standard library is the collection of basic algorithms. Everyone knows about sort and copy, but there are is a lot of powerful capabilities in the other algorithms as well. In this talk, I will explore some of the algorithms in the library, and give a rationale for writing your own, along with examples.
    The motivation for writing your own algorithms is that you can create generic building blocks that can be used over and over again in your library or application, and which will allow your to program at a higher level of abstraction. Instead of thinking, "how do I sort this vector", you just call std::sort. The same should apply to the algorithms that are specific to your domain - once you write them.
    -
    Marshall Clow
    Principal Engineer, Qualcomm, Inc.
    Marshall is a long-time LLVM and Boost participant. He is a principal engineer at Qualcomm, Inc. in San Diego, and the code owner for libc++, the LLVM standard library implementation. He is the author of the Boost.Algorithm library and maintains several other Boost libraries.
    -
    Videos Filmed & Edited by Bash Films: www.BashFilms.com
    *-----*
    Register Now For CppCon 2022: cppcon.org/registration/
    *-----*

ความคิดเห็น • 33

  • @emanuellandeholm5657
    @emanuellandeholm5657 ปีที่แล้ว +3

    I just found all these CppCon videos. Not a C++ dev by any means, but these lectures are so good. Thanks!

  • @videofountain
    @videofountain 7 ปีที่แล้ว +6

    Practical Gentle Introduction.

  • @__hannibaalbarca__
    @__hannibaalbarca__ ปีที่แล้ว +3

    I see video two times
    1. Just to understand English
    2. To Understand Algorithm.

  • @YourCRTube
    @YourCRTube 7 ปีที่แล้ว +33

    Nice talk, but a bit too 'entry level'. May be follow-up next year?

    • @michaelchadwick4920
      @michaelchadwick4920 7 ปีที่แล้ว +13

      I agree. It's a good introduction, but not very satisfying for anyone who's already written quite a few STL-style algorithms.

  • @benyuan620
    @benyuan620 7 ปีที่แล้ว +13

    but compile error is really not so friendly

  • @mrlithium69
    @mrlithium69 7 ปีที่แล้ว +9

    I wish he explained 12:00 why you would NOT want to use post-increment first++ operators instead of ++first , he even says the compile down to the same thing. What is the big deal about post-increment operators in the STD/STL

    • @daggawagga
      @daggawagga 6 ปีที่แล้ว +18

      He mentions the reason some time later. Using the post-increment creates another requirement imposed on the iterator. If you have less requirements then the algorithm can be applied in a wider variety of cases. Another case mentioned later uses the same reasoning when using first != last instead of first < last. All iterator types support !=, but not all of them support

    • @stephenhowe4107
      @stephenhowe4107 4 ปีที่แล้ว +9

      They are inefficient. The canonical way to implement them is to save the old iterator value, call ++iterator, return the old value.
      I would only call the post-increment iterator if I needed the old value and do wish to increment.

  • @childhood1888
    @childhood1888 2 ปีที่แล้ว +1

    36:00

  • @gast128
    @gast128 6 ปีที่แล้ว +2

    adjacent_pair is quite an useful algorithm; please propose or add to Boost. Also I support the suggestion to use good names, but it seems that the STL is a major offender here (e.g. std::remove_copy which has nothing to with std::remove but more like copy_if_not or copy_omit).

    • @jamesflames6987
      @jamesflames6987 4 ปีที่แล้ว +5

      std::remove_copy performs the same function as std::remove except it is not in place.

  • @So1dier
    @So1dier 4 ปีที่แล้ว +4

    Would be better if he shown how to use it in the code with an example

  • @broken_abi6973
    @broken_abi6973 7 ปีที่แล้ว +12

    I find std::algorithms very hard/non-intuitive to use. I have to always go online to refresh my memory on what each algorithm does and the order of its arguments and outputs. I would prefer a more functional programming or range syntax.

    • @neqkk
      @neqkk 7 ปีที่แล้ว +4

      They become much easier to use after reading Alexander Stepanov' Elements of Programming and watching is A9 lectures here on youtube. It was a bit disappointing from the presenter btw not to mention his name in the first place.

    • @JuanGarcia-zy8yw
      @JuanGarcia-zy8yw 7 ปีที่แล้ว +12

      LOLLLLLL with how complex c++ is and you get those beautiful easy to use abstractions and you still complain... bruh...

    • @cmlon
      @cmlon 7 ปีที่แล้ว +10

      He did mention him, at 29:13 and 30:01

    • @JuanGarcia-zy8yw
      @JuanGarcia-zy8yw 7 ปีที่แล้ว +4

      yoooooooo thank you for sharing that im loving his lectures. real in depth analysis with basic examples, and historical facts about programming . so awesome.

    • @edilsongiachini5847
      @edilsongiachini5847 6 ปีที่แล้ว

      u ar dumb

  •  7 ปีที่แล้ว +2

    I'm pretty sure that std::copy example has a bug in it (if 'first' points to an element after 'last' it will break). That for loop should be using "first < last" as the end condition to work around that. (hopefully that's how a real implementation does it).

    • @timpavlic6188
      @timpavlic6188 7 ปีที่แล้ว +25

      Input Iterators are not expected to have operator < defined. As was mentioned, the minimum amount of constraints are placed on types in the STL algorithms. Also, the documentation for std::copy says it will copy the range [first, last). If your parameters cannot represent that range, then you are invoking undefined behaviour. As an example, lets say we have an 8-bit micro with address range 0x00 to 0xFF. I want to copy the very last and first byte of the valid memory range to somewhere else.
      // Please excuse the use of C casts
      uint8_t* first = (uint8_t*)0xFF;
      uint8_t* last = (uint8_t*)0x01;
      uint8_t* out = (uint8_t*)0xAA;
      std::copy(first, last, out);
      This is both valid and well defined on my system, as pointers are 8-bit and will wrap from 0xFF to 0x00, thereby representing a valid copyable range.

    • @yiluan6133
      @yiluan6133 6 ปีที่แล้ว +3

      Ionuț Leonte Also watch around 38:00

  • @X_Baron
    @X_Baron 6 ปีที่แล้ว +2

    I find this clow funn.

  • @Fetrovsky
    @Fetrovsky 7 ปีที่แล้ว +6

    "A templated function" ... I hate that expression.

    • @N00byEdge
      @N00byEdge 7 ปีที่แล้ว +1

      Daniel Jesús Valencia Sánchez Well then maybe this talk is not for you

    • @tobiasfuchs7016
      @tobiasfuchs7016 6 ปีที่แล้ว +7

      I feel you. It's a "function template". It's a template that serves to specify functions. Not a template function, and not a templated function. Just like `std::vector` is not a class, it's a class template. `std::vector` is a class.
      I like the talk very much and recommend it to my students in my course, but many speakers, including some living legends, are rather imprecise about that and it does bother me a tad.

  • @indrajitbanerjee4350
    @indrajitbanerjee4350 4 ปีที่แล้ว +1

    There is no such thing as a 'templated function'. It's a 'function template' :)

  • @keyhanjannatkhah6729
    @keyhanjannatkhah6729 2 ปีที่แล้ว +1

    C++ has nice features but going to be so complex and unreadable. for system programming the system should be visible and understandable with simple concepts, C is much better in this way. with all respect to all efforts behind C++, unfortunately, it try abstract itself and the whole system in the wrong way. complexity over complexity.

    • @godDIEmanLIVE
      @godDIEmanLIVE 2 ปีที่แล้ว +1

      C is a part of CPP so everything you describe is opt-in.

  • @moderncpp
    @moderncpp ปีที่แล้ว

    adjacent_pair is very useful 👌