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.
assemble.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/assemble.hpp
27 * \brief Definition for various functions for assemble in operations
28 */
29
30#pragma once
31
36
37#include <type_traits>
38
39namespace tim
40{
41namespace operation
42{
43//
44//--------------------------------------------------------------------------------------//
45//
46//
47//
48//--------------------------------------------------------------------------------------//
49//
50template <typename Tp>
52
53template <template <typename...> class CompT, typename... C>
54struct fold_assemble<CompT<C...>>
55{
56public:
58
59 template <typename Up, typename Arg, typename... Args>
60 fold_assemble(bool& b, Up& obj, Arg&& arg, Args&&...)
61 {
62 if(!b)
63 sfinae(b, obj, 0, std::forward<Arg>(arg));
64 }
65
66private:
67 // satisfies mpl condition and accepts arguments
68 template <typename Up, typename Arg>
69 auto sfinae(bool& b, Up& obj, int, Arg&& arg)
70 -> decltype(obj.assemble(arg.template get_component<C>()...), void())
71 {
72 b = obj.assemble(arg.template get_component<C>()...);
73 }
74
75 template <typename Up, typename Arg>
76 void sfinae(bool&, Up&, long, Arg&&)
77 {}
78};
79//
80//--------------------------------------------------------------------------------------//
81//
82//
83//
84//--------------------------------------------------------------------------------------//
85//
86template <typename Tp>
88{
89 using type = Tp;
90
92
93private:
94 using derived_tuple_t = typename trait::derivation_types<Tp>::type;
95 template <size_t Idx>
96 using derived_t = typename std::tuple_element<Idx, derived_tuple_t>::type;
97
98public:
99 template <typename... Args>
100 explicit assemble(type& obj, Args&&... args);
101
102 template <typename Arg, size_t N = std::tuple_size<derived_tuple_t>::value,
103 std::enable_if_t<(N > 0)> = 0>
104 explicit assemble(type& obj, Arg&& arg)
105 {
106 bool b = false;
107 sfinae(b, obj, make_index_sequence<N>{}, std::forward<Arg>(arg));
108 if(!b)
109 sfinae(obj, 0, 0, std::forward<Arg>(arg));
110 }
111
112 template <template <typename...> class BundleT, typename... Args>
113 explicit assemble(type& obj, BundleT<Args...>& arg)
114 {
115 bool b = false;
116 constexpr auto N = std::tuple_size<derived_tuple_t>::value;
117 sfinae(b, obj, make_index_sequence<N>{}, arg);
118 if(!b)
119 sfinae(obj, 0, 0, arg);
120 }
121
122private:
123 // satisfies mpl condition and accepts arguments
124 template <typename Up, size_t... Idx, typename... Args>
125 auto sfinae(bool& b, Up& obj, index_sequence<Idx...>, Args&&... args)
126 {
128 fold_assemble<derived_t<Idx>>(b, obj, std::forward<Args>(args)...));
129 }
130
131private:
132 // satisfies mpl condition and accepts arguments
133 template <typename Up, typename... Args>
134 auto sfinae(Up& obj, int, int, Args&&... args)
135 -> decltype(obj.assemble(std::forward<Args>(args)...), void())
136 {
137 obj.assemble(std::forward<Args>(args)...);
138 }
139
140 // satisfies mpl condition but does not accept arguments
141 template <typename Up, typename... Args>
142 auto sfinae(Up& obj, int, long, Args&&...) -> decltype(obj.assemble(), void())
143 {
144 obj.assemble();
145 }
146
147 // no member function or does not satisfy mpl condition
148 template <typename Up, typename... Args>
149 void sfinae(Up&, long, long, Args&&...)
150 {
151 // SFINAE_WARNING(type);
152 }
153};
154//
155//--------------------------------------------------------------------------------------//
156//
157template <typename Tp>
158template <typename... Args>
159assemble<Tp>::assemble(type& obj, Args&&... args)
160{
161 sfinae(obj, 0, 0, std::forward<Args>(args)...);
162}
163//
164//--------------------------------------------------------------------------------------//
165//
166} // namespace operation
167} // namespace tim
typename std::enable_if< B, T >::type enable_if_t
Definition: types.hpp:58
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.
assemble(type &obj, Arg &&arg)
Definition: assemble.hpp:104
assemble(type &obj, BundleT< Args... > &arg)
Definition: assemble.hpp:113
assemble(type &obj, Args &&... args)
Definition: assemble.hpp:159
(assemble) private typename std::tuple_element< Idx, derived_tuple_t >::type derived_t
Definition: assemble.hpp:96
TIMEMORY_DELETED_OBJECT(fold_assemble) 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