2014-01-28 03:58:51 -08:00
|
|
|
/*
|
2017-03-06 08:36:57 -05:00
|
|
|
Copyright 2012-2015 Glen Joseph Fernandes
|
|
|
|
|
(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
|
|
|
|
|
|
2015-11-08 00:38:22 -05:00
|
|
|
#include <boost/config.hpp>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
|
|
namespace boost {
|
|
|
|
|
namespace detail {
|
2017-03-06 08:36:57 -05:00
|
|
|
|
2015-11-08 00:38:22 -05:00
|
|
|
template<class T>
|
|
|
|
|
struct up_if_object {
|
|
|
|
|
typedef std::unique_ptr<T> type;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class T>
|
2015-11-11 01:26:15 -05:00
|
|
|
struct up_if_object<T[]> { };
|
2015-11-08 00:38:22 -05:00
|
|
|
|
|
|
|
|
template<class T, std::size_t N>
|
2015-11-11 01:26:15 -05:00
|
|
|
struct up_if_object<T[N]> { };
|
2015-11-08 00:38:22 -05:00
|
|
|
|
|
|
|
|
template<class T>
|
2015-11-11 01:26:15 -05:00
|
|
|
struct up_if_array { };
|
2015-11-08 00:38:22 -05:00
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
struct up_if_array<T[]> {
|
|
|
|
|
typedef std::unique_ptr<T[]> type;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class T>
|
2016-02-19 08:09:25 -05:00
|
|
|
struct up_remove_reference {
|
|
|
|
|
typedef T type;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
struct up_remove_reference<T&> {
|
|
|
|
|
typedef T type;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
struct up_remove_reference<T&&> {
|
|
|
|
|
typedef T type;
|
2015-11-08 00:38:22 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class T>
|
2015-11-11 01:26:15 -05:00
|
|
|
struct up_element { };
|
2015-11-08 00:38:22 -05:00
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
struct up_element<T[]> {
|
|
|
|
|
typedef T type;
|
|
|
|
|
};
|
2017-03-06 08:36:57 -05:00
|
|
|
|
2015-11-08 00:38:22 -05:00
|
|
|
} /* detail */
|
|
|
|
|
|
|
|
|
|
template<class T>
|
2017-03-06 08:36:57 -05:00
|
|
|
inline typename detail::up_if_object<T>::type
|
|
|
|
|
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>
|
|
|
|
|
inline typename detail::up_if_object<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>
|
|
|
|
|
inline typename detail::up_if_object<T>::type
|
2017-03-06 08:36:57 -05:00
|
|
|
make_unique(typename detail::up_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>
|
2017-03-06 08:36:57 -05:00
|
|
|
inline typename detail::up_if_object<T>::type
|
|
|
|
|
make_unique_noinit()
|
2015-11-08 00:38:22 -05:00
|
|
|
{
|
|
|
|
|
return std::unique_ptr<T>(new T);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
2017-03-06 08:36:57 -05:00
|
|
|
inline typename detail::up_if_array<T>::type
|
|
|
|
|
make_unique(std::size_t size)
|
2015-11-08 00:38:22 -05:00
|
|
|
{
|
2017-03-06 08:36:57 -05:00
|
|
|
return std::unique_ptr<T>(new typename
|
|
|
|
|
detail::up_element<T>::type[size]());
|
2015-11-08 00:38:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
inline typename detail::up_if_array<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
|
|
|
{
|
2017-03-06 08:36:57 -05:00
|
|
|
return std::unique_ptr<T>(new typename
|
|
|
|
|
detail::up_element<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
|