Skip to content
Snippets Groups Projects
Commit df9583f7 authored by Ansgar Burchardt's avatar Ansgar Burchardt
Browse files

[!686] deprecate `make_unique` fallback implementation

Merge branch 'deprecate-make_unique-fallback' into 'master'

ref:core/dune-common Closes: [#97]

See merge request [!686]

  [#97]: gitlab.dune-project.org/NoneNone/issues/97
  [!686]: gitlab.dune-project.org/core/dune-common/merge_requests/686


Closes #97
parents 4970a420 754581d6
Branches
Tags
1 merge request!686deprecate `make_unique` fallback implementation
Pipeline #19227 passed
......@@ -523,12 +523,6 @@ check_include_file_cxx(
DUNE_HAVE_HEADER_EXPERIMENTAL_TYPE_TRAITS
)
check_cxx_symbol_exists(
"std::make_unique<int>"
memory
DUNE_HAVE_CXX_MAKE_UNIQUE
)
check_cxx_symbol_exists(
"std::move<std::bool_constant<true>>"
"utility;type_traits"
......
......@@ -41,9 +41,6 @@
/* does the standard library provide <experimental/type_traits> ? */
#cmakedefine DUNE_HAVE_HEADER_EXPERIMENTAL_TYPE_TRAITS 1
/* does the standard library provide make_unique() ? */
#cmakedefine DUNE_HAVE_CXX_MAKE_UNIQUE 1
/* does the standard library provide bool_constant ? */
#cmakedefine DUNE_HAVE_CXX_BOOL_CONSTANT 1
......
......@@ -3,8 +3,9 @@
#ifndef DUNE_COMMON_STD_MEMORY_HH
#define DUNE_COMMON_STD_MEMORY_HH
#warning dune/common/std/memory.hh is deprecated; use std::make_unique from <memory> instead
#include <memory>
#include <utility>
namespace Dune
{
......@@ -12,95 +13,8 @@ namespace Dune
namespace Std
{
#if DUNE_HAVE_CXX_MAKE_UNIQUE
using std::make_unique;
#else
#ifndef DOXYGEN
namespace Impl {
// Helper struct to distinguish non-array, unknown bound
// array, and known bound array types using SFINAE
// following proposal N3656 by Stephan T. Lavavej.
template<class T>
struct MakeUniqueHelper
{
typedef std::unique_ptr<T> NonArrayUniquePtr;
};
template<class T>
struct MakeUniqueHelper<T[]>
{
typedef std::unique_ptr<T[]> UnknownBoundArrayUniquePtr;
typedef T RawType;
};
template<class T, size_t N>
struct MakeUniqueHelper<T[N]>
{
typedef void KnownBoundArrayUniquePtr;
};
}
#endif // DOXYGEN
/** \brief Implementation of std::make_unique to be introduced in C++14
*
* \tparam T Nonarray type of object to be constructed
* \tparam ...Args Parameter types for constructor of T
*
* \param args Arguments to be passed to constructor of T
*
* This fallback implementation using perfect forwarding
* as proposed by Herb Sutter in http://herbsutter.com/gotw/_102/
*
* \ingroup CxxUtilities
*/
template<typename T, typename... Args>
typename Impl::MakeUniqueHelper<T>::NonArrayUniquePtr
make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
/** \brief Implementation of std::make_unique to be introduced in C++14
*
* \tparam T Array type of unknown bound
*
* \param n Size of array to allocate
*
* \ingroup CxxUtilities
*/
template<typename T>
typename Impl::MakeUniqueHelper<T>::UnknownBoundArrayUniquePtr
make_unique(size_t n)
{
return std::unique_ptr<T>(new typename Impl::MakeUniqueHelper<T>::RawType[n]());
}
/** \brief Implementation of std::make_unique to be introduced in C++14
*
* \tparam T Array type of known bound
* \tparam Args Dummy arguments
*
* This is deleted, since, according to the standard this should not
* participate in overload resolution
*
* \param args Dummy arguments
*
* \ingroup CxxUtilities
*/
template<typename T, typename ...Args>
typename Impl::MakeUniqueHelper<T>::KnownBoundArrayUniquePtr
make_unique(Args&&... args) = delete;
#endif // DUNE_HAVE_CXX_MAKE_UNIQUE
} // namespace Std
} // namespace Dune
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment