aboutsummaryrefslogtreecommitdiff
path: root/support/ToolchainSupport.h
diff options
context:
space:
mode:
Diffstat (limited to 'support/ToolchainSupport.h')
-rw-r--r--support/ToolchainSupport.h26
1 files changed, 23 insertions, 3 deletions
diff --git a/support/ToolchainSupport.h b/support/ToolchainSupport.h
index 56cbce8cc4..cb156f39c7 100644
--- a/support/ToolchainSupport.h
+++ b/support/ToolchainSupport.h
@@ -339,24 +339,37 @@ inline bool isfinite(half_float::half value)
namespace cpp14
{
/** make_unique is missing in CPP11. Re-implement it according to the standard proposal. */
+
+/**<Template for single object */
template <class T>
struct _Unique_if
{
- typedef std::unique_ptr<T> _Single_object;
+ typedef std::unique_ptr<T> _Single_object; /**< Single object type */
};
+/** Template for array */
template <class T>
struct _Unique_if<T[]>
{
- typedef std::unique_ptr<T[]> _Unknown_bound;
+ typedef std::unique_ptr<T[]> _Unknown_bound; /**< Array type */
};
+/** Template for array with known bounds (to throw an error).
+ *
+ * @note this is intended to never be hit.
+ */
template <class T, size_t N>
struct _Unique_if<T[N]>
{
- typedef void _Known_bound;
+ typedef void _Known_bound; /**< Should never be used */
};
+/** Construct a single object and return a unique pointer to it.
+ *
+ * @param[in] args Constructor arguments.
+ *
+ * @return a unique pointer to the new object.
+ */
template <class T, class... Args>
typename _Unique_if<T>::_Single_object
make_unique(Args &&... args)
@@ -364,6 +377,12 @@ make_unique(Args &&... args)
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
+/** Construct an array of objects and return a unique pointer to it.
+ *
+ * @param[in] n Array size
+ *
+ * @return a unique pointer to the new array.
+ */
template <class T>
typename _Unique_if<T>::_Unknown_bound
make_unique(size_t n)
@@ -372,6 +391,7 @@ make_unique(size_t n)
return std::unique_ptr<T>(new U[n]());
}
+/** It is invalid to attempt to make_unique an array with known bounds. */
template <class T, class... Args>
typename _Unique_if<T>::_Known_bound
make_unique(Args &&...) = delete;