ITK
5.3.0
Insight Toolkit
ITK
Modules
Core
Common
include
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
24
#if __cplusplus < 202002L
25
26
# include <type_traits>
// For remove_extent_t, false_type, etc.
27
28
namespace
itk
29
{
30
31
// Namespace of implementation details (not part of the public ITK interface).
32
namespace
MakeUniqueForOverwriteImplDetail
33
{
34
35
// `is_unbounded_array` implementation for C++14/C++17. From C++20, `std::is_unbounded_array` is preferred.
36
template
<
typename
>
37
struct
is_unbounded_array
: std::false_type
38
{};
39
40
template
<
typename
T>
41
struct
is_unbounded_array
<T[]> : std::true_type
42
{};
43
44
}
// namespace MakeUniqueForOverwriteImplDetail
45
46
56
// Create a buffer that may be used to store the specified number of elements.
57
auto
buffer = make_unique_for_overwrite<ElementType[]>(numberOfElements);
58
\endcode
59
*
60
*/
61
template
<
typename
TUnboundedArray>
62
auto
63
make_unique_for_overwrite
(
const
size_t
numberOfElements)
64
{
65
// The template argument must be something like `ElementType[]`, having an empty pair of square brackets.
66
static_assert(
MakeUniqueForOverwriteImplDetail::is_unbounded_array<TUnboundedArray>::value
,
67
"The specified template argument must be an unbounded array type!"
);
68
return
std::unique_ptr<TUnboundedArray>(
new
std::remove_extent_t<TUnboundedArray>[numberOfElements]);
69
}
70
71
}
// namespace itk
72
73
#else
74
75
namespace
itk
76
{
77
using ::std::make_unique_for_overwrite
;
78
}
79
80
#endif
81
82
#endif // itkMakeUniqueForOverwrite_h
itk::MakeUniqueForOverwriteImplDetail::is_unbounded_array
Definition:
itkMakeUniqueForOverwrite.h:37
itk::make_unique_for_overwrite
auto make_unique_for_overwrite(const vcl_size_t numberOfElements)
Definition:
itkMakeUniqueForOverwrite.h:63
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition:
itkAnnulusOperator.h:24
Generated on
unknown
for ITK by
1.8.16