Difference between revisions of "Intermediate C++ Game Programming Tutorial 16"

From Chilipedia
Jump to: navigation, search
(Video Timestamp Index)
(Video Timestamp Index)
Line 16: Line 16:
 
* Sorting a (forward) list <code>std::list</code>, using its member function <code>std::list::sort()</code> [https://youtu.be/3J1Pz30IE4Q?t=2m16s 2:16]
 
* Sorting a (forward) list <code>std::list</code>, using its member function <code>std::list::sort()</code> [https://youtu.be/3J1Pz30IE4Q?t=2m16s 2:16]
 
* Introducing Concepts / named requirements of types (e.g., the <code>Compare</code> requirement of <code>std::sort</code> [https://youtu.be/3J1Pz30IE4Q?t=2m54s 2:54]
 
* Introducing Concepts / named requirements of types (e.g., the <code>Compare</code> requirement of <code>std::sort</code> [https://youtu.be/3J1Pz30IE4Q?t=2m54s 2:54]
* Modyfing sorting order by passing a comparison function object (functor), like so (vec is a vector of ints):<br /><code>std::sort(vec.begin(),vec.end(),std::greater<int>{});</code> [https://youtu.be/3J1Pz30IE4Q?t=3m17s 3:17]
+
* Modyfing sorting order by passing a comparison function object (functor) as a predicate, like so (vec is a vector of ints):<br /><code>std::sort(vec.begin(),vec.end(),std::greater<int>{});</code> [https://youtu.be/3J1Pz30IE4Q?t=3m17s 3:17]
 
* Sort custom types, example code for sorting a custom class object [https://youtu.be/3J1Pz30IE4Q?t=4m07s 4:07]
 
* Sort custom types, example code for sorting a custom class object [https://youtu.be/3J1Pz30IE4Q?t=4m07s 4:07]
 
* [WORK-IN-PROGRESS]
 
* [WORK-IN-PROGRESS]

Revision as of 21:53, 28 September 2019

In the video we take a look at a couple of bangers from <algorithm>, and we learn what lambda functions are and how to use them.

Topics Covered

  • Algorithms std::sort and std::remove_if
  • Concepts (as in, type concepts like Comparable)
  • <functional> functors as predicates
  • Lambda functions

Errata

In the video Chili states that std::remove does not preserve the relative order of elements in the container, but this is fake news! Relative order is preserved: [1]

Video Timestamp Index

Tutorial 16

  • Generic Algorithms: how Templates and Iterators make Algorithms independent of Data Types and Containers 0:17
  • The std::sort algorithm and its requirements 0:43
  • Sorting a (forward) list std::list, using its member function std::list::sort() 2:16
  • Introducing Concepts / named requirements of types (e.g., the Compare requirement of std::sort 2:54
  • Modyfing sorting order by passing a comparison function object (functor) as a predicate, like so (vec is a vector of ints):
    std::sort(vec.begin(),vec.end(),std::greater<int>{}); 3:17
  • Sort custom types, example code for sorting a custom class object 4:07
  • [WORK-IN-PROGRESS]

Homework

Solve the problems in Source.cpp attached below using the <algorithm> library and other parts of the standard library as extensively as possible. As a bonus problem, implement the sprite drawing effect shown at the end of the video using a lambda function.

Related Series

For an in-depth look into the <algorithm> library and beyond, check out STD Gems.

Links

Algorithms Library

See also