Có 60+ tài liệu thuộc chủ đề "program documentation"
tailieu.vn Xem trực tuyến Tải xuống
intrusive_ptr. Header: "boost/intrusive_ptr.hpp". intrusive_ptr is the intrusive analogue to shared_ptr. (Actually, there are ways to solve that problem with non- intrusive smart pointers too, as we saw earlier in this chapter.) intrusive_ptr is different from the other smart pointers because it requires you to provide the reference counter that it manipulates.. When intrusive_ptr increments or decrements a reference count on...
tailieu.vn Xem trực tuyến Tải xuống
some_class(). "some_class::some_class()\n";. some_class(const some_class&. "some_class(const some_class&. ~some_class(). "some_class::~some_class()\n";. boost::intrusive_ptr<some_class>. intrusive_ptr_add_ref and intrusive_ptr_release do their jobs right, here is the output from running the program:. Before start of scope some_class::some_class() some_class::~some_class() After end of scope. The intrusive_ptr is taking care of business for us. intrusive_ptr p1 is created, it is passed a new instance of some_class . The intrusive_ptr constructor actually...
tailieu.vn Xem trực tuyến Tải xuống
void intrusive_ptr_add_ref(T* t. void intrusive_ptr_release(T* t. Here, we have implemented generic versions of intrusive_ptr_add_ref and intrusive_ptr_release. boost::intrusive_ptr<my_namespace::another_class>. boost::intrusive_ptr<A>. boost::intrusive_ptr<my_namespace::derived_class>. First, the intrusive_ptr p1 is passed a new instance of my_namespace::. When resolving the call to intrusive_ptr_add_ref, the compiler finds the version in my_namespace, the namespace of the my_namespace::. intrusive_ptr_release, too. Then, the intrusive_ptr p2 is created and passed a pointer...
tailieu.vn Xem trực tuyến Tải xuống
weak_ptr_unary(std::equal_to<string>(),string("of using")));. shared_ptr<string>. The most interesting line of code (yes, it's quite a long one) is where we create a weak_ptr_unary_t for use with the find_if algorithm.. vector<weak_ptr<string>. weak_ptr_unary(. std::equal_to<string>(),string("of using")));. The function object is created by passing another function object, std::equal_to, to the helper function weak_ptr_unary, together with the string that is to be used for the matching. Because...
tailieu.vn Xem trực tuyến Tải xuống
polymorphic_cast. Header: "boost/cast.hpp". Polymorphic conversions in C++ are performed via dynamic_cast. dynamic_cast tHRows an exceptionstd::bad_castif the conversion is not possible when used on a reference type. Of course, when using dynamic_cast to convert a pointer type, failure is indicated by returning the null pointer.. dynamic_cast's different behavior depending on whether pointer or reference types are used is a valuable property,...
tailieu.vn Xem trực tuyến Tải xuống
When you have a question about the behavior of a certain method, e.g., IO#gets, you can invoke ri IO#gets to read the brief explanation of the method. You can get ri from. http://www.pragmaticprogrammer.com/ruby/downloads/ri.html.. method 5.2.2 eRuby. it's a tool that embeds fragments of Ruby code in other files such as HTML files. eruby is available from http://www.modruby.net/.. Unfortunately, the supporting...
tailieu.vn Xem trực tuyến Tải xuống
ruby -r debug sieve.rb 100 Debug.rb. sieve.rb:2:max = Integer(ARGV.shift. [-3, 6] in sieve.rb. [7, 16] in sieve.rb 7. 14 puts sieve.compact.join . Set breakpoint 1 at sieve.rb:8 (rdb:1) c. Breakpoint 1, toplevel at sieve.rb:8 sieve.rb:8:for i in 2. Set breakpoint 2 at sieve.rb:14 (rdb:1) c. Breakpoint 2, toplevel at sieve.rb:14 sieve.rb:14:puts sieve.compact.join . [nil, nil, 2, 3, nil, 5, nil,...
tailieu.vn Xem trực tuyến Tải xuống
soc=dynamic_cast<some_other_class&>(*p);. dynamic_cast<some_other_class*>(p. In this example, the pointer p is dereferenced [5] and the target type of the. This invokes the throwing version of dynamic_cast. The second part of the example uses the non- throwing version by converting to a pointer type. Whether you see this as a clear and concise statement of the code's intent depends upon your experience. Will...
tailieu.vn Xem trực tuyến Tải xuống
lexical_cast. Header: "boost/lexical_cast.hpp". That's lexical_cast 's purpose. lexical_cast as using a std::stringstream as an interpreter between the string and other representation of a value. appropriate operator<<. lexical_cast makes a conversion between types look like any other type- converting cast. Rather than calling one of a number of conversion routines, or even coding the conversion locally, lexical_cast does that job for...
tailieu.vn Xem trực tuyến Tải xuống
Compile time assertions with BOOST_STATIC_ASSERT. Safe destruction with checked_delete and checked_array_delete. We'll start with BOOST_STATIC_ASSERT, a facility for asserting integral constant expressions at compile time. checked_delete makes that discussion more interesting. BOOST_STATIC_ASSERT Header: "boost/static_assert.hpp". There are many variations for performing runtime assertions, but how do you assert at compile time? Of course, the only way to do that is to...
tailieu.vn Xem trực tuyến Tải xuống
Header: "boost/utility.hpp". I'm not talking about comments in the code, but about denying access to the copy constructor and copy assignment operator. Fortunately, the compiler-generated copy constructor and copy assignment operator are not usable when the class has bases or data members that aren't copyable or assignable.. boost::noncopyable works by prohibiting access to its copy constructor and assignment operator and...
tailieu.vn Xem trực tuyến Tải xuống
When taking the address of a variable, we typically depend on the returned value to be, well, the address of the variable. However, it's technically possible to overload operator&. It is used where operator&. class some_class. some_class s;. some_class* p=boost::addressof(s);. Before seeing more details on how to use addressof , it is helpful to understand why and how operator&. If...
tailieu.vn Xem trực tuyến Tải xuống
This is one of the shortest chapters in the book, and I suspect that you've read through it fairly quickly. How Does the Operators Library Improve Your Programs?. Among the operators defined in C. you expect to find operator!= and probably operator<, operator<. Sometimes, a class only provides operator<. When you define one operator from a set for your class,...
tailieu.vn Xem trực tuyến Tải xuống
To start using the Operators library, implement the applicable operator(s) for your class, include "boost/operators.hpp", and derive from one or more of the Operator base classes (they have the same names as the concepts they help implement), which all reside in namespace boost. For the first example of usage, we'll define a class, some_class, with an operator<. We decide that...
tailieu.vn Xem trực tuyến Tải xuống
assert(a<b &&. a<c &&. !(b<a) &&. b<c &&. !(c<a) &&. assert(!(x<a) &&. assert( (!(x<a) &&. !(a<x)) &&. (!(y<x) &&. !(x<y)) &&. (!(y<a) &&. This method removes the inheritance from multiple empty base classes, which may not trigger your compiler's empty base optimization, in favor of derivation from a chain of empty base classes, increasing the chance of triggering the empty...
tailieu.vn Xem trực tuyến Tải xuống
If two elements are compared, and neither is less than the other, we can consider them to be equivalent. For example, it may be reasonable to omit certain characteristics from a less than relation, but consider them for equality. class animal : boost::less_than_comparable<animal, boost::equality_comparable<animal>. with the age ". Only the animal's name is part of the less than relation, whereas...
tailieu.vn Xem trực tuyến Tải xuống
But there are also less clear-cut cases, where one needs to consider the expectations of clients of the class, and where perceived ambiguity might make a member function a better choice.. Concatenating strings with addition operators and I/O with shift operators are two common examples where the operators do not necessarily have a mathematical meaning, but have been used for...
tailieu.vn Xem trực tuyến Tải xuống
Brings support for regular expressions to C++. Regular expressions are very often used in text processing. For example, there are a number of validation tasks that are suitable for regular expressions. and using regular expressions to do the validation is straightforward. Another typical area where regular expressions excel are text substitutionsthat is, replacing some text with other text. Again, regular...
tailieu.vn Xem trực tuyến Tải xuống
To begin using Boost.Regex, you need to include the header "boost/regex.hpp".. Regex is one of the two libraries (the other one is Boost.Signals) covered in this book that need to be separately compiled. The first thing you need to do is to declare a variable of type basic_regex. This is one of the core classes in the library, and it's...
tailieu.vn Xem trực tuyến Tải xuống
if (boost::regex_search(s,m,reg. if (m[1].matched). "The expression (new) matched!\n";. if (m[2].matched). "The expression (delete) matched!\n";. The preceding program searches the input string for new or delete , and reports which one it finds first. regex_search , we gain access to the details of how the algorithm succeeded. In our expression, there are two subexpressions, and we can thus get to the....