Files
boost_smart_ptr/include/boost/smart_ptr/make_unique.hpp

65 lines
1.6 KiB
C++
Raw Normal View History

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)
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)
*/
2014-01-28 03:58:51 -08:00
#ifndef BOOST_SMART_PTR_MAKE_UNIQUE_HPP
#define BOOST_SMART_PTR_MAKE_UNIQUE_HPP
#include <boost/smart_ptr/detail/sp_type_traits.hpp>
#include <memory>
2024-10-06 18:44:04 +03:00
#include <type_traits>
#include <utility>
namespace boost {
2017-03-06 08:36:57 -05:00
template<class T>
2024-10-06 19:35:07 +03:00
inline typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T> >::type
2017-03-06 08:36:57 -05:00
make_unique()
{
return std::unique_ptr<T>(new T());
}
template<class T, class... Args>
2024-10-06 19:35:07 +03:00
inline typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T> >::type
2017-03-06 08:36:57 -05:00
make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
template<class T>
2024-10-06 19:35:07 +03:00
inline typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T> >::type
2024-10-06 18:44:04 +03:00
make_unique(typename std::remove_reference<T>::type&& value)
{
return std::unique_ptr<T>(new T(std::move(value)));
}
template<class T>
2024-10-06 19:35:07 +03:00
inline typename std::enable_if<!std::is_array<T>::value, std::unique_ptr<T> >::type
2017-03-06 08:36:57 -05:00
make_unique_noinit()
{
return std::unique_ptr<T>(new T);
}
template<class T>
inline typename std::enable_if<detail::sp_is_unbounded_array<T>::value,
2019-02-22 17:59:05 -05:00
std::unique_ptr<T> >::type
2017-03-06 08:36:57 -05:00
make_unique(std::size_t size)
{
2024-10-06 19:26:17 +03:00
return std::unique_ptr<T>(new typename std::remove_extent<T>::type[size]());
}
template<class T>
inline typename std::enable_if<detail::sp_is_unbounded_array<T>::value,
2019-02-22 17:59:05 -05:00
std::unique_ptr<T> >::type
2017-03-06 08:36:57 -05:00
make_unique_noinit(std::size_t size)
{
2024-10-06 19:26:17 +03:00
return std::unique_ptr<T>(new typename std::remove_extent<T>::type[size]);
}
2017-03-06 08:36:57 -05:00
} /* boost */
2014-01-28 03:58:51 -08:00
#endif