In this course, you’ll learn with a combination of slides and demo code, how to use associative containers like std::set, std::map, and std::unordered_map.
This is a follow up course of my previous course, which I encourage you to watch before this one.
Starting from this course page, you can freely play the course overview, and read a more detailed course description and the table of content.
These are some feedback notes frommy reviewers:
Nice use of the PowerPoint slides and Camtasia callouts to keep the learners focused and engaged. [Peer Review]
Enjoyable clip of std::map string to string dictionary translation. [Peer Review]
Overall, a strong module that’s well-explained, approachable and professionally polished. Looking forward to more! [Peer Review]
The content is logically sequenced, building on concepts as we go. The clips are nice and short, which makes it easy to move through and absorb the content. You also do a great job transitioning across the clips; there’s a cohesive flow to the module. [Peer Review]
I’m glad you showed this error, explained why it’s happening, and how to fix it. It’s a good opportunity to reiterate learnings from earlier in the module, and also seems like a common gotcha. [Peer Review]
In this course, you’ll learn how to use some important containers implemented in the C++ Standard Library, with a combination of theoretical introduction using slides, and practical C++ implementation code, including analyzing and fixing some common bugs.
C++ Standard Library implementations offer high-quality well-tested and highly-optimized standard containers, that are very powerful tools when developing software written in C++.
In particular, I’ll discuss std::vector (which is a Standard Library workhorse), std::array, and std::list, including how to use them, discussing their pros and cons, and giving some guidance on picking one or the other, based on the problem at hand. Other containers (e.g. std::map) will be the topic of follow-up courses.
No prior knowledge of C++ Standard Library containers is required. You only need a basic knowledge of C++ language features.
Containers and algorithms are kind of like “bread and butter”, so in this course you’ll also learn about the C++ Standard Library design based on the teamwork between containers, iterators and algorithms, and you’ll see how to perform important operations on containers leveraging some useful algorithms already implemented in the C++ Standard Library.
Note that this course is boththeory and practice! In fact, I’ll show practical demo code, and I’ll also discuss some bugs that are especially common for those who are just starting to learn the C++ Standard Library’s containers.
These are some feedback notes from my reviewers:
The narration is clear, animated, and engaging. The visuals are particularly helpful. [Peer Review]
You do a particularly good job clearly stating the problem here (and elsewhere) so that the solution, when it comes, makes sense and fits nicely. [Peer Review]
Great simple example of undefined behavior to reinforce the concepts you’ve introduced as well as a bonus of uncovering a security issue. [Peer Review]
Very nice module with good examples. Also excellent visuals when describing list, vectors and the various operations. [Peer Review]
Very nice discussion of the trade-offs between a linked list and a vector [Peer Review]
Nice use of a bug to teach a key concept [Peer Review]
Starting from this course page, you can freely play the course overview, and read a more detailed course description and the table of content.
Let me also express my gratitude to all the Pluralsight persons involved in the production of this course: It’s always a pleasure to work with you all!
In this course, you’ll learn how to implement some fundamental data structures and algorithms in C++ from scratch, with a combination of theoretical introduction using slides, and practical C++ implementation code.
No prior data structure or algorithm theory knowledge is required. You only need a basic knowledge of C++ language features (please watch the “Prerequisites” clip in the first module for more details about that).
During this course journey, you’ll also learn some practical C++ coding techniques (ranging from move semantic optimization, to proper safe array copying techniques, insertion operator overloading, etc.) that you’ll be able to use in your own C++ projects, as well.
So, this course is boththeory and practice!
Here’s just a couple of feedback notes from my reviewers:
The callouts are helpful and keep the demo engaging as you explain the code. [Peer Review]
To say that this is an excellent explanation of Big-O notation would be an understatement. The way you illustrate and explain it is far better than the way it was taught to me in college! [Peer Review]
Starting from this course page, you can freely play the course overview, and read a more detailed course description and table of content.
Last time, I enumerated a few types of strings available in C++.
These days, I’d suggest as the default option for cross-platform standard C++ code to use std::string, storing UTF-8-encoded text inside it. Note that pure ASCII is a proper subset of UTF-8, so storing pure ASCII text in std::string objects is just fine.
In addition, for those platform-specific sections of C++ code, I’d suggest using whatever string class and encoding are typical and “natural” for that platform. For example, at the Windows API boundary, use the UTF-16 encoding, and the std::wstring class in C++ code that doesn’t use ATL or MFC.
In addition, in C++ Windows-specific code that already uses ATL or MFC, another option is to use CString (or the explicit CStringW) enabling Visual Studio Unicode builds (“Configuration Properties” | “General” | “Character Set”: “Use Unicode Character Set”, which has been the default since probably Visual Studio 2005).
On the other hand, Qt-based C++ code can use the QString class, and so on.
And don’t forget L”Connie”, u”Connie” and U”Connie”, which represent const wchar_t*, const char16_t* (UTF-16 encoded) and const char32_t* (UTF-32 encoded) respectively.
Now we are done, right? Not yet!
In fact, you can combine the previous prefixes with the standard s-suffix, for example: L”Connie”s is a std::wstring! U”Connie”s is a std::u32string. And so on.
Done, right? Not yet!! In fact, there are raw string literals to consider, too. For example: R”(C:\Path\To\Connie)”, which is a const char* to “C:\Path\To\Connie” (well, this saves you escaping \ with \\).
And don’t forget the combinations of raw string literals with the above prefixes and optionally the standard s-suffix, as well: LR”(C:\Path\To\Connie)”, UR”(C:\Path\To\Connie)”, LR”(C:\Path\To\Connie)”s, UR”(C:\Path\To\Connie)”s, and more!
Oh, and in addition to the standard std::string class, and other standard std::basic_string-based typedefs (e.g. std::wstring, std::u16string, std::u32string, etc.), there are platform/library specific string classes, like ATL/MFC’s CString, CStringA and CStringW. And Qt brings QString to the table. And wxWidgets does the same with its wxString.
Wow! And I would not be surprised if I missed some other string variation out 😊
P.S. With all this string variety (maybe too much…), what about adding to the C++ Standard Library some convenient functions for at least common string operations like trimming spaces and converting strings to upper case and lower case? All in all, C++ does already have rocket-science stuff like Bessel functions in its Standard Library. While, back in the old MFC days, CString already offered convenient methods like Trim, MakeLower and MakeUpper, just to name a few.
If you want to learn modern C++ from scratch, in a fun and interesting way, with engaging slides and demo code, please check out my course!
We are in 2018, and there have been C++14 and C++17 in the meantime. So, a legit question is: “Does it make sense for me to watch your C++11 course today for a beginner-oriented introduction to C++?” And the answer is a BIG STRONG YES! 😊
In fact, in that course you will learn modern C++ topics that are valid in both C++11, and also in next versions of the language. For example, what you will learn about the parameter passing rules, like passing by reference vs. passing by value, is perfectly valid in C++11, C++14, and C++17 as well.
Moreover, the practical introductions I gave to standard library’s classes like std::string, or std::vector, and to the std::sort algorithm, just to name a few, are totally valid also in C++14 and C++17.
Similarly, my discussions on defining custom types, constructors, destructor, the RAII pattern and the scope-based lifetime of objects are still valid in C++14 and C++17, as well.
Maybe a better title for that course would be “Modern C++ from Scratch”. Anyway, the content is already there, available for an enjoyable learning experience, with a mix of slides containing interesting visuals, and demo code.
C++14 and C++17 added many new features to the C++ language. This course will teach you practical features introduced in C++14 and C++17, that you will be able to use to write clearer, simpler, and higher-quality modern C++ code.
You can take this course to learn about practical features added in C++14 and C++17, ranging from syntactic sugar like digit separators, to more substantial features like polymorphic lambdas (this course will offer an introduction to basic lambdas as well), relaxed constexpr functions, the Chrono library with its standard-defined duration suffixes, and C++17 juice ranging from nested namespaces, variable declarations in if statements, to “constexpr if” and structured bindings, just to name a few.
I discussed these topics with both slides and demo code, including showing some bugs and how to fix them.
You can watch the course trailer and read a more detailed course description and the table of content starting from this course page.
I put the discussed features in proper context for learners who are already familiar with basic elements of C++11. For example, when I introduced C++14 std::make_unique, I also talked about smart pointers and introduced std::unique_ptr as well. If you need an introduction to basic elements of modern C++, you can take my “C++11 from Scratch” course.
Here’s some feedback from my reviewers:
You’ve done an excellent job with the animated shapes/callouts throughout the module. They really help me to follow along with the narrative explanations. [Peer Review]
The content is logically organized and chunked into bite-size clips. I also like your mix of slides and demos. [Peer Review]
This is an excellent challenge to the viewer to spot the bug in the code. [Peer Review]
Overall, a strong module that will be well-received by an intermediate audience. The explanations are clear and the concepts build on each other, making it easy to follow along. Keep up the great work! [Peer Review]
Writing and producing this course has been an interesting journey and a rewarding experience for me. There are several people who worked with me during this journey and with their contributions helped me producing this quality course. I’d like to thank my ASM (former Editor) Beth Gerard-Hess, my Production Editor Austin Crawford, my Curriculum Director Tod Gentille, my reviewers (both QA and peer), and all the Pluralsight persons who worked on this course project. Thanks also to Stephan T. Lavavej for interesting e-mail conversations that provided good food for thought.
Suppose that you want to convert a std::string object to lowercase.
The first thing you would do is probably searching the std::string documentation for a convenient easy simple method named to_lower, or something like that. Unfortunately, there’s nothing like that.
So, you might start developing your own “to_lower” function. A typical implementation I’ve seen of such custom function goes something like this: For each character in the input string, convert it to lowercase invoking std::tolower. In fact, there’s even this sample code on cppreference.com:
Well, if you try this code with something like str_tolower(“Connie”), everything seems to work fine, and you get “connie” as expected.
Now, since C++ folks like storing UTF-8-encoded text in std::string objects, in some large code base someone happily takes the aforementioned str_tolower function, and invokes it with their lovely UTF-8 strings. Fun ensured! …Well, actually, bugs ensured.
So, the problem is that str_tolower, under the hood, calls std::tolower on each char in the input string. While this works fine for pure ASCII strings like “Connie”, such code is a bug farm for UTF-8 strings. In fact, UTF-8 is a variable-width character encoding. So, there are some Unicode “characters” (code points) that are encoded in UTF-8 using one byte, while other characters are encoded using two bytes, and so on, up to four bytes. The poor std::tolower has no clue of such UTF-8 encoding features, so it innocently spits out wrong results, char by char.
For example, I tried invoking the above function on “PERCHÉ” (the last character is the Unicode U+00C9 LATIN CAPITAL LETTER E WITH ACUTE, encoded in UTF-8 as the two-byte sequence 0xC3 0x89), and the result I got was “perchÉ” instead of the expected “perché” (é is Unicode U+00E9, LATIN SMALL LETTER E WITH ACUTE). So, the pure ASCII characters in the input string were all correctly converted to lowercase, but the final non-ASCII character wasn’t.
Actually, it’s not the std::tolower function: It’s that this function was misused, invoking it in a way that the function was not designed for.
This is one of the perils of taking std::string-based C++ code that initially worked with ASCII strings, and thoughtlessly reuse it for UTF-8-encoded text.
So, how can you fix that problem? Well, a portable way is using the ICU library with its icu::UnicodeString class and its toLower method.
On the other hand, if you are writing Windows-specific C++ code, you can use the LcMapStringEx API. Note that this function uses the UTF-16 encoding (as almost all Windows Unicode APIs do). So, if you have UTF-8-encoded text stored in std::string objects, you first have to convert it from UTF-8 to UTF-16, then invoke the aforementioned API, and finally convert the UTF-16-encoded result back to UTF-8. For these UTF-8/UTF-16 conversions, you may find my MSDN Magazine article on “Unicode Encoding Conversions with STL Strings and Win32 APIs” interesting.