Chapter 35. Intermezzo: Proscribing Fatuous Output Iterator Syntax Using the Dereference Proxy Pattern
If knowledge can create problems, it is not through ignorance that we can solve them. | ||
--Isaac Asimov |
As was discussed in the last chapter, std::ostream_iterator
supports the required semantics of an output iterator by using a simple implementation trick, whereby the dereference operator (operator *()
) returns an instance to the object and an assignment operator (operator =()
) taking the assigned type is defined. (See Listing 34.5 to see how it is implemented for stlsoft::ostream_iterator
.) Consider the following code:
1 std::ostream_iterator<int> iter(std::cout); 2 3 *iter = 10; // Sensible
Line 3 is equivalent to:
iter.operator *().operator =(10); ...
Get Extended STL, Volume 1: Collections and Iterators now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.