timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
derive.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2020, The Regents of the University of California,
4// through Lawrence Berkeley National Laboratory (subject to receipt of any
5// required approvals from the U.S. Dept. of Energy). All rights reserved.
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in all
15// copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23// SOFTWARE.
24
25/**
26 * \file timemory/operations/types/derive.hpp
27 * \brief Definition for various functions for derive in operations
28 */
29
30#pragma once
31
36
37namespace tim
38{
39namespace operation
40{
41//
42//--------------------------------------------------------------------------------------//
43//
44//
45//
46//--------------------------------------------------------------------------------------//
47//
48template <typename Tp>
50
51template <template <typename...> class CompT, typename... C>
52struct fold_derive<CompT<C...>>
53{
54public:
56
57 template <typename Up, typename Arg, typename... Args>
58 fold_derive(bool& b, Up& obj, Arg&& arg, Args&&...)
59 {
60 if(!b)
61 sfinae(b, obj, 0, std::forward<Arg>(arg));
62 }
63
64private:
65 // satisfies mpl condition and accepts arguments
66 template <typename Up, typename Arg>
67 auto sfinae(bool& b, Up& obj, int, Arg&& arg)
68 -> decltype(obj.derive(arg.template get_component<C>()...), void())
69 {
70 b = obj.derive(arg.template get_component<C>()...);
71 }
72
73 template <typename Up, typename Arg>
74 void sfinae(bool&, Up&, long, Arg&&)
75 {}
76};
77//
78//--------------------------------------------------------------------------------------//
79//
80//
81//
82//--------------------------------------------------------------------------------------//
83//
84template <typename Tp>
85struct derive
86{
87 using type = Tp;
88
90
91private:
92 using derived_tuple_t = typename trait::derivation_types<Tp>::type;
93 template <size_t Idx>
94 using derived_t = typename std::tuple_element<Idx, derived_tuple_t>::type;
95
96public:
97 template <typename... Args>
98 explicit derive(type& obj, Args&&... args);
99
100 template <typename Arg, size_t N = std::tuple_size<derived_tuple_t>::value,
101 std::enable_if_t<N != 0> = 0>
102 explicit derive(type& obj, Arg&& arg)
103 {
104 bool b = false;
105 sfinae(b, obj, make_index_sequence<N>{}, std::forward<Arg>(arg));
106 if(!b)
107 sfinae(obj, 0, 0, std::forward<Arg>(arg));
108 }
109
110 template <template <typename...> class BundleT, typename... Args>
111 explicit derive(type& obj, BundleT<Args...>& arg)
112 {
113 bool b = false;
114 constexpr auto N = std::tuple_size<derived_tuple_t>::value;
115 sfinae(b, obj, make_index_sequence<N>{}, arg);
116 if(!b)
117 sfinae(obj, 0, 0, arg);
118 }
119
120private:
121 // satisfies mpl condition and accepts arguments
122 template <typename Up, size_t... Idx, typename... Args>
123 auto sfinae(bool& b, Up& obj, index_sequence<Idx...>, Args&&... args)
124 {
126 fold_derive<derived_t<Idx>>(b, obj, std::forward<Args>(args)...));
127 }
128
129private:
130 // satisfies mpl condition and accepts arguments
131 template <typename Up, typename... Args>
132 auto sfinae(Up& obj, int, int, Args&&... args)
133 -> decltype(obj.derive(std::forward<Args>(args)...), void())
134 {
135 obj.derive(std::forward<Args>(args)...);
136 }
137
138 // satisfies mpl condition but does not accept arguments
139 template <typename Up, typename... Args>
140 auto sfinae(Up& obj, int, long, Args&&...) -> decltype(obj.derive(), void())
141 {
142 obj.derive();
143 }
144
145 // no member function or does not satisfy mpl condition
146 template <typename Up, typename... Args>
147 void sfinae(Up&, long, long, Args&&...)
148 {
149 // SFINAE_WARNING(type);
150 }
151};
152//
153//--------------------------------------------------------------------------------------//
154//
155template <typename Tp>
156template <typename... Args>
157derive<Tp>::derive(type& obj, Args&&... args)
158{
159 sfinae(obj, 0, 0, std::forward<Args>(args)...);
160}
161//
162//--------------------------------------------------------------------------------------//
163//
164} // namespace operation
165} // namespace tim
Definition: kokkosp.cpp:39
std::make_integer_sequence< size_t, Num > make_index_sequence
Alias template make_index_sequence.
Definition: types.hpp:182
std::integer_sequence< size_t, Idx... > index_sequence
Alias template index_sequence.
Definition: types.hpp:178
The declaration for the types for operations without definitions.
Include the macros for operations.
Declare the operations types.
derive(type &obj, Arg &&arg)
Definition: derive.hpp:102
(derive) private typename std::tuple_element< Idx, derived_tuple_t >::type derived_t
Definition: derive.hpp:94
derive(type &obj, BundleT< Args... > &arg)
Definition: derive.hpp:111
derive(type &obj, Args &&... args)
Definition: derive.hpp:157
TIMEMORY_DELETED_OBJECT(fold_derive) template< typename Up
std::tuple< type_list<> > type
#define TIMEMORY_DELETED_OBJECT(NAME)
Definition: types.hpp:96
#define TIMEMORY_FOLD_EXPRESSION(...)
Definition: types.hpp:56
typename typename typename
Definition: types.hpp:226