Google OR-Tools: ortools/base/dump_vars.h Source File
39#ifndef ORTOOLS_BASE_DUMP_VARS_H_
40#define ORTOOLS_BASE_DUMP_VARS_H_
49#include "absl/container/inlined_vector.h"
53#define DUMP_FOR_EACH_N0(F)
54#define DUMP_FOR_EACH_N1(F, a) F(a)
55#define DUMP_FOR_EACH_N2(F, a, ...) F(a) DUMP_FOR_EACH_N1(F, __VA_ARGS__)
56#define DUMP_FOR_EACH_N3(F, a, ...) F(a) DUMP_FOR_EACH_N2(F, __VA_ARGS__)
57#define DUMP_FOR_EACH_N4(F, a, ...) F(a) DUMP_FOR_EACH_N3(F, __VA_ARGS__)
58#define DUMP_FOR_EACH_N5(F, a, ...) F(a) DUMP_FOR_EACH_N4(F, __VA_ARGS__)
59#define DUMP_FOR_EACH_N6(F, a, ...) F(a) DUMP_FOR_EACH_N5(F, __VA_ARGS__)
60#define DUMP_FOR_EACH_N7(F, a, ...) F(a) DUMP_FOR_EACH_N6(F, __VA_ARGS__)
61#define DUMP_FOR_EACH_N8(F, a, ...) F(a) DUMP_FOR_EACH_N7(F, __VA_ARGS__)
62#define DUMP_FOR_EACH_N9(F, a, ...) F(a) DUMP_FOR_EACH_N8(F, __VA_ARGS__)
63#define DUMP_FOR_EACH_N10(F, a, ...) F(a) DUMP_FOR_EACH_N9(F, __VA_ARGS__)
64#define DUMP_FOR_EACH_N11(F, a, ...) F(a) DUMP_FOR_EACH_N10(F, __VA_ARGS__)
65#define DUMP_FOR_EACH_N12(F, a, ...) F(a) DUMP_FOR_EACH_N11(F, __VA_ARGS__)
67#define DUMP_CONCATENATE(x, y) x##y
68#define DUMP_FOR_EACH_(N, F, ...) \
69 DUMP_CONCATENATE(DUMP_FOR_EACH_N, N)(F __VA_OPT__(, __VA_ARGS__))
71#define DUMP_NARG(...) DUMP_NARG_(__VA_OPT__(__VA_ARGS__, ) DUMP_RSEQ_N())
72#define DUMP_NARG_(...) DUMP_ARG_N(__VA_ARGS__)
73#define DUMP_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, N, ...) N
74#define DUMP_RSEQ_N() 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
75#define DUMP_FOR_EACH(F, ...) \
76 DUMP_FOR_EACH_(DUMP_NARG(__VA_ARGS__), F __VA_OPT__(, __VA_ARGS__))
78#define DUMP_VARS(...) DUMP_VARS_WITH_BINDINGS((), __VA_ARGS__)
81#define DUMP_STRINGIZE(a) #a,
82#define DUMP_STRINGIFY(...) DUMP_FOR_EACH(DUMP_STRINGIZE, __VA_ARGS__)
85#define DUMP_IDENTITY(...) __VA_ARGS__
87#define DUMP_RM_PARENS(...) DUMP_IDENTITY __VA_ARGS__
89#define DUMP_GEN_ONE_BINDING(a) , &a = a
90#define DUMP_GEN_BINDING(binding) \
91 &DUMP_FOR_EACH(DUMP_GEN_ONE_BINDING, DUMP_RM_PARENS(binding))
93#define DUMP_VARS_WITH_BINDINGS(binding, ...) \
94 ::operations_research::base::internal_dump_vars::make_dump_vars<>( \
95 ::operations_research::base::internal_dump_vars::DumpNames{ \
96 DUMP_STRINGIFY(__VA_ARGS__)}, \
97 [DUMP_GEN_BINDING(binding)]( \
98 ::std::ostream& os, const ::std::string& field_sep, \
99 const ::std::string& kv_sep, \
100 const ::operations_research::base::internal_dump_vars::DumpNames& \
102 ::operations_research::base::internal_dump_vars::print_fields{ \
125std::ostream& operator<<(std::ostream& os, const ::std::vector<T>& vec) {
133std::ostream& operator<<(std::ostream& os, const ::std::optional<T>& opt) {
142template <typename T, typename U>
151using DumpNames = ::std::vector<::std::string>;
177 explicit Dump(const ::std::string&& field_sep, const ::std::string&& kv_sep,
179 : field_sep_(::std::move(field_sep)),
180 kv_sep_(::std::move(kv_sep)),
181 names_(::std::move(names)),
182 f_(::std::move(f)) {}
192 return Dump<F>(::std::string{field_sep_}, ::std::string{kv_sep_},
201 Dump& sep(::std::string&& field_sep, ::std::string&& kv_sep) {
202 field_sep_ = ::std::move(field_sep);
207 friend ::std::ostream& operator<<(::std::ostream& os, const Dump& dump) {
213 void print_fields_(::std::ostream& os) const {
Definition dump_vars.h:175
::std::string str() const
Definition dump_vars.h:184
Dump< F > as(N &&... names) const
Definition dump_vars.h:191
friend::std::ostream & operator<<(::std::ostream &os, const Dump &dump)
Definition dump_vars.h:207
Dump & sep(::std::string &&field_sep, ::std::string &&kv_sep)
Definition dump_vars.h:201
Dump & sep(::std::string &&field_sep)
Definition dump_vars.h:196
Dump(const ::std::string &&field_sep, const ::std::string &&kv_sep, DumpNames &&names, F f)
Definition dump_vars.h:177
Definition dump_vars.h:111
Dump< F > make_dump_vars(DumpNames &&names, F f)
Definition dump_vars.h:224
std::ostream & operator<<(std::ostream &os, const ::absl::InlinedVector< T, 8 > &vec)
Definition dump_vars.h:115
::std::vector<::std::string > DumpNames
Definition dump_vars.h:151
Definition dump_vars.h:110
Definition dump_vars.h:153
std::ostream & os
Definition dump_vars.h:167
::std::size_t n
Definition dump_vars.h:171
const DumpNames & names
Definition dump_vars.h:170
const ::std::string & kv_sep
Definition dump_vars.h:169
const ::std::string & field_sep
Definition dump_vars.h:168
void operator()(const T1 &t1, const T2 &t2, const Ts &... ts)
Definition dump_vars.h:162
void operator()()
Definition dump_vars.h:154
void operator()(const T &t)
Definition dump_vars.h:157