Wednesday, June 30, 2010

Predefined Function Objects

The following are predefined C++ function objects:
        negate<type>()
        plus<type>()
        minus<type>()
        multiplies<type>()
        divides<type>()
        modulus<type>()
        equal_to<type>()
        not_equal_to<type>()
        less<type>()
        greater<type>()
        less_equal<type>()
        greater_equal<type>()
        logical_not<type>()
        logical_and<type>()
        logical_or<type>()

Reference: The C++ Standard Library: A Tutorial and Reference by Nicolas M. Josuttis. Addison-Wesley, 1999, p. 305.

Tuesday, June 29, 2010

Predefined Function Objects

The predefined function objects are declared in the <functional>
include file.

Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 305.

Saturday, June 26, 2010

Internationalization

"i18n" stands for internationalization. The "18" stands for the number of letters between 'i' and 'n'.

Reference: "The C++ Standard Library" by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 685.

Thursday, June 24, 2010

Enum

Given:
  enum MyEnum
  
  {

    zero,
    minus_ten = -10,
    mystery
  };

mystery equals -9.

Tuesday, June 22, 2010

The for_each() Algorithm

The for_each algorithm can take a range and a function object as parameters. It will apply the function object to each item in the range.
The for_each algorithm returns the function_object. It is the only algorithm that does this. You can query the returned function object to get its state.

Sunday, June 20, 2010

String Size and Length

For any string s, s.size() == s.length()

Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 476.

Saturday, June 19, 2010

String of Zeroes

If a string s, only contains 10 bytes of zero, then s.length() == 10.

Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 476.

Wednesday, June 16, 2010

String Resize

Given:
    string s;
    s.resize(10);

s.length() is equal to 10.

New character positions will be filled in with the default value of char, which is the null character (0).

Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 476.

Tuesday, June 15, 2010

Strings

A string can contain any character, i.e. any value from 0x00 to 0xFF.

Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 482.

Saturday, June 12, 2010

String

The following does not compile: std::string s('z');

Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 484.

Thursday, June 10, 2010

String

There are three string member functions to get the contents of a string into a C-style array: data(),c_str(),and copy(). c_str() is the only function that appends a '\0' to the end of the contents of the string.

Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis, Addison-Wesely, 1999, p. 484.

Tuesday, June 8, 2010

const string

Given: const std::string mine("mine"); (mine[mine.length()] == '\0') is true, because for constant strings, the '\0' is guaranteed to be there.

Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis, Addison-Wesley, 1999, p. 487.

Sunday, June 6, 2010

Strings

Given:
    std::string theirs["theirs"];
The behavior of the following is undefined:
    theirs[theirs.length()] == '\0';
Reference: The C++ Standard Library: A Tutorial and Reference, Nicolai M. Josuttis. Addison-Wesley, 1999, p. 487.

Friday, June 4, 2010

data() and c_str() can invalidate iterators

A call to data() or c_str() can invalidate pointers, references, and iterators referring to characters of a string, because these functions may cause copying of the data to another buffer.

Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 488.

Wednesday, June 2, 2010

Parentheses Operator

If you are using the parentheses operator, you are calling a function.

Reference: The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis. Addison-Wesley, 1999, p. 489.