C++ 2: boost::bind & boost::function

Download C++ 2: boost::bind & boost::function

Post on 07-Jul-2015

181 views

Category:

Documents

1 download

Embed Size (px)

TRANSCRIPT

<ul><li> 1. 6. Valery Lesin. C++ In-Depth, 2014 1 </li></ul> <p> 2. std::terminate : ; ; . Valery Lesin. C++ In-Depth, 2014 2 3. try...catch Valery Lesin. C++ In-Depth, 2014 3 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. try { // throws explicit or implicit throw exception_type(/*...*/); //... } catch(std::exception const&amp; err) {/*...*/} catch(...) { /*...*/ throw; } //... Type::Type(/*...*/) try : field1_(/*...*/) , field2_(/*...*/) { /*...*/ } catch(std::exception const&amp;) { /*some logging*/ throw; } 4. ( int const char*) , std::exception ( what) , , std::runtime_error, logic_error () ; ; . Valery Lesin. C++ In-Depth, 2014 4 5. RAII ? Valery Lesin. C++ In-Depth, 2014 5 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. double sqrt(double value) { if (value &lt; 0) throw runtime_error("nagative"); /*...*/ } double* make_roots(double* values, size_t size) { double* roots = new double[size]; transform(values, values + size, roots, sqrt); return roots; } 6. RAII (2) ? Valery Lesin. C++ In-Depth, 2014 6 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. double* make_roots(double* values, size_t size) { double* roots = new double[size]; try { transform(values, values + size, roots, sqrt); } catch(std::exception const&amp; err) { delete [] roots; cerr</p>