GithubHelp home page GithubHelp logo

apolukhin / boost-cookbook Goto Github PK

View Code? Open in Web Editor NEW
398.0 398.0 107.0 4.6 MB

Online examples from "Boost C++ Application Development Cookbook":

Home Page: http://apolukhin.github.io/Boost-Cookbook/

License: Boost Software License 1.0

QMake 7.22% C++ 83.08% Python 9.70%
book boost c-plus-plus cpp cpp11 cpp14 cpp17 online-compiler online-learning recipes teaching tutorial tutorials

boost-cookbook's People

Contributors

apolukhin avatar bingozhu0197 avatar mloskot avatar ohmyarch 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

boost-cookbook's Issues

start up on Raspberry pi [SOLVED]

hi !
thanks for the Book. but it took me a time to just start up with even "Hello world" example )
i work on Raspberry pi Raspbian bullseyes.
so for those whos suffring as i was i wrote short intro how to start with boost on raspberry pi:

sudo apt install libboost-all-dev

nano main.cpp

#include <boost/program_options.hpp>
#include <iostream>

namespace opt = boost::program_options;

int main(int argc, char *argv[])
{
    // Constructing an options describing variable and giving it a
    // textual description "All options".
    opt::options_description desc("All options");

    // When we are adding options, first parameter is a name
    // to be used in command line. Second parameter is a type
    // of that option, wrapped in value<> class. Third parameter
    // must be a short description of that option.
    desc.add_options()
        ("apples", opt::value<int>(), "how many apples do you have")
        ("oranges", opt::value<int>(), "how many oranges do you have")
        ("help", "produce help message")
    ;

    // Variable to store our command line arguments.
    opt::variables_map vm;

    // Parsing and storing arguments.
    opt::store(opt::parse_command_line(argc, argv, desc), vm);

    // Must be called after all the parsing and storing.
    opt::notify(vm);

    if (vm.count("help")) {
        std::cout << desc << "\n";
        return 1;
    }

    std::cout << "Fruits count: "
        << vm["apples"].as<int>() + vm["oranges"].as<int>()
        << std::endl;

} // end of `main`

nano CMakeLists.txt

cmake_minimum_required(VERSION 3.3)
project(BoostTest)

FIND_PACKAGE(Boost COMPONENTS program_options REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
#set(CMAKE_CXX_FLAGS "-lboost_program_options")

set(SOURCE_FILES main.cpp)
add_executable(BoostTest ${SOURCE_FILES})
target_link_libraries(BoostTest ${Boost_LIBRARIES} -lpthread)
target_link_libraries(BoostTest ${Boost_LIBRARIES} -lboost_program_options)
cmake . 
make

./BoostTest --apples 20 --oranges 30
Screenshot_1

Chapter05/02_mutex/main.cpp

i have trouble with compilation on raspberry pi but finally got in working.
heres the code:

#include <boost/thread/mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread.hpp>
#include <iostream>

namespace with_sync {

int shared_i = 0;
boost::mutex i_mutex;

void do_inc() {
    for (std::size_t i = 0; i < 30000; ++i) {
        int i_snapshot;
        {   // Critical section begin.
            boost::lock_guard<boost::mutex> lock(i_mutex);
            i_snapshot = ++shared_i;
        }   // Critical section end.
        std::cout<<i_snapshot<<std::endl;
        // Do some work with i_snapshot.
        // ...
        (void)i_snapshot;
    }
}

void do_dec() {
    for (std::size_t i = 0; i < 30000; ++i) {
        int i_snapshot;
        {   // Critical section begin.
            boost::lock_guard<boost::mutex> lock(i_mutex);
            i_snapshot = -- shared_i;
        }   // Critical section end.
            std::cout<<i_snapshot<<std::endl;
        // Do some work with i_snapshot.
        // ...
        (void) i_snapshot;
    }
}

int run() {
    boost::thread t1(&do_inc);
    boost::thread t2(&do_dec);

    t1.join();
    t2.join();

    assert(shared_i == 0);
    std::cout << "shared_i == " << shared_i;
}

} // namespace without_sync
int main() {
with_sync::run();
return 0; };

i have to add to CMakeLists.txt:

target_link_libraries(BoostTest ${Boost_LIBRARIES} -lpthread)
target_link_libraries(BoostTest ${Boost_LIBRARIES} -lboost_thread)

do these things double each other ?
but without any of them get a error.

Spirit examples using `auto`

Looks like there's an issue with replacing SPIRIT rules with auto. Make a minimized example and report the issue (or fix the examples, if there's no issue). Add CI tests.

unknown type name _lock_policy - Ubuntu 18.04

to include file /usr/include/c++/7/backward/auto_ptr.h
similar change is also required if g++-8 is used eg. /usr/include/c++/8/backward/auto_ptr.h

added line 35
#include <tr1/memory>

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.