mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-15 22:37:14 +02:00
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:
@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user