VTK-m  2.2
Placeholders.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_worklet_internal_Placeholders_h
11 #define vtk_m_worklet_internal_Placeholders_h
12 
13 #include <vtkmstd/integer_sequence.h>
14 
15 #include <type_traits>
16 
17 #include <vtkm/exec/arg/BasicArg.h>
18 
19 namespace vtkm
20 {
21 namespace placeholders
22 {
23 
24 //============================================================================
30 template <int ControlSignatureIndex>
31 struct Arg : vtkm::exec::arg::BasicArg<ControlSignatureIndex>
32 {
33 };
34 
35 //============================================================================
39 template <typename>
40 struct FunctionSigArity;
41 template <typename R, typename... ArgTypes>
42 struct FunctionSigArity<R(ArgTypes...)>
43 {
44  static constexpr std::size_t value = sizeof...(ArgTypes);
45 };
46 
47 //============================================================================
48 template <int... Args>
49 auto DefaultSigGenerator(vtkmstd::integer_sequence<int, 0, Args...>) -> void (*)(Arg<Args>...);
50 
60 template <int Length>
61 struct DefaultExecSig
62 {
63  using seq = vtkmstd::make_integer_sequence<int, Length + 1>;
64  using type = typename std::remove_pointer<decltype(DefaultSigGenerator(seq{}))>::type;
65 };
66 template <>
67 struct DefaultExecSig<1>
68 {
69  using type = void(Arg<1>);
70 };
71 template <>
72 struct DefaultExecSig<2>
73 {
74  using type = void(Arg<1>, Arg<2>);
75 };
76 template <>
77 struct DefaultExecSig<3>
78 {
79  using type = void(Arg<1>, Arg<2>, Arg<3>);
80 };
81 template <>
82 struct DefaultExecSig<4>
83 {
84  using type = void(Arg<1>, Arg<2>, Arg<3>, Arg<4>);
85 };
86 
87 template <bool HasExecSig_, typename Sig_>
88 struct ExecSigQuery
89 {
90  static constexpr bool HasExecSig = HasExecSig_;
91  using Sig = Sig_;
92 };
93 
94 template <typename U, typename S = decltype(std::declval<typename U::ExecutionSignature>())>
95 static ExecSigQuery<true, typename U::ExecutionSignature> get_exec_sig(int);
96 
97 template <typename U>
98 static ExecSigQuery<false, void> get_exec_sig(...);
99 
100 //============================================================================
115 template <typename WorkletType>
116 struct GetExecSig
117 {
118  using cont_sig = typename WorkletType::ControlSignature;
119  using cont_sig_info = vtkm::placeholders::FunctionSigArity<cont_sig>;
120 
121  using result = decltype(get_exec_sig<WorkletType>(0));
122  static constexpr bool has_explicit_exec_sig = result::HasExecSig;
123 
124  using ExecutionSignature = typename std::conditional<
125  has_explicit_exec_sig,
126  typename result::Sig,
127  typename vtkm::placeholders::DefaultExecSig<cont_sig_info::value>::type>::type;
128 };
129 }
130 }
131 
132 #endif
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::exec::arg::BasicArg
The underlying tag for basic ExecutionSignature arguments.
Definition: BasicArg.h:32
BasicArg.h