Island in the Streams
, and ustl::cerr
work mostly the same as their standard counterparts. For example:
using namespace ustl;
cout << "Hello world!" << endl;
cout << 456 << ios::hex << 0x1234 << endl;
cerr.format("object address: 0x%08X\n", &o);//format() is a uSTL extension
That's pretty much it for console I/O in uSTL. <fstream>
classes are not implemented yet. To perform file I/O, you create a string buffer, call read_file()
, and then attach a stream to it. It's ugly but gets the job done.
The major difference between ISO STL and uSTL is that the former uses a distinct allocator per specialization, whereas the latter keeps all the memory management logic in a single base class. When ISO STL containers reallocate storage, they call new to create more storage and then copy the elements to the new destination. This technique incurs size and speed penalties. uSTL uses a different approach. It manages memory as an opaque, typeless block, and then uses the container templates to cast it to an appropriate pointer type. I know what you're thinking: bitwise copying of objects is a no-no, and you're right. However, uSTL doesn't copy elements; it merely moves them.
What's Still Missing
I've given you the impression that uSTL is a compact, smart and clutter free version of ISO STL. This is true in most part but there are a few caveats you should take note of if you plan to port existing apps to a mobile platform. The most noticeable deviation from ISO STL is the absence of standard function objects such as greater, less, etc. Sharov's rationale for this deliberate omission doesn't sound convincing. Indeed, some of STL's abstruse features don't have a place in a tightly packed implementation but function objects and predicates are too important to be completely dismissed. Additional unimplemented features include:
- File stream classes. This could cause porting difficulties but you can get by with read_file().
- deque and priority_queue.
- Heap algorithms such as push_heap(), make_heap(), etc.
- TR1 hashed containers (now officially called "unordered containers"), like unordered_map. This isn't a major issue since many existing ISO STL implementations don't offer these yet.
- wchar_t-oriented stream and string classes
| Author's Note: Since the time of writing, uSTL 1.0 has been released. The new version is much closer to ISO STL as it provides many features that were missing from version 0.8, including fstream classes, function objects, and function adaptors (like unary_negate and unary_function)as well as non-standard extensions such as the select1st and select2nd algorithms.
Overall, uSTL 0.8 is much closer to ISO STL than I anticipated, in spite of its peculiar design. Although it contains a subset of ISO STL, it will suit the needs of the average C++ programmer who simply needs reliable and familiar building blocks such as vector, list, sort(), remove() and cout. Considering the shoddy classes and proprietary APIs that Symbian developers use as alternatives to containers and algorithms, uSTL is light years ahead. uSTL gets a major thumbs up!