Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
dump_vars.h File Reference
#include <optional>
#include <ostream>
#include <sstream>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
#include "absl/container/inlined_vector.h"

Go to the source code of this file.

Classes

struct  operations_research::base::internal_dump_vars::print_fields
 
class  operations_research::base::internal_dump_vars::Dump< F >
 

Namespaces

namespace  operations_research
 In SWIG mode, we don't want anything besides these top-level includes.
 
namespace  operations_research::base
 
namespace  operations_research::base::internal_dump_vars
 

Macros

#define DUMP_FOR_EACH_N0(F)
 
#define DUMP_FOR_EACH_N1(F, a)
 
#define DUMP_FOR_EACH_N2(F, a, ...)
 
#define DUMP_FOR_EACH_N3(F, a, ...)
 
#define DUMP_FOR_EACH_N4(F, a, ...)
 
#define DUMP_FOR_EACH_N5(F, a, ...)
 
#define DUMP_FOR_EACH_N6(F, a, ...)
 
#define DUMP_FOR_EACH_N7(F, a, ...)
 
#define DUMP_FOR_EACH_N8(F, a, ...)
 
#define DUMP_FOR_EACH_N9(F, a, ...)
 
#define DUMP_FOR_EACH_N10(F, a, ...)
 
#define DUMP_FOR_EACH_N11(F, a, ...)
 
#define DUMP_CONCATENATE(x, y)
 
#define DUMP_FOR_EACH_(N, F, ...)
 
#define DUMP_NARG(...)
 
#define DUMP_NARG_(...)
 
#define DUMP_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, N, ...)
 
#define DUMP_RSEQ_N()
 
#define DUMP_FOR_EACH(F, ...)
 
#define DUMP_VARS(...)
 
#define DUMP_STRINGIZE(a)
 
#define DUMP_STRINGIFY(...)
 
#define DUMP_IDENTITY(...)
 Returns the arguments.
 
#define DUMP_RM_PARENS(...)
 Removes parenthesis. Requires argument enclosed in parenthesis.
 
#define DUMP_GEN_ONE_BINDING(a)
 
#define DUMP_GEN_BINDING(binding)
 
#define DUMP_VARS_WITH_BINDINGS(binding, ...)
 

Typedefs

using operations_research::base::internal_dump_vars::DumpNames = ::std::vector<::std::string>
 

Functions

template<typename T >
std::ostream & operations_research::base::internal_dump_vars::operator<< (std::ostream &os, const ::absl::InlinedVector< T, 8 > &vec)
 needed by routing
 
template<typename T >
std::ostream & operations_research::base::internal_dump_vars::operator<< (std::ostream &os, const ::std::vector< T > &vec)
 needed by algorithms tests
 
template<typename T >
std::ostream & operations_research::base::internal_dump_vars::operator<< (std::ostream &os, const ::std::optional< T > &opt)
 
template<class F >
Dump< F > operations_research::base::internal_dump_vars::make_dump_vars (DumpNames &&names, F f)
 

Macro Definition Documentation

◆ DUMP_ARG_N

#define DUMP_ARG_N ( _1,
_2,
_3,
_4,
_5,
_6,
_7,
_8,
_9,
_10,
_11,
N,
... )
Value:
N

Definition at line 72 of file dump_vars.h.

◆ DUMP_CONCATENATE

#define DUMP_CONCATENATE ( x,
y )
Value:
x##y
IntegerValue y
const Variable x
Definition qp_tests.cc:127

Definition at line 66 of file dump_vars.h.

◆ DUMP_FOR_EACH

#define DUMP_FOR_EACH ( F,
... )
Value:
DUMP_FOR_EACH_(DUMP_NARG(__VA_ARGS__), F __VA_OPT__(, __VA_ARGS__))
#define DUMP_NARG(...)
Definition dump_vars.h:70
#define DUMP_FOR_EACH_(N, F,...)
Definition dump_vars.h:67

Definition at line 74 of file dump_vars.h.

◆ DUMP_FOR_EACH_

#define DUMP_FOR_EACH_ ( N,
F,
... )
Value:
DUMP_CONCATENATE(DUMP_FOR_EACH_N, N)(F __VA_OPT__(, __VA_ARGS__))
#define DUMP_CONCATENATE(x, y)
Definition dump_vars.h:66

Definition at line 67 of file dump_vars.h.

◆ DUMP_FOR_EACH_N0

#define DUMP_FOR_EACH_N0 ( F)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. DUMP_VARS() is a convenience macro for writing objects to text logs. It prints all of its arguments as key-value pairs.

Example: int foo = 42; vector<int> bar = {1, 2, 3}; ///< Prints: foo = 42, bar.size() = 3 LOG(INFO) << DUMP_VARS(foo, bar.size());

DUMP_VARS() produces high quality human-readable output for most types: builtin types, strings, anything with operator<<.

====[ Limitations ]====

DUMP_VARS() accepts at most 8 arguments.

Structured bindings require an extra step to make DUMP_VARS print them. They need to be listed as first argument of DUMP_VARS_WITH_BINDINGS:

for (const auto& [x, y, z] : Foo()) { ///< Would not compile: ///< LOG(INFO) << DUMP_VARS(x, *y, f(z), other_var); LOG(INFO) << DUMP_VARS_WITH_BINDINGS((x, y, z), x, *y, f(z), other_var); }

Definition at line 53 of file dump_vars.h.

◆ DUMP_FOR_EACH_N1

#define DUMP_FOR_EACH_N1 ( F,
a )
Value:
F(a)
int64_t a
Definition table.cc:44

Definition at line 54 of file dump_vars.h.

◆ DUMP_FOR_EACH_N10

#define DUMP_FOR_EACH_N10 ( F,
a,
... )
Value:
F(a) DUMP_FOR_EACH_N9(F, __VA_ARGS__)
#define DUMP_FOR_EACH_N9(F, a,...)
Definition dump_vars.h:62

Definition at line 63 of file dump_vars.h.

◆ DUMP_FOR_EACH_N11

#define DUMP_FOR_EACH_N11 ( F,
a,
... )
Value:
F(a) DUMP_FOR_EACH_N10(F, __VA_ARGS__)
#define DUMP_FOR_EACH_N10(F, a,...)
Definition dump_vars.h:63

Definition at line 64 of file dump_vars.h.

◆ DUMP_FOR_EACH_N2

#define DUMP_FOR_EACH_N2 ( F,
a,
... )
Value:
F(a) DUMP_FOR_EACH_N1(F, __VA_ARGS__)
#define DUMP_FOR_EACH_N1(F, a)
Definition dump_vars.h:54

Definition at line 55 of file dump_vars.h.

◆ DUMP_FOR_EACH_N3

#define DUMP_FOR_EACH_N3 ( F,
a,
... )
Value:
F(a) DUMP_FOR_EACH_N2(F, __VA_ARGS__)
#define DUMP_FOR_EACH_N2(F, a,...)
Definition dump_vars.h:55

Definition at line 56 of file dump_vars.h.

◆ DUMP_FOR_EACH_N4

#define DUMP_FOR_EACH_N4 ( F,
a,
... )
Value:
F(a) DUMP_FOR_EACH_N3(F, __VA_ARGS__)
#define DUMP_FOR_EACH_N3(F, a,...)
Definition dump_vars.h:56

Definition at line 57 of file dump_vars.h.

◆ DUMP_FOR_EACH_N5

#define DUMP_FOR_EACH_N5 ( F,
a,
... )
Value:
F(a) DUMP_FOR_EACH_N4(F, __VA_ARGS__)
#define DUMP_FOR_EACH_N4(F, a,...)
Definition dump_vars.h:57

Definition at line 58 of file dump_vars.h.

◆ DUMP_FOR_EACH_N6

#define DUMP_FOR_EACH_N6 ( F,
a,
... )
Value:
F(a) DUMP_FOR_EACH_N5(F, __VA_ARGS__)
#define DUMP_FOR_EACH_N5(F, a,...)
Definition dump_vars.h:58

Definition at line 59 of file dump_vars.h.

◆ DUMP_FOR_EACH_N7

#define DUMP_FOR_EACH_N7 ( F,
a,
... )
Value:
F(a) DUMP_FOR_EACH_N6(F, __VA_ARGS__)
#define DUMP_FOR_EACH_N6(F, a,...)
Definition dump_vars.h:59

Definition at line 60 of file dump_vars.h.

◆ DUMP_FOR_EACH_N8

#define DUMP_FOR_EACH_N8 ( F,
a,
... )
Value:
F(a) DUMP_FOR_EACH_N7(F, __VA_ARGS__)
#define DUMP_FOR_EACH_N7(F, a,...)
Definition dump_vars.h:60

Definition at line 61 of file dump_vars.h.

◆ DUMP_FOR_EACH_N9

#define DUMP_FOR_EACH_N9 ( F,
a,
... )
Value:
F(a) DUMP_FOR_EACH_N8(F, __VA_ARGS__)
#define DUMP_FOR_EACH_N8(F, a,...)
Definition dump_vars.h:61

Definition at line 62 of file dump_vars.h.

◆ DUMP_GEN_BINDING

#define DUMP_GEN_BINDING ( binding)
Value:
#define DUMP_FOR_EACH(F,...)
Definition dump_vars.h:74
#define DUMP_RM_PARENS(...)
Removes parenthesis. Requires argument enclosed in parenthesis.
Definition dump_vars.h:86
#define DUMP_GEN_ONE_BINDING(a)
Definition dump_vars.h:88

Definition at line 89 of file dump_vars.h.

◆ DUMP_GEN_ONE_BINDING

#define DUMP_GEN_ONE_BINDING ( a)
Value:
, &a = a

Definition at line 88 of file dump_vars.h.

◆ DUMP_IDENTITY

#define DUMP_IDENTITY ( ...)
Value:
__VA_ARGS__

Returns the arguments.

Definition at line 84 of file dump_vars.h.

◆ DUMP_NARG

#define DUMP_NARG ( ...)
Value:
DUMP_NARG_(__VA_OPT__(__VA_ARGS__, ) DUMP_RSEQ_N())
#define DUMP_RSEQ_N()
Definition dump_vars.h:73
#define DUMP_NARG_(...)
Definition dump_vars.h:71

Definition at line 70 of file dump_vars.h.

◆ DUMP_NARG_

#define DUMP_NARG_ ( ...)
Value:
DUMP_ARG_N(__VA_ARGS__)
#define DUMP_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, N,...)
Definition dump_vars.h:72

Definition at line 71 of file dump_vars.h.

◆ DUMP_RM_PARENS

#define DUMP_RM_PARENS ( ...)
Value:
DUMP_IDENTITY __VA_ARGS__
#define DUMP_IDENTITY(...)
Returns the arguments.
Definition dump_vars.h:84

Removes parenthesis. Requires argument enclosed in parenthesis.

Definition at line 86 of file dump_vars.h.

◆ DUMP_RSEQ_N

#define DUMP_RSEQ_N ( )
Value:
11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0

Definition at line 73 of file dump_vars.h.

◆ DUMP_STRINGIFY

#define DUMP_STRINGIFY ( ...)
Value:
#define DUMP_STRINGIZE(a)
Definition dump_vars.h:80

Definition at line 81 of file dump_vars.h.

◆ DUMP_STRINGIZE

#define DUMP_STRINGIZE ( a)
Value:
#a,

Definition at line 80 of file dump_vars.h.

◆ DUMP_VARS

#define DUMP_VARS ( ...)
Value:
DUMP_VARS_WITH_BINDINGS((), __VA_ARGS__)
#define DUMP_VARS_WITH_BINDINGS(binding,...)
Definition dump_vars.h:92

Definition at line 77 of file dump_vars.h.

◆ DUMP_VARS_WITH_BINDINGS

#define DUMP_VARS_WITH_BINDINGS ( binding,
... )
Value:
DUMP_STRINGIFY(__VA_ARGS__)}, \
[DUMP_GEN_BINDING(binding)]( \
::std::ostream& os, const ::std::string& field_sep, \
const ::std::string& kv_sep, \
const ::operations_research::base::internal_dump_vars::DumpNames& \
names) { \
.os = os, \
.field_sep = field_sep, \
.kv_sep = kv_sep, \
.names = names, \
}(__VA_ARGS__); \
})
#define DUMP_GEN_BINDING(binding)
Definition dump_vars.h:89
Dump< F > make_dump_vars(DumpNames &&names, F f)
Definition dump_vars.h:213
::std::vector<::std::string > DumpNames
Definition dump_vars.h:140

Definition at line 92 of file dump_vars.h.