2014-01-28 03:58:51 -08:00
|
|
|
/*
|
2019-02-22 17:59:05 -05:00
|
|
|
Copyright 2012-2019 Glen Joseph Fernandes
|
2017-03-06 08:36:57 -05:00
|
|
|
(glenjofe@gmail.com)
|
2015-11-08 00:38:22 -05:00
|
|
|
|
2017-03-06 08:36:57 -05:00
|
|
|
Distributed under the Boost Software License, Version 1.0.
|
|
|
|
(http://www.boost.org/LICENSE_1_0.txt)
|
2015-11-08 00:38:22 -05:00
|
|
|
*/
|
2014-01-28 03:58:51 -08:00
|
|
|
#ifndef BOOST_SMART_PTR_MAKE_UNIQUE_HPP
|
|
|
|
#define BOOST_SMART_PTR_MAKE_UNIQUE_HPP
|
|
|
|
|
2019-02-22 17:59:05 -05:00
|
|
|
#include <boost/type_traits/enable_if.hpp>
|
|
|
|
#include <boost/type_traits/is_array.hpp>
|
|
|
|
#include <boost/type_traits/is_unbounded_array.hpp>
|
|
|
|
#include <boost/type_traits/remove_extent.hpp>
|
|
|
|
#include <boost/type_traits/remove_reference.hpp>
|
2015-11-08 00:38:22 -05:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
namespace boost {
|
2017-03-06 08:36:57 -05:00
|
|
|
|
2015-11-08 00:38:22 -05:00
|
|
|
template<class T>
|
2019-02-22 17:59:05 -05:00
|
|
|
inline typename enable_if_<!is_array<T>::value, std::unique_ptr<T> >::type
|
2017-03-06 08:36:57 -05:00
|
|
|
make_unique()
|
2015-11-08 00:38:22 -05:00
|
|
|
{
|
|
|
|
return std::unique_ptr<T>(new T());
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
|
|
|
template<class T, class... Args>
|
2019-02-22 17:59:05 -05:00
|
|
|
inline typename enable_if_<!is_array<T>::value, std::unique_ptr<T> >::type
|
2017-03-06 08:36:57 -05:00
|
|
|
make_unique(Args&&... args)
|
2015-11-08 00:38:22 -05:00
|
|
|
{
|
|
|
|
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template<class T>
|
2019-02-22 17:59:05 -05:00
|
|
|
inline typename enable_if_<!is_array<T>::value, std::unique_ptr<T> >::type
|
|
|
|
make_unique(typename remove_reference<T>::type&& value)
|
2015-11-08 00:38:22 -05:00
|
|
|
{
|
|
|
|
return std::unique_ptr<T>(new T(std::move(value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2019-02-22 17:59:05 -05:00
|
|
|
inline typename enable_if_<!is_array<T>::value, std::unique_ptr<T> >::type
|
2017-03-06 08:36:57 -05:00
|
|
|
make_unique_noinit()
|
2015-11-08 00:38:22 -05:00
|
|
|
{
|
|
|
|
return std::unique_ptr<T>(new T);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2019-02-22 17:59:05 -05:00
|
|
|
inline typename enable_if_<is_unbounded_array<T>::value,
|
|
|
|
std::unique_ptr<T> >::type
|
2017-03-06 08:36:57 -05:00
|
|
|
make_unique(std::size_t size)
|
2015-11-08 00:38:22 -05:00
|
|
|
{
|
2019-02-22 17:59:05 -05:00
|
|
|
return std::unique_ptr<T>(new typename remove_extent<T>::type[size]());
|
2015-11-08 00:38:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
2019-02-22 17:59:05 -05:00
|
|
|
inline typename enable_if_<is_unbounded_array<T>::value,
|
|
|
|
std::unique_ptr<T> >::type
|
2017-03-06 08:36:57 -05:00
|
|
|
make_unique_noinit(std::size_t size)
|
2015-11-08 00:38:22 -05:00
|
|
|
{
|
2019-02-22 17:59:05 -05:00
|
|
|
return std::unique_ptr<T>(new typename remove_extent<T>::type[size]);
|
2015-11-08 00:38:22 -05:00
|
|
|
}
|
2017-03-06 08:36:57 -05:00
|
|
|
|
2015-11-08 00:38:22 -05:00
|
|
|
} /* boost */
|
2014-01-28 03:58:51 -08:00
|
|
|
|
|
|
|
#endif
|