gdb: add gdb::make_unique function

While GDB is still C++11, lets add a gdb::make_unique template
function that can be used to create std::unique_ptr objects, just like
the C++14 std::make_unique.

If GDB is being compiled with a C++14 compiler then the new
gdb::make_unique function will delegate to the std::make_unique.  I
checked with gcc, and at -O1 and above gdb::make_unique will be
optimised away completely in this case.

If C++14 (or later) becomes our minimum, then it will be easy enough
to go through the code and replace gdb::make_unique with
std::make_unique later on.

I've make use of this function in all the places I think this can
easily be used, though I'm sure I've probably missed some.

Should be no user visible changes after this commit.

Approved-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
Andrew Burgess
2023-08-10 17:57:46 +01:00
parent adc5f8b99a
commit 0b72cde372
15 changed files with 32 additions and 22 deletions

View File

@@ -56,6 +56,19 @@ struct noop_deleter
void operator() (T *ptr) const { }
};
/* Create simple std::unique_ptr<T> objects. */
template<typename T, typename... Arg>
std::unique_ptr<T>
make_unique (Arg &&...args)
{
#if __cplusplus >= 201402L
return std::make_unique<T> (std::forward<Arg> (args)...);
#else
return std::unique_ptr<T> (new T (std::forward<Arg> (args)...));
#endif /* __cplusplus < 201402L */
}
} /* namespace gdb */
/* Dup STR and return a unique_xmalloc_ptr for the result. */