GithubHelp home page GithubHelp logo

excerise-c-plus-plus-'s Introduction

Note Becom to C++ Developer on LinkedIn

How to install boost for C++ libraies in Ubuntu

Install libboost-all-dev Using apt-get: sudo apt-get update sudo apt-get -y install libboost-all-dev

RAII in C++ programming (Resource Acquisition Is Initialization)

1. Basic Concepts

Very complex memory management problem in C++. If you want to minimize the impact of memory management on the programming process, then RAII is the choice for you.

Performs a binding between an object initialized on the heap and an object stored on the stack. Thereby, when the object on the stack is destroyed, ie exits the scope of the object, the memory on the heap will also be destroyed.

2. Examples

You can see an example example 1 , example 2

3. Learn about Smart Pointer

shared_ptr,unique_ptr ,weak_ptr, boost::scoped_ptr (if you install library Boost)

Learn about smart pointers here and more.

Some topics for C++

Topics 1 : transform, copy_if, acumulate in C++

  • 1. Transform

Applies an operation sequentially to the elements of one (1) or two (2) ranges and stores the result in the range that begins at result. For example:

int main()
{
    auto render = [](auto collection) {
        for(const auto &val: collection) {
            cout << val << endl;
        }
    };

    vector<int> inCollection{1,2,3,4,5,6,7,8,9,10};
    vector<int> outCollection;
    transform(inCollection.begin(), inCollection.end(), 
       back_inserter(outCollection), [](const int &value){ return value * 3;}
    );
    cout << "Transform" << endl;
    render(outCollection);
}

The output: {3,,6,9,12,15,...,30} More examples at this link Examples

2. Copy_if

C++ Algorithm copy_if() function is used to copy the elements of the container [first,last] into a different container starting from result for which the value of pred is true. ***For examples: ***


int main()
{
    vector<int> inCollection{1,2,3,4,5,6,7,8,9,10};
    vector<int> filteredCollection;
    copy_if(outCollection.begin(), outCollection.end(),
        back_inserter(filteredCollection), [](int &value){ return value %2 != 0;});
    cout << "copy_if" << endl;
    render(filteredCollection);
    return 0;
}

The output is the numbers in the original vector that satisfy the filter condition in copy_if. In this case , the output is {1,3,5,7,9} More examples at this link Examples

3. Acumulate

In short, the function is the sum of the elements More examples at this link Examples

Topics 2: Template metaprogramming with C++

Difference between template and template metaprogramming

normal templates run at runtime , template metaprogramming runs at compile time See example with factorial calculation function here

excerise-c-plus-plus-'s People

Contributors

denotevn avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

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.