Home   Notes   Contact Me

Boost c++ library

Local

External


String to int via lexicalcast

int index; try { index = boost::lexical_cast<int>(key); } catch(boost::bad_lexical_cast &) { // error }

tokenizer

UNICODE or std::wstring

std::wstring selector(L"the string to tokenize"); boost::tokenizer< boost::char_separator<wchar_t>, std::wstring::const_iterator, std::wstring > tok1(selector); wchar_t* escapeChars = L"\\"; // Use \ as an escape wchar_t* fieldSeperators = L".["; wchar_t* quoteChars = L"\"\'"; boost::escaped_list_separator<wchar_t> els1(escapeChars, fieldSeperators, quoteChars); typedef boost::tokenizer< boost::escaped_list_separator<wchar_t>, std::wstring::const_iterator, std::wstring > MyTokenizer; MyTokenizer tok2(selector, els1); for (MyTokenizer::iterator it = tok2.begin(); it != tok2.end(); it++) { }

Smart Pointers

Official page: http://www.boost.org/libs/smart_ptr/smart_ptr.htm

shared_ptr

MethodDescription
...
T* operator() const;
T* get() const;
Pointer that is wrapped
...

Debugging Boost

Note: This is Windows specific

  1. Boost throws assert failures that are caught by Microsoft's c runtime library
  2. At least in debug compiles
  3. This causes an abort to happen, which hides where the problem occured
  4. By default the output of the assert goes to ?stdout?, so it is not seen in Windows programming
  5. Microsoft's c runtime library can be told to popup a window when this problem occurs, which luckily happens in the same thread as the problem, which allows the problem to be traced down
  6. Use this to make it show a popup error message:
    _set_error_mode(_OUT_TO_MSGBOX);
    It is best to place it at the beginning of main.