Description

Welcome to another installment of C9 Lectures covering the powerful general C++ library, STL. Joining us once again is the great Stephan T. Lavavej, Microsoft's keeper of the STL cloth (this means he manages the partnership between the owners of STL (dinkumware) and Microsoft, including, of course, bug fixes and enhancements to the STL that ships as part of Visual C++). Simply, Stephan is a C++ library developer.

As is Stephan's nature, he elaborates on technical details in very substantive way. The Standard Template Library, orSTL, is a C++ library of container classes, algorithms, and iterators. STL provides many fundamental algorithms and data structures. Furthermore, the STL is a general-purpose library: its components are heavily parameterized, such that almost every component in the STL is a template.

As for your second implementation, lower_bound() and upper_bound() require sorted sequences, while minmax_element() accepts arbitrary sequences. Finding the minimum and maximum of a sorted sequence can be done in O(1) time. :->

There's always more to tell. I'm getting close to exhausting the simple topics, so it's probably time to begin introducing C++0x features. Lambdas (which I've shown a little), perfect forwarding, and perfect returning are all relevant to functors.

I've been spraining my brain recently with how to implement Shear-sort, its absolutely cool,entertaining and fast. Shell & Radix soort used to be my favs, but now its shearsort. Have a look at it, you also may find it fairly entertaining.

[Mr Crash]> when to use lambdas and when to use bind, bind2nd, mem_fn.> i've read that lambdas can replace these functions but when should you use functions like bind, bind2nd,mem_fn. instead of lambdas ?

But lambdas supersede all of them. Lambdas are easier to read, easier to write, and more efficient. In the few cases where lambdas aren't sufficient, you should use handwritten functors. (One case is a map's comparator, where you want an easily named and default-constructible type. Other cases include templated or recursive functors.)

[HeavensRevenge]> Shell & Radix soort used to be my favs, but now its shearsort.

My favorite special-purpose sort uses a suffix tree to sort the suffixes of a string. A string of length N has N suffixes ("meow" has the suffixes "meow", "eow", "ow", and "w"; one convention is to count the whole string, but not the empty string, as a suffix). Using a general-purpose sort takes O(N^2 log(N^2)) = O(2 * N^2 log(N)) = O(N^2 log(N)), which is slower than quadratic. (It would perform N log N comparisons, but each comparison takes O(N) time in the worst case; consider the string "aaaaaaaab".) Suffix trees take O(N) time. That's not a typo, it really is linear time.

I made it be around screen width(each 600 wide), both sorts using 1000 entries to sort, Comparing side-by-side my new fav Shearsort with the also impressive IntroSort. The bigger N, the better Shearsort can do, since its complexity stays way down, and is excellently-parallel n-way per "shear".

Unfortunately, that's a complicated topic, I'm not an expert there (I know stuff, but I like to teach things only when I'm an expert), and iostreams/locales aren't part of the STL proper (string is a borderline case). So I don't think I'll be covering Unicode in this series.

[HeavensRevenge]> For general purpose, I believe the complexity of shearsort is something like O(n^1/2 (log n))

The best that a serial general-purpose sort can do is O(N log N). That's a theorem that CS students prove in Algorithms 101. std::sort() is now required by C++0x to be worst-case O(N log N). In C++98/03, it was permitted to be average O(N log N), worst-case O(N^2), i.e. the behavior of a plain quicksort.

The STL currently doesn't contain parallel algorithms. I've asked for parallel_sort() from the Concurrency Runtime team, but haven't gotten it yet. :->

Recursive lambdas don't actually look so bad:std::function<int(int)> factorial = [&factorial](int n) -> int { return n <= 1 ? 1 : n * factorial(n-1);};std::cout << factorial(4);They do not work with "auto" however... And you couldn't just slap this inside an algorithm as you need to define a variable, and if you're doing that anyway you may as well just be making a named functor for it.Source: http://cottonvibes.blogspot.com/2010/07/c0x-autos-lambdas-and-lambda-recursion.html

If you watch carefully, near the end of the video, I accidentally brushed the TV's capacitive buttons with my arm, switching its input from my laptop (which has a background of the Carina Nebula) to one of the studio's computers (which has the background that you saw). I didn't even notice that this had happened until after I had finished recording the video, as my right eye is blind.

@STL: > Is there anything else that people want to see?How about making a simple yet extensible calculator using STLi think a lot the STL will come in handy.What do you think about that suggestion ?Keep the videos coming, please :)