From 9271517e0de0e65eeedb425bd5f18d0a21aefaec Mon Sep 17 00:00:00 2001 From: Michael Spector Date: Tue, 3 May 2016 11:00:23 +0300 Subject: [PATCH] Format sample usage --- README.md | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 9f0c2b6..e7d7119 100644 --- a/README.md +++ b/README.md @@ -23,37 +23,35 @@ Features: - two variants, one depends on Boost Lockfree Queue library, http://boost.org, which is a header only library -Sample usage +Sample usage: -void first(int id) { +```cpp +void first(int id) { std::cout << "hello from " << id << '\n'; -} +} - struct Second { +struct Second { void operator()(int id) const { std::cout << "hello from " << id << '\n'; } } second; -void third(int id, const std::string & additional_param) {} +void third(int id, const std::string & additional_param) {} +int main () { + ctpl::thread_pool p(2 /* two threads in the pool */); + p.push(first); // function -int main () { + p.push(third, "additional_param"); - ctpl::thread_pool p(2 /* two threads in the pool */); - - p.push(first); // function - - p.push(third, "additional_param"); - - p.push( [] (int id){ - std::cout << "hello from " << id << '\n'; -}); // lambda - - p.push(std::ref(second)); // functor, reference - - p.push(const_cast<const Second &>(second)); // functor, copy ctor - - p.push(std::move(second)); // functor, move ctor - -} + p.push([] (int id) { + std::cout << "hello from " << id << '\n'; + }); // lambda + + p.push(std::ref(second)); // functor, reference + + p.push(const_cast(second)); // functor, copy ctor + + p.push(std::move(second)); // functor, move ctor +} +```