61 lines
2.1 KiB
C++
61 lines
2.1 KiB
C++
/* ***************************************************************************
|
|
*
|
|
* FastFlow is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU Lesser General Public License version 3 as
|
|
* published by the Free Software Foundation.
|
|
* Starting from version 3.0.1 FastFlow is dual licensed under the GNU LGPLv3
|
|
* or MIT License (https://github.com/ParaGroup/WindFlow/blob/vers3.x/LICENSE.MIT)
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
* License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*
|
|
****************************************************************************
|
|
*/
|
|
|
|
|
|
#ifndef FF_MAKEUNIQUE_HPP
|
|
#define FF_MAKEUNIQUE_HPP
|
|
|
|
#include <memory>
|
|
#include <type_traits>
|
|
#include <utility>
|
|
|
|
|
|
#if __cplusplus < 201400L // to check
|
|
// C++11 implementation of make_unique
|
|
|
|
#if (__cplusplus >= 201103L) || (defined __GXX_EXPERIMENTAL_CXX0X__) || (defined(HAS_CXX11_VARIADIC_TEMPLATES))
|
|
template <typename T, typename... Args>
|
|
std::unique_ptr<T> make_unique_helper(std::false_type, Args&&... args) {
|
|
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
|
}
|
|
|
|
template <typename T, typename... Args>
|
|
std::unique_ptr<T> make_unique_helper(std::true_type, Args&&... args) {
|
|
static_assert(std::extent<T>::value == 0,
|
|
"make_unique<T[N]>() is forbidden, please use make_unique<T[]>().");
|
|
|
|
typedef typename std::remove_extent<T>::type U;
|
|
return std::unique_ptr<T>(new U[sizeof...(Args)]{std::forward<Args>(args)...});
|
|
}
|
|
|
|
template <typename T, typename... Args>
|
|
std::unique_ptr<T> make_unique(Args&&... args) {
|
|
return make_unique_helper<T>(std::is_array<T>(), std::forward<Args>(args)...);
|
|
}
|
|
#endif
|
|
|
|
#else
|
|
|
|
using std::make_unique;// need to check if only the name is sufficient
|
|
|
|
#endif
|
|
|
|
|
|
#endif // FF_MAKEUNIQUE_HPP
|