diff options
Diffstat (limited to 'boost/smart_ptr')
-rw-r--r-- | boost/smart_ptr/detail/up_if_array.hpp | 26 | ||||
-rw-r--r-- | boost/smart_ptr/detail/up_if_not_array.hpp | 31 | ||||
-rw-r--r-- | boost/smart_ptr/make_unique.hpp | 108 | ||||
-rw-r--r-- | boost/smart_ptr/make_unique_array.hpp | 31 | ||||
-rw-r--r-- | boost/smart_ptr/make_unique_object.hpp | 45 | ||||
-rw-r--r-- | boost/smart_ptr/shared_ptr.hpp | 2 |
6 files changed, 100 insertions, 143 deletions
diff --git a/boost/smart_ptr/detail/up_if_array.hpp b/boost/smart_ptr/detail/up_if_array.hpp deleted file mode 100644 index 7e62d106b4..0000000000 --- a/boost/smart_ptr/detail/up_if_array.hpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2014 Glen Joseph Fernandes - * glenfe at live dot com - * - * Distributed under the Boost Software License, - * Version 1.0. (See accompanying file LICENSE_1_0.txt - * or copy at http://boost.org/LICENSE_1_0.txt) - */ -#ifndef BOOST_SMART_PTR_DETAIL_UP_IF_ARRAY_HPP -#define BOOST_SMART_PTR_DETAIL_UP_IF_ARRAY_HPP - -#include <memory> - -namespace boost { - namespace detail { - template<class T> - struct up_if_array; - - template<class T> - struct up_if_array<T[]> { - typedef std::unique_ptr<T[]> type; - }; - } -} - -#endif diff --git a/boost/smart_ptr/detail/up_if_not_array.hpp b/boost/smart_ptr/detail/up_if_not_array.hpp deleted file mode 100644 index fd74f25318..0000000000 --- a/boost/smart_ptr/detail/up_if_not_array.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2014 Glen Joseph Fernandes - * glenfe at live dot com - * - * Distributed under the Boost Software License, - * Version 1.0. (See accompanying file LICENSE_1_0.txt - * or copy at http://boost.org/LICENSE_1_0.txt) - */ -#ifndef BOOST_SMART_PTR_DETAIL_UP_IF_NOT_ARRAY_HPP -#define BOOST_SMART_PTR_DETAIL_UP_IF_NOT_ARRAY_HPP - -#include <memory> - -namespace boost { - namespace detail { - template<class T> - struct up_if_not_array { - typedef std::unique_ptr<T> type; - }; - - template<class T> - struct up_if_not_array<T[]> { - }; - - template<class T, std::size_t N> - struct up_if_not_array<T[N]> { - }; - } -} - -#endif diff --git a/boost/smart_ptr/make_unique.hpp b/boost/smart_ptr/make_unique.hpp index 90402e2baa..d054e3dfe1 100644 --- a/boost/smart_ptr/make_unique.hpp +++ b/boost/smart_ptr/make_unique.hpp @@ -1,15 +1,105 @@ /* - * Copyright (c) 2014 Glen Joseph Fernandes - * glenfe at live dot com - * - * Distributed under the Boost Software License, - * Version 1.0. (See accompanying file LICENSE_1_0.txt - * or copy at http://boost.org/LICENSE_1_0.txt) - */ +(c) 2014-2015 Glen Joseph Fernandes +<glenjofe -at- gmail.com> + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #ifndef BOOST_SMART_PTR_MAKE_UNIQUE_HPP #define BOOST_SMART_PTR_MAKE_UNIQUE_HPP -#include <boost/smart_ptr/make_unique_array.hpp> -#include <boost/smart_ptr/make_unique_object.hpp> +#include <boost/config.hpp> +#include <memory> +#include <utility> + +namespace boost { +namespace detail { +template<class T> +struct up_if_object { + typedef std::unique_ptr<T> type; +}; + +template<class T> +struct up_if_object<T[]> { }; + +template<class T, std::size_t N> +struct up_if_object<T[N]> { }; + +template<class T> +struct up_if_array { }; + +template<class T> +struct up_if_array<T[]> { + typedef std::unique_ptr<T[]> type; +}; + +template<class T> +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; +}; + +template<class T> +struct up_element { }; + +template<class T> +struct up_element<T[]> { + typedef T type; +}; +} /* detail */ + +template<class T> +inline typename detail::up_if_object<T>::type make_unique() +{ + 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 + make_unique(Args&&... args) +{ + return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); +} +#endif + +template<class T> +inline typename detail::up_if_object<T>::type + make_unique(typename detail::up_remove_reference<T>::type&& value) +{ + return std::unique_ptr<T>(new T(std::move(value))); +} + +template<class T> +inline typename detail::up_if_object<T>::type make_unique_noinit() +{ + return std::unique_ptr<T>(new T); +} + +template<class T> +inline typename detail::up_if_array<T>::type make_unique(std::size_t n) +{ + return std::unique_ptr<T>(new + typename detail::up_element<T>::type[n]()); +} + +template<class T> +inline typename detail::up_if_array<T>::type + make_unique_noinit(std::size_t n) +{ + return std::unique_ptr<T>(new + typename detail::up_element<T>::type[n]); +} +} /* boost */ #endif diff --git a/boost/smart_ptr/make_unique_array.hpp b/boost/smart_ptr/make_unique_array.hpp deleted file mode 100644 index eb0528e63d..0000000000 --- a/boost/smart_ptr/make_unique_array.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2014 Glen Joseph Fernandes - * glenfe at live dot com - * - * Distributed under the Boost Software License, - * Version 1.0. (See accompanying file LICENSE_1_0.txt - * or copy at http://boost.org/LICENSE_1_0.txt) - */ -#ifndef BOOST_SMART_PTR_MAKE_UNIQUE_ARRAY_HPP -#define BOOST_SMART_PTR_MAKE_UNIQUE_ARRAY_HPP - -#include <boost/smart_ptr/detail/up_if_array.hpp> -#include <boost/smart_ptr/detail/array_traits.hpp> - -namespace boost { - template<class T> - inline typename boost::detail::up_if_array<T>::type - make_unique(std::size_t size) { - typedef typename boost::detail::array_inner<T>::type U; - return std::unique_ptr<T>(new U[size]()); - } - - template<class T> - inline typename boost::detail::up_if_array<T>::type - make_unique_noinit(std::size_t size) { - typedef typename boost::detail::array_inner<T>::type U; - return std::unique_ptr<T>(new U[size]); - } -} - -#endif diff --git a/boost/smart_ptr/make_unique_object.hpp b/boost/smart_ptr/make_unique_object.hpp deleted file mode 100644 index 9e6108a36a..0000000000 --- a/boost/smart_ptr/make_unique_object.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2014 Glen Joseph Fernandes - * glenfe at live dot com - * - * Distributed under the Boost Software License, - * Version 1.0. (See accompanying file LICENSE_1_0.txt - * or copy at http://boost.org/LICENSE_1_0.txt) - */ -#ifndef BOOST_SMART_PTR_MAKE_UNIQUE_OBJECT_HPP -#define BOOST_SMART_PTR_MAKE_UNIQUE_OBJECT_HPP - -#include <boost/config.hpp> -#include <boost/smart_ptr/detail/up_if_not_array.hpp> -#include <boost/type_traits/add_rvalue_reference.hpp> -#include <utility> - -namespace boost { - template<class T> - inline typename boost::detail::up_if_not_array<T>::type - make_unique() { - return std::unique_ptr<T>(new T()); - } - -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) - template<class T, class... Args> - inline typename boost::detail::up_if_not_array<T>::type - make_unique(Args&&... args) { - return std::unique_ptr<T>(new T(std::forward<Args>(args)...)); - } -#endif - - template<class T> - inline typename boost::detail::up_if_not_array<T>::type - make_unique(typename add_rvalue_reference<T>::type value) { - return std::unique_ptr<T>(new T(std::move(value))); - } - - template<class T> - inline typename boost::detail::up_if_not_array<T>::type - make_unique_noinit() { - return std::unique_ptr<T>(new T); - } -} - -#endif diff --git a/boost/smart_ptr/shared_ptr.hpp b/boost/smart_ptr/shared_ptr.hpp index 47bc33d517..bcefda8897 100644 --- a/boost/smart_ptr/shared_ptr.hpp +++ b/boost/smart_ptr/shared_ptr.hpp @@ -1065,7 +1065,7 @@ template< class T > struct hash; template< class T > std::size_t hash_value( boost::shared_ptr<T> const & p ) BOOST_NOEXCEPT { - return boost::hash< T* >()( p.get() ); + return boost::hash< typename boost::shared_ptr<T>::element_type* >()( p.get() ); } } // namespace boost |