ITK  6.0.0
Insight Toolkit
itkMakeUniqueForOverwrite.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18
19#ifndef itkMakeUniqueForOverwrite_h
20#define itkMakeUniqueForOverwrite_h
21
22#include <memory> // For unique_ptr.
23#include <type_traits> // For remove_extent_t, false_type, etc.
24
25namespace itk
26{
27
28// Namespace of implementation details (not part of the public ITK interface).
29namespace MakeUniqueForOverwriteImplDetail
30{
31
32// `is_unbounded_array` implementation for C++14/C++17. From C++20, `std::is_unbounded_array` is preferred.
33template <typename>
34struct is_unbounded_array : std::false_type
35{};
36
37template <typename T>
38struct is_unbounded_array<T[]> : std::true_type
39{};
40
41} // namespace MakeUniqueForOverwriteImplDetail
42
43
54 // Create a buffer that may be used to store the specified number of elements.
55 auto buffer = make_unique_for_overwrite<ElementType[]>(numberOfElements);
56 \endcode
57 *
58 */
59template <typename TUnboundedArray>
60auto
61make_unique_for_overwrite(const size_t numberOfElements)
62{
63 // The template argument must be something like `ElementType[]`, having an empty pair of square brackets.
65 "The specified template argument must be an unbounded array type!");
66 return std::unique_ptr<TUnboundedArray>(new std::remove_extent_t<TUnboundedArray>[numberOfElements]);
67}
68
69} // namespace itk
70
71#endif // itkMakeUniqueForOverwrite_h
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
auto make_unique_for_overwrite(const vcl_size_t numberOfElements)