CppCon 2014: Stephan Lavavej "STL Features And Implementation Techniques"

CppCon · 23K views · 2014 · 59:42

Open on YouTube

C, C++, Rust, Go & systems languagesSoftware architecture & designtalk

Why Stack Overflow recommends it

Stack Overflow users link it as an authoritative source from the STL maintainer on allocators, literal namespaces, dual-range algorithms and SFINAE details.

Recommended by 8 people across 8 different months, 2014 to 2021.

What it is

Stephan T. Lavavej, who maintains Visual C++'s standard library at Microsoft, gives a CppCon 2014 talk on underappreciated C++11/14 library features. Topics include dual-range algorithms, minimal allocators, heterogeneous associative lookup, and the implementation tricks behind them.

What people said

Recommends Drop · 2014-11 · Stack Overflow · on “Vector manipulation using STL algorithms”

Probably it would be an interesting addition. Mr. STL thinks that "1.5-iterator-range" binary algorithms overloads are bad and it is a road to undefined behavior. He recommends using overloads with 2 ranges. See CppCon 2014: Stephan Lavavej "STL Features And Implementation Techniques" [this video] (from 8:00)

Recommends Dietmar Kühl · 2014-12 · Stack Overflow · on “Why is operator""s hidden in a namespace?”

There are actually two reasons why literals are put into namespaces: It is considered undesirable that users would use using namespace std; just to get hold of the corresponding literals. Having the literals declared in namespaces specific to these doesn't cause the problem. Depending on the domain it may be desirable to use s as the suffix for something else. There is already another suffix s to mean seconds but they don't really conflict. In the video of STL's CppCon 2014 talk [this video] (posted by remyable in a comment) Stephan T. Lavavej explains the overall design of the literals in C++14 and its pretty clear that they are not supposed to be in the global namespace! Instead, the literal su

Recommends user3920237 · 2015-02 · Stack Overflow · on “Is there a reason to place operator ""s into std::literals::string_literals?”

Better yet, just watch CppCon 2014: Stephan Lavavej "STL Features And Implementation Techniques" [this video] , he briefly talks about UDL's in inline namespaces.

Recommends R2-Dequeue · 2015-07 · Stack Overflow · on “Parsing allocator::rebind calls”

@helloB Glad you asked! I do: CppCon 2014: Stephan Lavavej "STL Features And Implementation Techniques" [this video] CppCon2014: Alisdair Meredith "Making Allocators Work, Part I" [LINK] CppCon 2014: Alisdair Meredith "Making Allocators Work, Part II" [LINK] You can get a recent draft standard of C++14 here [LINK] and start with section 17.6.3.5 Allocator requirements [allocator.requirements].

Recommends Arnaud · 2016-04 · Stack Overflow · on “Is Stephen Lavavej's Mallocator the same in C++11?”

STL himself has an answer to this question in his STL Features and Implementation techniques [this video] talk at CppCon 2014 (Starting at 26'30). The slides [LINK] are on github. I merged the content of slides 28 and 29 below: #include <stdlib.h> // size_t, malloc, free #include <new> // bad_alloc, bad_array_new_length template <class T> struct Mallocator { typedef T value_type; Mallocator() noexcept { } // default ctor not required template <class U> Mallocator(const Mallocator<U>&) noexcept { } template <class U> bool operator==( const Mallocator<U>&) const noexcept { return true; } template <class U> bool operator!=( const Mallocator<U>&) const noexcept { return false; } T * allocate(const si

Recommends Tas · 2016-07 · Stack Overflow · on “const auto && really not useful?”

FYI, you can right-click YouTube videos at the desired time and choose "Copy video URL at current time" which gives you a link direct to that time: [this video]

Recommends Qaz · 2020-05 · Stack Overflow · on “Operator bool() conflicting with template Type() operator when Type = bool”

If you'd like a clear explanation of the `typename U = T` necessity, STL gives one in his old talk [this video] . It goes on for a fair few minutes, with the link timestamp being where the context starts.

Recommends kcsquared · 2021-09 · Stack Overflow · on “If the sizes of the two ranges to the algorithm std::mismatch different yields Undefined Behavior?”

Yes, the ranges are assumed to be identical for the old overloads. From the MSVC documentation [LINK] : Use the dual-range overloads in C++14 code because the overloads that only take a single iterator for the second range will not detect differences if the second range is longer than the first range, and will result in undefined behavior if the second range is shorter than the first range The performance penalty for using the dual-range algorithms is minimal (one extra comparison per loop), and, with random-access iterators, the dual-range std::equals and std::is_permutation are required to return False in constant time if the lengths are different. If you're interested, there's a talk by M

Cites Quuxplusone · 2014-12 · Stack Overflow · on “Reasoning about boost mpl placeholders”

Indeed, you're thinking about placeholders the wrong way. mpl::minus is a template in MPL's metalanguage that symbolically represents (or corresponds to ) a certain high-level behavior, namely, subtraction. You're thinking of it as if it's a non-meta construct such as a function int minus(int a, int b) { return a - b; } but it's not. (The standard C++11 library does have something kind of like that, called std::minus<> [LINK] , but that's not what mpl::minus does!) mpl::minus represents the subtraction operation at a higher level of abstraction . Don't worry for another couple of paragraphs about how mpl::minus is implemented. Just think about what it represents , which is subtraction of two

Cites Qaz · 2015-03 · Stack Overflow · on “C++ template sfinae error”

SFINAE (the S is "substitution", not "specialization", by the way) for member functions does not work this way with class type parameters. A simple way to get around that is to use another template parameter: template< typename TCopy = T typename boost::enable_if< boost::is_same<myStruct, TCopy>, int >::type = 0 > void print() { std::cout << "this is my struct" << std::endl; } I pulled this from STL's CppCon talk [this video] . TL;DW: when using the class's T type parameter, the compiler knows what that type is when instantiating the class template and would check for the type member at that point in time. With the extra TCopy type parameter being local to the function, the compiler cannot know f