This repo is inspired by many of the concise examples of idiomatic modern C++ that appear in the book A Tour of C++ by Bjarne Stroustrup. I initially started the repo to expand and experiment with the specific examples from the book, but I have since added a lot of new examples of modern C++ features that are not from the book.
@book{stroustrup2018tour,
title={A Tour of C++},
author={Stroustrup, Bjarne},
year={2018},
publisher={Addison-Wesley Professional}
}
Find more information about the book at the link below:
https://www.stroustrup.com/Tour.html
- 01-the-basics
- 02-user-defined-types
- 03-modularity
- 04-classes
- 05-essential-operations
- 06-templates
- 07-concepts-and-generic-programming
- 08-library-overview
- 09-strings-and-regular-expressions
- 10-input-and-output
- 11-containers
- 12-algorithms
- 13-utilities
- 14-numerics
- 15-concurrency
- forloop.cc
- Demonstrate different forms of for-range syntax for array/vector containers.
- helloworld.cc
- Hello World in modern c++.
- if.cc
- Go-style variable declaration as part of
if
.
- Go-style variable declaration as part of
- init.cc
- Various forms of literal initialization.
- literal.cc
- Literal intiailization that emphasizes readability.
- nullptr.cc
- Demonstrate use of
nullptr
as replacement forNULL
macro.
- Demonstrate use of
- pointer.cc
- Demonstrate basic pointer operations and equivalencies.
- printer.cc
- Template for printing containers.
- ref.cc
- Demonstrate basic reference operations and distinction from pointers.
- square.cc
- Demonstrate
constexpr
for pure functions aka functions without side-effects.
- Demonstrate
- enum.cc
- Demonstrate
enum class
and use of operator overloading with enum.
- Demonstrate
- read_and_sum.cc
- Read n integers from istream, c-style alloc/free functions.
- variant.cc
- Demonstrate std::variant as an improvment of
union
.
- Demonstrate std::variant as an improvment of
- vector1.cc
- Repeat of
read_and_sum.cc
, but using cpp constructor/destructor.
- Repeat of
- base.cc
- Return a number as string in arbitrary base.
- binding.cc
- Demonstrate use of unpacking for multi-value return type.
- rangemap.cc
- Demonstrate use of unpacking and for-range syntax for map containers.
- throwcatch.cc
- Demonstrate cpp convention of throw-by-value and catch by (const) reference.
- shapes.cc
- Polymorphic hierarchy with pure virtual base class, container of unique_ptr to base class.
- vector2.cc
- Demonstrate use of std::initializer_list constructor.
- mat3x3.cc
- Demonstrate copy/move constructor and assignment for POD-type class.
- vector3.cc
- Demonstrate copy/move constructor and assignment for resource handle class.
- uliteral.cc
- Demonstrate creating user-defined literals.
- accumulate.cc
- Implement function template equivalent to std::accumulate.
- count_if.cc
- Implement function template equivalent to std::count_if with UnaryPredicate.
- for_each.cc
- Implement function template equivalent to std::for_each with UnaryFunction.
- recursive_lambdas.cc
- Demonstrate methods for creating recursive lambda functions.
- tuple_apply.cc
- Apply a function to every member of tuple using fold expression.
- printf.cc
- Implement typesafe version of printf using variadic templates.
- stringops.cc
- Demonstrate operations in std::string.
- catstringview.cc
- Demonstrate operations in std::string_view.
- regexops.cc
- Demonstrate operations in std::regex.
- csvparsers.cc
- All the different ways to parse a csv.
- anytoany.cc
- Demonstrate use of std::stringstream for any-to-any conversion.
- readfile.cc
- Read a file line-by-line raising std::runtime_error if error.
- customhash.cc
- Demonstrate use of custom hash functions with containers.
- erase_remove.cc
- Demonstrate the erase-remove idiom to remove elements from containers.
- hash_combine.cc
- Demonstrate combining hash functions.
- inserter.cc
- Demonstrate use of std::inserter for adding elements to container.
- mapinsert.cc
- Demonstrate different ways to insert into a unordered_map.
- priority_queue.cc
- Demonstrate std::priority_queue using lambda functions for ordering.
- rangecheckvec.cc
- Demonstrate using composition to obtain range-checked std::vector.
- vecemplace.cc
- Demonstrate use of template forwarding for emplace into container.
- vecsizecap.cc
- Demonstrate size and capacity of std::vector with reserve, resize, clear, and shrink_to_fit.
- all_any_none_of.cc
- all_any_none_of demonstrates logical algorithms using bind.
- findall.cc
- Implement template function findall that demonstrates use of type alias.
- first_less_than.cc
- first_less_than complements lower_bound and upper_bound.
- heap_ops.cc
- Demonstrate heap functions in std::algorithms.
- parallelsort.cc
- Demonstrate std::execution policies for parallel and/or vectorized sorting.
- partial_sum.cc
- partial_sum implements cumsum and factorial.
- set_ops.cc
- set_ops demonstrates union, intersection, and (symmetric)difference.
- unique.cc
- Implement function template equivalent to std::unique for removing adjacent duplicate values.
- wordcount.cc
- Emit word frequency count based on input read from stdin.
- bitsetops.cc
- Demonstrate operations in std::bitset.
- iterator_traits.cc
- Implement traits-based function overload with type aliases.
- optional.cc
- Demonstrate use of std::optional.
- pairtuple.cc
- Demonstrate use of std::pair and std::tuple.
- smartptr.cc
- Demonstrate use of std::unique_ptr and std::shared_ptr.
- span.cc
- Span is a (pointer,count) pair with support for range-based for loop.
- swap.cc
- Demonstrate exception safe swap implemented using std::move.
- timeit.cc
- Demonstrate use of std::chrono for microbenchmarking.
- rng_iterator.cc
- An iterator that returns an infinite sequence of random integers.
- random.cc
- Demonstrate use of pseudorandom number generators in std::random.
- counter.cc
- Demonstrate use of mutex for sharing counter across threads.
- deadlock.cc
- Demonstrate use of scoped_lock with pairs of locks to avoid deadlock.
- events.cc
- Demonstrate use of std::condition_variable for communicating events to listeners.
- starvation.cc
- Demonstrate thread starvation between greedy and polite worker threads.
- thread.cc
- Demonstrate initializing std::thread with function and functor.