std::numeric_limits<char>::is_signed tells you if char is a signed type or not.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 61-62.
Monday, August 30, 2010
Saturday, August 28, 2010
NULL
A C NULL is (void*)0, a C++ NULL is 0.
Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 71.
Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 71.
Thursday, August 26, 2010
atexit() Function
Functions registered by atexit() are executed in reverse order when a program ends.
If exit() is called, these functions are still called.
If abort() is called, these functions are not called.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 71.
If exit() is called, these functions are still called.
If abort() is called, these functions are not called.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 71.
Wednesday, August 25, 2010
Tertiary Operator
Given:
int x = 0; int y = 0;Then:
(1 ? x : y) = 4;Sets x to 4.
Tuesday, August 24, 2010
String's push_back() Member Function
The string container has a push_back() member function.
Reference: The C++ Standard Library by Nicolai Josuttis. Addison-Wesley, 1999, p. 81.
Reference: The C++ Standard Library by Nicolai Josuttis. Addison-Wesley, 1999, p. 81.
Sunday, August 22, 2010
Incrementing an Insert Iterator
Incrementing an insert iterator is a NO OP.
Reference: The C++ Standard Library by Nicolai M. Josuttiis. Addison-Wesley, 1999, p. 104.
Reference: The C++ Standard Library by Nicolai M. Josuttiis. Addison-Wesley, 1999, p. 104.
Friday, August 20, 2010
Vector at() Function
If you have a vector v; v.at(10) will do range checking, while v[10] will not.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 152.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 152.
Wednesday, August 18, 2010
POD Data
Every ordinary C structure is POD data (Plain Old Data).
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 156.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 156.
Monday, August 16, 2010
Vector Reallocations
When a vector is forced to perform a reallocation, all of its elements must to be copied. For a deque (pronounced "deck"), it is not always necessary that all of its elements are copied during a reallocation. This is because a deque does not have to be stored contiguously as in the case of a vector.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 161.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 161.
Sunday, August 15, 2010
capacity() and reserve()
Vector and string provide the functions capacity() and reserve(). They are the only STL containers that have these functions.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 163.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 163.
Thursday, August 12, 2010
at() and operator[]() Functions
Vectors and deques provide the at() and operator[]() functions. Having these functions happens to correspond with containers that have Random Access Iterators, with one exception. map has operator[](), but does not have a random access iterator. Map's operator[]() does not execute in constant time, O(1); whereas containers with random access iterators are able to execute in constant time.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 162.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 162.
Tuesday, August 10, 2010
List front() and back()
On a list, el, if the element el.front() exists, then el.back() also exists.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 168.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 168.
Sunday, August 8, 2010
C++ Containers
C++ set, multiset, list, map, and multimap are node-based containers. The other kind of container is the array-based container. String, vector, and deque are arry-based containers.
Node-based iterators only become invalid when the item they point to is erased.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 185.
Node-based iterators only become invalid when the item they point to is erased.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 185.
Friday, August 6, 2010
Random Access Iterators
Pointers are random access iterators.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 218.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 218.
Wednesday, August 4, 2010
Iterator Categories
Vector, deque, and string have random access iterators; list, set, multiset, map and multimap have bidirectional iterators.
The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 239.
The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 239.
Monday, August 2, 2010
Reverse Iterators
All of the following have reverse iterators: vector, deque, list, set, multiset, map, multimap, and string.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 240.
Reference: The C++ Standard Library by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 240.
Subscribe to:
Posts (Atom)