Boost logo

Boost :

Subject: Re: [boost] [Range] New I/O functions for ranges
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2014-10-06 05:56:44


> -----Original Message-----
> From: Boost [mailto:boost-bounces_at_[hidden]] On Behalf Of Indiana
> Sent: 05 October 2014 16:47
> To: boost_at_[hidden]
> Subject: Re: [boost] [Range] New I/O functions for ranges
>
> On 14-10-01 05:00 AM, Paul A. Bristow wrote:
> > You may well be right, but I'm only reporting what I found were my 'needs'.
> >
> > You can show how to wrap write_all output (with 'smart' delimiter - no
> > ugly trailing commas!) with prefix and suffix strings, that will probably be
fine.
> Yeah, sure - actually write_all() does that right out of the box:
>
> o << "prefix" << write_all({1,2,3}, "delimiter") << "suffix"; // Prints:
> "prefix1delimiter2delimiter3suffix";
>
> So:
>
> o << '{' << write_all({1,2,3}, ',') << '}'; // Prints: "{1,2,3}"
> > I only meant a string in C++ syntax like
> >
> > int[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
> >
> > that you have shown is possible.
> Actually, you can probably generalize that. The following code isn't tested,
but:
>
> template <typename Range, typename CharT, typename Traits> void
> format_range(std::basic_ostream<CharT, Traits>& o, Range&& r) {
> using std::begin;
> using std::end;
> using value_type = std::decay_t<typename range_value<Range>::type>;
>
> std::basic_ostringstream<CharT, Traits> oss{};
> oss.imbue(std::locale::classic());
>
> oss << boost::typeindex::type_id<value_type>().pretty_name();
> oss << '[' << std::distance(begin(r), end(r)) << ']' << " = ";
> oss << '{' << write_all(std::forward<Range>(r), ", ") << "};\n";
>
> o << oss.str();
> }
>
> Calling format_range() for any range type should give the output you want,
more or
> less, dependent on the range value type.
>
> auto v = std::vector<int>{1,2,3};
> cout << format_range(v); // Prints: "int[3] = {1, 2, 3};"
> auto const a = std::array<double, 4>{1.1, 2.2, 3.3, 4.4}; cout <<
format_range(a); //
> Prints: "double[4] = {1.1, 2.2, 3.3, 4.4};"

Even neater :-)

> > Now you need some enthusiastic users to support you on a review ;-)
> Yeah? I'm not sure how the process goes here.

Nor me.

I assume you've seen

http://www.boost.org/development/requirements.html

> Do I make a pull request on the
> Boost.Range repository and implement the changes? Or do I implement the idea
> separately, so people can experiment and mess around with it, and only after
it's
> passed review try to integrate it with the rest of the library? Do I get in
touch with
> the Boost.Range maintainers (seems to be Thorsten Ottosen and Neil Groves)?

I doubt if you should try to add to the existing range library - unless the
Boost.Range maintainers are keen, but yes - do ask.

You could produce a new-name (range_write, range_out, range_IO?) sub-module at
GIThub that people can clone into their existing Boost GIT files to see if they
like it?

Good luck!

Paul

---
Paul A. Bristow
Prizet Farmhouse
Kendal UK LA8 8AB
+44 (0) 1539 561830
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

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