Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-08-31 11:55:41


From: "Jonathan Turkanis" <technews_at_[hidden]>
>
> Here's a summary of the names and extensions I'd like to see:
>
> - multi_skipper, etc. I'd like these usages to be supported:
>
> cin >> skip_line >> ... // skip a line
> cin >> skip_lines(12) >> .. // skip 12 lines

Someone raised the issue of singular versus plural causing
confusion, but since "skip_line" takes no arguments, and
"skip_lines" takes arguments, there should be no problem.

> cin >> skip('c', 3) >> ... // skip 3 c's
> cin >> skip("hello world!") >> .. // skip given sequence

Nice. This, too:

   cin >> skip('x') >> ... // skip one 'x'

> cin >> skip_if(isalpha) // skip alphabetic characters
> cin >> skip_to(isalpha) // skip non-alphabetic characters

These are terrific ideas. Obviously, the argument should be a
predicate of general form so that clients can make their own.

> - multi_newer, etc.
>
> cout << newline << ... // write a newline without flushing
> cout << newlines(7) << ... // write 7 newlines

Again, the singular versus plural issue is moot given the
distinct invocation syntax.

> cout << repeat('c', 3) << ... // write 3 c's

A question was raised wrt "repeat." If that's a problem, I
suggest these alternatives ("repeat" is the best, though):

   ditto
   copy (would be a problem as std::copy)
   replicate
   multiple
   multi

It would be interesting to make "repeat" (or whatever) a class so
that it could be used to generate a string, insert on a stream,
be iterable, etc.:

template <typename T>
class ditto
{
public:
   typedef ... iterator;
   typedef ... const_iterator;

   ditto(T value, std::size_t const count_i);

   iterator
   begin();

   const_iterator
   begin() const;

   iterator
   end();

   const_iterator
   end() const;

   std::string
   toString() const;

   template <class OutputStream>
   void
   insert(OutputStream & os_i) const;

private:
   T value_;
   std::size_t count_;
};

template <class OutputStream>
OutputStream &
operator <<(OutputStream & os_i, ditto const & value_i)
{
   value_i.insert(os_i);
   return os_i;
}

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk