gtsam 4.2.0
gtsam
utilities.h
1#pragma once
2
3#include <string>
4#include <iostream>
5#include <sstream>
6
7namespace gtsam {
16 RedirectCout() : ssBuffer_(), coutBuffer_(std::cout.rdbuf(ssBuffer_.rdbuf())) {}
17
19 std::string str() const;
20
23
24private:
25 std::stringstream ssBuffer_;
26 std::streambuf* coutBuffer_;
27};
28
29}
30
31// boost::index_sequence was introduced in 1.66, so we'll manually define an
32// implementation if user has 1.65. boost::index_sequence is used to get array
33// indices that align with a parameter pack.
34#include <boost/version.hpp>
35#if BOOST_VERSION >= 106600
36#include <boost/mp11/integer_sequence.hpp>
37#else
38namespace boost {
39namespace mp11 {
40// Adapted from https://stackoverflow.com/a/32223343/9151520
41template <size_t... Ints>
43 using type = index_sequence;
44 using value_type = size_t;
45 static constexpr std::size_t size() noexcept { return sizeof...(Ints); }
46};
47namespace detail {
48template <class Sequence1, class Sequence2>
50
51template <size_t... I1, size_t... I2>
53 : index_sequence<I1..., (sizeof...(I1) + I2)...> {};
54} // namespace detail
55template <size_t N>
58 typename make_index_sequence<N / 2>::type,
59 typename make_index_sequence<N - N / 2>::type> {};
60template <>
62template <>
64template <class... T>
65using index_sequence_for = make_index_sequence<sizeof...(T)>;
66} // namespace mp11
67} // namespace boost
68#endif
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
For Python str().
Definition: utilities.h:14
~RedirectCout()
destructor – redirect stdout buffer to its original buffer
Definition: utilities.cpp:9
std::string str() const
return the string
Definition: utilities.cpp:5
RedirectCout()
constructor – redirect stdout buffer to a stringstream buffer
Definition: utilities.h:16
Definition: utilities.h:42
Definition: utilities.h:59