Giter Site home page Giter Site logo

cpp17-stl-cookbook's Introduction

C++17 STL Cookbook

This is the code repository for C++17 STL Cookbook, published by Packt. It contains all the supporting project files necessary to work through the book from start to finish.

About the Book

The C++17 STL Cookbook will teach you how to get the most out of C++17 by providing coding recipes that combine the C++ language and its standard library, the STL. Indeed, this book uses as much STL as possible, which is worth a bit of explanation.

C++ is such a great and powerful language. It allows us to hide complex solutions behind simple high-level interfaces but, at the same time, to write low-level code where high performance and low overhead really matter. The ISO C++ Standard Committee works hard on improving the C++ standard. C++11 brought a lot of great features to C++, and so did C++14 and C++17.

As of today, C++ is a language that provides language features and standard library facilities for sophisticated standard data structures and algorithms, automatic resource management pointers, lambda expressions, constant expressions, portable thread control for concurrent programming, regular expressions, random number generators, exceptions, variadic templates (the part of C++ for expressing template types is even Turing-complete!), user-defined literals, portable filesystem traversal, and so much more. This giant bunch of features makes it a general-purpose language ideal for implementing high-quality and high-performance software in all fields of the software industry.

However, many C++ programmers eagerly learn C++ as a language but put its standard library, the STL, in the second place. Using the C++ language without the help that the standard library provides often leads to programs that look like C with classes, but not what modern programs in the 21st century should look like. This is very sad because using C++ like that means dropping half its strength.

In the C++11 edition of his book, The C++ Programming Language, Bjarne Stroustrup writes, "Please remember that those libraries and language features exist to support programming techniques for developing quality software. They are meant to be used in combination--as bricks in a building set--rather than to be used individually in relative isolation to solve a specific problem."

This is exactly what this book and its recipes are about. All the recipes in this book are designed to be as near as possible to real-life problems, while at the same time, they do not rely on any external libraries other than the STL. This way, it is very simple to play around with each of them, without having to do confusing setup work. I really hope that you find inspiration in the recipes and, maybe, find some of them to be nice standard building blocks for solving higher-level problems with this great programming language.

Instructions and Navigation

All of the code is organized into folders. Each folder starts with a number followed by the application name. For example, Chapter02.

The code will look like the following:

my_wrapper<T1, T2, T3> make_wrapper(T1 t1, T2 t2, T3 t3)
{
    return {t1, t2, t3};
}

All recipes in this book are kept as simple and self-contained as possible. They are easy to compile and run, but depending on the reader’s choice of operating system and compiler, there are differences.

Related Products

Suggestions and Feedback

Click here if you have any feedback or suggestions.

cpp17-stl-cookbook's People

Contributors

hussaink72 avatar mykolalebid avatar packt-itservice avatar sv1990 avatar tfc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpp17-stl-cookbook's Issues

Sequential execution in multi_producer_consumer.cpp

There is a problem in multi_producer_consumer.cpp code.
Mutexes are locked even when thread is paused by sleep_for(..ms). As result, all threads wait while any other thread is paused on sleep_for(..ms). sleep_for should be moved out of unique_lock scope.

Error during cartesian_product compilation by mingw 7.3.0 x64

I try to compile that code [https://github.com/PacktPublishing/Cpp17-STL-Cookbook/blob/master/Chapter04/cartesian_product.cpp] by mingw 7.3.0 x64, but I get an error:

no matching function for call to 
'std::initializer_list<int>::initializer_list(<brace-enclosed initializer list>)' 
(void)std::initializer_list<int>{
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
((void)call_cart(f, xs, xs...), 0)...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     };

I noticed that I can fix the problem, if I change "xs..." to "1,2,3", for example

std::initializer_list

Can you say why you didn't used std::list instead of std::initializer_list in personal_organiser_priority_queue.cpp ?

false behaviour of shared_lock

I am running shared_lock.cpp file but unexpectedly print_exclusive() acquires lock never ever it print "Unable to lock exclusively".

My config is :
g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

g++ --std=c++1z -g3 -O0 -c /home/med/100daysOfCodingChallenge/c++17_parallelism/4_SharedLock/main.cpp -o ./build/Debug/main.o && g++ --std=c++1z -g3 -O0 ./build/Debug/main.o -o ./build/Debug/outDebug

Segfault on Chapter2 -> Recipe12

On Implement a writing style helper tool for finding very long sentences in text with std::multimap the implementation "segfaults" if the input ends in something else than "." On most systems the input will end in "\n" or "\r\n".

The issue can be fixed if the update to "it2" checks for failure before continuing the loop:

    it1 = next(it2, 1);
    if ((it2 = find(it1, end_it, '.')) == end_it) {
      break;
    }

If we don't "break" out of the loop when updating "it2" then the program segfaults.

Chapter09 auto_parallel does not compile

I tested the compilation of the programs in Chapter09 with
clang++-5.0 version 5.0.0 and
g++-7 version 7.1.0

The program, auto_parallel.cpp does not compile with either of the above compilers:

  1. auto_parallel.cpp:5:10: fatal error: 'algorith' file not found
    Then, with it commented out, // #included
  2. auto_parallel.cpp:6:10: fatal error: 'execution' file not found
  3. I had to add LDFLAGS = -lpthread to the Makefile so that the files would would produce execcutables.

If you could post how it was that auto_parallel.cpp compiled it would be appreciated. (What compiler did you use? Were there required environmental variables?)

Can't compile in g++ 8.3

Can't compile files as downloaded with g++8.3 under Debian buster
First: experimental/ not found so I modified file to not look in experimental
And to use only
Please see attached script from build
See attached list.cpp as modified

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.