Re: [PATCH v2 31/31] Support an "unlimited" number of user-defined arguments

Philipp Rudo
2016-10-19T17:40:51Z

On Wed, 19 Oct 2016 13:47:22 +0100
Pedro Alves <palves@redhat.com> wrote:

> On 10/19/2016 12:33 PM, Philipp Rudo wrote:
> > Pedro Alves <palves@redhat.com> wrote:
>
> >> I also needed a way to convert a number to a std::string, so I added a
> >> new utility for that, gdb::to_string. Yet another thing that can go
> >> away with C++11.
> > [... snip ...]
> >> +/* Returns a string representation of VAL. Replacement for
> >> + std::to_string, which is only available in C++11 or later. */
> >> +
> >> +namespace gdb {
> >> +
> >> +template <class T>
> >> +inline std::string
> >> +to_string (const T &val)
> >> +{
> >> + std::stringstream ss;
> >> +
> >> + ss << val;
> >> + return ss.str ();
> >> +}
> >> +
> >> +}
> >> +
> >> /* Make a copy of the string at PTR with LEN characters
> >> (and add a null character at the end in the copy).
> >> Uses malloc to get the space. Returns the address of the copy. */
> >
> > Is this really necessary?
> > As far as I understood the discussion, we jump directly to C++11. Thus there is no need for an homemade to_string.
>
> We haven't actually officially committed to requiring
> C++11, so I didn't want to be blocked by that. It's
> trivial to remove that bit latter if this lands first.

True that C++11 is not official yet. But the "trivial to remove" is
exactly the reason I wrote, as those pieces of code tend to stay in the longest.
And in 10+ years nobody knows why there is such a messy mix of different
functions doing the same thing and why it hasn't been done right in the
first place ;)

So my mail should not push you to use std::to_string but be seen as a reminder,
that if we require C++11 your home made function should be deleted better sooner
than later.

Phil