Viskores  1.0
Placeholders.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_worklet_internal_Placeholders_h
19 #define viskores_worklet_internal_Placeholders_h
20 
21 #include <viskoresstd/integer_sequence.h>
22 
23 #include <type_traits>
24 
26 
27 namespace viskores
28 {
29 namespace placeholders
30 {
31 
32 //============================================================================
38 template <int ControlSignatureIndex>
39 struct Arg : viskores::exec::arg::BasicArg<ControlSignatureIndex>
40 {
41 };
42 
43 //============================================================================
47 template <typename>
48 struct FunctionSigArity;
49 template <typename R, typename... ArgTypes>
50 struct FunctionSigArity<R(ArgTypes...)>
51 {
52  static constexpr std::size_t value = sizeof...(ArgTypes);
53 };
54 
55 //============================================================================
56 template <int... Args>
57 auto DefaultSigGenerator(viskoresstd::integer_sequence<int, 0, Args...>) -> void (*)(Arg<Args>...);
58 
68 template <int Length>
69 struct DefaultExecSig
70 {
71  using seq = viskoresstd::make_integer_sequence<int, Length + 1>;
72  using type = typename std::remove_pointer<decltype(DefaultSigGenerator(seq{}))>::type;
73 };
74 template <>
75 struct DefaultExecSig<1>
76 {
77  using type = void(Arg<1>);
78 };
79 template <>
80 struct DefaultExecSig<2>
81 {
82  using type = void(Arg<1>, Arg<2>);
83 };
84 template <>
85 struct DefaultExecSig<3>
86 {
87  using type = void(Arg<1>, Arg<2>, Arg<3>);
88 };
89 template <>
90 struct DefaultExecSig<4>
91 {
92  using type = void(Arg<1>, Arg<2>, Arg<3>, Arg<4>);
93 };
94 
95 template <bool HasExecSig_, typename Sig_>
96 struct ExecSigQuery
97 {
98  static constexpr bool HasExecSig = HasExecSig_;
99  using Sig = Sig_;
100 };
101 
102 template <typename U, typename S = decltype(std::declval<typename U::ExecutionSignature>())>
103 static ExecSigQuery<true, typename U::ExecutionSignature> get_exec_sig(int);
104 
105 template <typename U>
106 static ExecSigQuery<false, void> get_exec_sig(...);
107 
108 //============================================================================
123 template <typename WorkletType>
124 struct GetExecSig
125 {
126  using cont_sig = typename WorkletType::ControlSignature;
127  using cont_sig_info = viskores::placeholders::FunctionSigArity<cont_sig>;
128 
129  using result = decltype(get_exec_sig<WorkletType>(0));
130  static constexpr bool has_explicit_exec_sig = result::HasExecSig;
131 
132  using ExecutionSignature = typename std::conditional<
133  has_explicit_exec_sig,
134  typename result::Sig,
135  typename viskores::placeholders::DefaultExecSig<cont_sig_info::value>::type>::type;
136 };
137 }
138 }
139 
140 #endif
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
BasicArg.h
viskores::exec::arg::BasicArg
The underlying tag for basic ExecutionSignature arguments.
Definition: BasicArg.h:40