ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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).
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
58template <typename TUnboundedArray>
59auto
60make_unique_for_overwrite(const size_t numberOfElements)
61{
62 // The template argument must be something like `ElementType[]`, having an empty pair of square brackets.
64 "The specified template argument must be an unbounded array type!");
65 return std::unique_ptr<TUnboundedArray>(new std::remove_extent_t<TUnboundedArray>[numberOfElements]);
66}
67
68} // namespace itk
69
70#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)