1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkMeta.h
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 #ifndef vtkMeta_h
17 #define vtkMeta_h
18 
19 #include <type_traits>
20 #include <utility>
21 
22 /**
23  * @file vtkMeta.h
24  * This file contains a variety of metaprogramming constructs for working
25  * with vtk types.
26  */
27 
28 // Forward decs for StripPointers:
29 template <typename ArrayType>
30 class vtkNew;
31 template <typename ArrayType>
32 class vtkSmartPointer;
33 template <typename ArrayType>
34 class vtkWeakPointer;
35 
36 namespace vtk
37 {
38 namespace detail
39 {
40 
41 //------------------------------------------------------------------------------
42 // Strip vtkNew, vtkSmartPointer, etc from a type.
43 template <typename T>
44 struct StripPointers
45 {
46   using type = T;
47 };
48 
49 template <typename T>
50 struct StripPointers<T*>
51 {
52   using type = T;
53 };
54 
55 template <typename ArrayType>
56 struct StripPointers<vtkNew<ArrayType>>
57 {
58   using type = ArrayType;
59 };
60 
61 template <typename ArrayType>
62 struct StripPointers<vtkSmartPointer<ArrayType>>
63 {
64   using type = ArrayType;
65 };
66 
67 template <typename ArrayType>
68 struct StripPointers<vtkWeakPointer<ArrayType>>
69 {
70   using type = ArrayType;
71 };
72 
73 //------------------------------------------------------------------------------
74 // Test if a type is defined (true) or just forward declared (false).
75 template <typename T>
76 struct IsComplete
77 {
78 private:
79   // Can't take the sizeof an incomplete class.
80   template <typename U, std::size_t = sizeof(U)>
81   static std::true_type impl(U*);
82   static std::false_type impl(...);
83   using bool_constant = decltype(impl(std::declval<T*>()));
84 
85 public:
86   static constexpr bool value = bool_constant::value;
87 };
88 
89 }
90 } // end namespace vtk::detail
91 
92 #endif // vtkMeta_h
93 
94 // VTK-HeaderTest-Exclude: vtkMeta.h
95