Honour must be given to whom honour is due. Firstly, honour must be given to Bjarne Stroustrup for providing us with the C++ formalism with which we present our ideas. Secondly, honour must be given to Alexander Stepanov for presenting to us this style of reasoning, his ideas and hard-work have greatly changed the way programs are written.
All codes presented here are based on what the smart minds behind SGI STL have bequeathed to humanity. I do not make claim to the concepts, approaches detailed here but only provide explanations based on my understanding with the hope that it may be useful to some other programmer who cares about beautifully crafted components.
What is a better way to put theory to test if not by implementation. I classify algorithms at Algorithmcity. Confident of my C++ skills, I applied at think-cell, I flunked the interview, I was humbled and needed to rethink my design approach. I was made to appreciate the difference between coding an algorithm and designing a useful software component. First I devoured most papers by Alexander Stepanov, then I set my eyes on the Standard Template Library and the Boost Library. This are some of the things I have learn’t when messing with this libraries.
Ostream iterator models an output iterator. It outputs objects of a particular type to an ostream.
code fragment: (line #4 — #6)
Here we defined the character type, character traits type and the stream type.
code fragment: (line #8 — #12)
Here the iterator traits of the ostream_iterator class are defined. Its iterator category is output iterator denoted by output_iterator_tag. The reference , difference type, pointer and value type are all void.
code fragment: (line #14 — #21)
Here, semi-regular operations are defined for the ostream_iterator type as well as constructors for construction.
code fragment: (line #23 — #25)
Line #23 defines dereferencing through operator*().
Line #24 defines pre-increment operator through operator++().
Line #25 defines post-increment operator through operator++(int).