in Listener, remove raw pointers allocations, use unique_ptr instead.

Add an overload of sls::make_unique for array types.
This commit is contained in:
Samuel Debionne
2019-03-06 08:55:19 +01:00
parent ceb515d517
commit db232ad00d
3 changed files with 42 additions and 45 deletions

View File

@ -8,6 +8,7 @@
#include <vector>
#include <sstream>
#include <memory>
namespace sls {
@ -15,10 +16,20 @@ namespace sls {
// C++11 make_unique implementation for exception safety
// already available as std::make_unique in C++14
template <typename T, typename... Args>
std::unique_ptr<T> make_unique(Args &&... args) {
typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T>>::type
make_unique(Args &&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
template <typename T>
typename std::enable_if<std::is_array<T>::value, std::unique_ptr<T>>::type
make_unique(std::size_t n)
{
typedef typename std::remove_extent<T>::type RT;
return std::unique_ptr<T>(new RT[n]);
}
template <typename T>
bool allEqual(const std::vector<T>& container)
{