Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-08-31 12:30:51


"Rob Stewart" <stewart_at_[hidden]> wrote in message
news:200408311655.i7VGtfY13582_at_lawrencewelk.systems.susq.com...
> 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.

I'm glad you agree.

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

Thanks.

>
> 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.

That was what I was thinking.

> > - 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

A bit too cute, I think ;-)

> copy (would be a problem as std::copy)

and would clash with boost::io::copy, if my iostreams library is accepted.

> replicate
> multiple
> multi

These are all on the right track, but none is as intuitive as 'repeat', I think.
Do you think 'iterate' has too many connotations?

> 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;
> }

Thanks sounds good.

Regards,
Jonathan


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