Presentation is loading. Please wait.

Presentation is loading. Please wait.

Piotr Klecha. C++ Przegląd bibliotek Instalacja Przyszłe wersje C++

Similar presentations


Presentation on theme: "Piotr Klecha. C++ Przegląd bibliotek Instalacja Przyszłe wersje C++"— Presentation transcript:

1 Piotr Klecha

2 C++ Przegląd bibliotek Instalacja Przyszłe wersje C++

3 trudny język nieczytelny kod zarządzanie pamięcią wielowątkowość STL wydajność

4 std::auto_ptr { std::auto_ptr x1(new X(10)); std::cout x << std::endl; std::auto_ptr x2 = x1; //std::cout x << std::endl; func(x2); //std::cout x << std::endl; }

5 typedef boost::shared_ptr XPtr; XPtr x1(new X(5)); //XPtr x1(new X(5), Deleter()); XPtr x2(x1); std::cout << x1.use_count() << std::endl; //2 std::vector v; v.push_back(x1); v.push_back(x2); x2.reset(); std::cout << x1.use_count() << std::endl; //3 for(unsigned i = 0; i < v.size(); i++) std::cout x << std::endl;

6 boost::scoped_ptr boost::shared_ptr boost::intrusive_ptr boost::weak_ptr boost::scoped_array boost::shared_array

7 pimpl: class X { public: void func(int x, int y); … private: class Impl; boost::shared_ptr pimpl; };

8 std::pair boost::optional y; boost::optional z(10); //std::cout << *y << std::endl; y.reset(5); if (z && y) std::cout << "optional: " << *y << "," << *z << std::endl;

9 boost::optional boost::logic::tribool tribool x(indeterminate); tribool y(true); if (indeterminate(x == y)) …

10 boost::regex_match boost::regex e("(a?(ba)+\\d+)(tm)?"); std::string s("tmababa11tm"); if (boost::regex_match(s, e)) …

11 boost::regex_search boost::regex e("(abc)?(def)(ghi)+"); std::string s("abcdefghighi defdefghi defghi"); std::string::const_iterator start, end; start = s.begin(); end = s.end(); boost::match_results matched; while (boost::regex_search(start, end, matched, e)) { std::cout << " " << matched.str() << std::endl; start = matched[0].second; }

12 boost::regex_replace boost::regex e("(abc)(def)((ghi)+)"); std::string s("abcdefghighi defghi"); std::string r("\\1\\3"); std::cout << boost::regex_replace(s, e, r) << std::endl; //abcghighi ghi

13 using namespace boost::lambda; int seq[5] = {6,2,9,1,5}; std::vector v(seq, seq+5); int count = 0; count = (int)std::count_if(v.begin(), v.end(), _1 > 2); std::cout << "count: " << count << std::endl; //C++: _1 + 1 //C#: x => x + 1

14 std::bind1st, std::bind2nd, std::binder1st, std::binder2nd, std::ptr_fun(), std::mem_fun() template class Greater : public std::binary_function { public: bool operator()(const T& x, const T& y) const { return x > y; } };... int seq[5] = {6,2,9,1,5}; int count = 0; std::vector v(seq, seq+5); count = (int)std::count_if(v.begin(), v.end(), std::bind2nd(Greater (),2)); std::cout << "count: " << count << std::endl;

15 std::bind1st(std::ptr_fun(funct), 5)(x); boost::bind(funct, 5, _1)(x); boost::bind(funct, x, y); boost::bind(funct, boost::ref(x), y);

16 boost::shared_ptr x1(new X(10)); boost::function funct; //boost::function2 funct; funct = boost::bind(&X::func, x1, _1, _2); std::cout func(5,5.5)

17 boost::function fun; fun = Greater (); fun = &funct; std::cout << "fun: " << fun(5,8) << std::endl; //C#: delegate bool fun(int, int)

18 std::pair > boost::tuple typedef boost::tuple Tuple; int a = 1; double b = 2.4; int c = 8; char d = 'a'; Tuple tup(a, b, c, d); Tuple tup2 = boost::make_tuple(a, b, c, d); if (tup == tup2) …

19 Tuple tup3(3, 4, 5, 'b'); boost::tie(a,b,c,d) = tup3; int i = boost::get (tup); //tup.get (); boost::get (tup) = 5.4; std::cout << tup << std::endl;

20 boost::thread_group boost::thread boost::mutex boost::recursive_mutex boost::mutex::scoped_lock Mutex, Read/Write Mutex

21 boost::thread_group threads; for (int i = 0; i < 20; ++i) threads.create_thread(&thread_func); threads.join_all();

22 void* std::vector v; int m = 12; std::string s("boost"); boost::shared_ptr mp(new int(50)); v.push_back(m); v.push_back(s); v.push_back(mp); //boost::any_cast (v[0]); boost::any_cast (v[1]); //boost::any_cast (v[2]); *boost::any_cast >(v[2]);

23 boost::asio boost::conversion boost::filesystem boost::gil boost::graph boost::interval boost::math boost::mpl boost::parameter

24 boost::python boost::random boost::rational boost::spirit boost::timer boost::tokenizer boost::variant

25

26 Boost Software License

27 Technical Report 1 smart_ptr, function, bind, tuple, regex C++0x

28 Pytania?


Download ppt "Piotr Klecha. C++ Przegląd bibliotek Instalacja Przyszłe wersje C++"

Similar presentations


Ads by Google