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.
stl.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/** \file mpl/stl.hpp
26 * \headerfile mpl/stl.hpp "timemory/mpl/stl.hpp"
27 * Provides operators on common STL structures such as <<, +=, -=, *=, /=, +, -, *, /
28 *
29 */
30
31#pragma once
32
33#include "timemory/math/stl.hpp"
35
36#include <array>
37#include <ostream>
38#include <tuple>
39#include <utility>
40#include <vector>
41
42namespace tim
43{
44inline namespace stl
45{
46/// \namespace tim::stl::ostream
47/// \brief the namespace provides overloads to output complex data types w/ streams
48namespace ostream
49{
50template <template <typename...> class Tuple, typename... Types, size_t... Idx>
51void
52tuple_printer(const Tuple<Types...>& obj, std::ostream& os, index_sequence<Idx...>);
53
54//--------------------------------------------------------------------------------------//
55//
56// operator <<
57//
58//--------------------------------------------------------------------------------------//
59
60template <typename T, typename U>
61std::ostream&
62operator<<(std::ostream&, const std::pair<T, U>&);
63
64template <typename... Types>
65std::ostream&
66operator<<(std::ostream&, const std::tuple<Types...>&);
67
68template <typename Tp, typename... Extra>
69std::ostream&
70operator<<(std::ostream&, const std::vector<Tp, Extra...>&);
71
72template <typename Tp, size_t N>
73std::ostream&
74operator<<(std::ostream&, const std::array<Tp, N>&);
75
76//--------------------------------------------------------------------------------------//
77
78template <typename T, typename U>
79std::ostream&
80operator<<(std::ostream& os, const std::pair<T, U>& p)
81{
82 os << "(" << p.first << "," << p.second << ")";
83 return os;
84}
85
86template <typename... Types>
87std::ostream&
88operator<<(std::ostream& os, const std::tuple<Types...>& p)
89{
90 constexpr size_t N = sizeof...(Types);
92 return os;
93}
94
95template <typename Tp, typename... ExtraT>
96std::ostream&
97operator<<(std::ostream& os, const std::vector<Tp, ExtraT...>& p)
98{
99 os << "(";
100 for(size_t i = 0; i < p.size(); ++i)
101 os << p.at(i) << ((i + 1 < p.size()) ? "," : "");
102 os << ")";
103 return os;
104}
105
106template <typename Tp, size_t N>
107std::ostream&
108operator<<(std::ostream& os, const std::array<Tp, N>& p)
109{
110 os << "(";
111 for(size_t i = 0; i < p.size(); ++i)
112 os << p.at(i) << ((i + 1 < p.size()) ? "," : "");
113 os << ")";
114 return os;
115}
116
117template <template <typename...> class Tuple, typename... Types, size_t... Idx>
118void
119tuple_printer(const Tuple<Types...>& obj, std::ostream& os, index_sequence<Idx...>)
120{
121 using namespace ::tim::stl::ostream;
122 constexpr size_t N = sizeof...(Types);
123
124 if(N > 0)
125 os << "(";
126 char delim[N];
127 TIMEMORY_FOLD_EXPRESSION(delim[Idx] = ',');
128 delim[N - 1] = '\0';
129 TIMEMORY_FOLD_EXPRESSION(os << std::get<Idx>(obj) << delim[Idx]);
130 if(N > 0)
131 os << ")";
132}
133
134} // namespace ostream
135} // namespace stl
136} // namespace tim
the namespace provides overloads to output complex data types w/ streams
void tuple_printer(const Tuple< Types... > &obj, std::ostream &os, index_sequence< Idx... >)
Definition: stl.hpp:119
std::ostream & operator<<(std::ostream &, const std::pair< T, U > &)
Definition: stl.hpp:80
Definition: kokkosp.cpp:39
std::make_integer_sequence< size_t, Num > make_index_sequence
Alias template make_index_sequence.
Definition: types.hpp:182
const std::string std::ostream * os
std::integer_sequence< size_t, Idx... > index_sequence
Alias template index_sequence.
Definition: types.hpp:178
#define TIMEMORY_FOLD_EXPRESSION(...)
Definition: types.hpp:56