# flex_string

This code accompanies the article "Type-Safe Formatting" in C/C++ Users Journal, July 2005. It implements a simple `printf` emulation framework, which is typesafe at the price of a slightly modified invocation syntax.

`flex_string` is a drop-in replacement for the standard string (`std::basic_string`, better known by its `typedef`ed name, `std::string`. If you think that reimplementing a likely fine-tuned component of your standard library is not a very rewarding endeavor, think again. `flex_string` has a policy-based design allowing unparalleled control over its behavior and optimizations, and also allows you to define new implementations in only a few dozens of lines of code. If you're looking for controllable performance and predictible behavior with multiple threads, then `flex_string` might be of interest to you.

To find more about `flex_string`, you may want to read "A Policy-Based `basic_string` Implementation," C/C++ Users Journal, June 2001.

The downloadable code consists of the `flex_string` header and a test suite that compares its behavior against `std::string`. Though no performance comparison suite is available at this time, Harmut Kaizer reported that simply dropping in `flex_string` in the Wave Boost Preprocessor improved its speed by 5-10%, depending on input.

Justin Matthews contributed with flex_string_hash.h, an add-on for `flex_string` that allows using it with hash maps. Justin's code supports (and automatically recognizes) two implementations: STLPort and Microsoft Visual C++ 7.1.