stream operator

release/4.3a0
Frank Dellaert 2025-01-26 16:57:37 -05:00
parent 131f51a30c
commit 4027e86057
2 changed files with 17 additions and 2 deletions

View File

@ -26,12 +26,24 @@ using std::stringstream;
namespace gtsam {
/* ************************************************************************ */
static void stream(std::ostream& os, const DiscreteValues& x,
const KeyFormatter& keyFormatter) {
for (const auto& kv : x)
os << "(" << keyFormatter(kv.first) << ", " << kv.second << ")";
}
/* ************************************************************************ */
std::ostream& operator<<(std::ostream& os, const DiscreteValues& x) {
stream(os, x, DefaultKeyFormatter);
return os;
}
/* ************************************************************************ */
void DiscreteValues::print(const string& s,
const KeyFormatter& keyFormatter) const {
cout << s << ": ";
for (auto&& kv : *this)
cout << "(" << keyFormatter(kv.first) << ", " << kv.second << ")";
stream(cout, *this, keyFormatter);
cout << endl;
}

View File

@ -64,6 +64,9 @@ class GTSAM_EXPORT DiscreteValues : public Assignment<Key> {
/// @name Standard Interface
/// @{
/// ostream operator:
friend std::ostream& operator<<(std::ostream& os, const DiscreteValues& x);
// insert in base class;
std::pair<iterator, bool> insert( const value_type& value ){
return Base::insert(value);