diff --git a/src/Magnum/Math/Test/VectorTest.cpp b/src/Magnum/Math/Test/VectorTest.cpp index bd90de797..da6da6297 100644 --- a/src/Magnum/Math/Test/VectorTest.cpp +++ b/src/Magnum/Math/Test/VectorTest.cpp @@ -119,6 +119,7 @@ struct VectorTest: TestSuite::Tester { void debug(); void debugPacked(); + void debugPropagateFlags(); }; /* What's a typedef and not a using differs from the typedefs in root Magnum @@ -197,7 +198,8 @@ VectorTest::VectorTest() { &VectorTest::strictWeakOrdering, &VectorTest::debug, - &VectorTest::debugPacked}); + &VectorTest::debugPacked, + &VectorTest::debugPropagateFlags}); } void VectorTest::construct() { @@ -1332,6 +1334,14 @@ void VectorTest::debugPacked() { CORRADE_COMPARE(out.str(), "{0.5, 15, 1, 1} Vector(0, 0, 0, 0)\n"); } +void VectorTest::debugPropagateFlags() { + std::ostringstream out; + /* The modifier shouldn't become persistent for values after. The nospace + modifier shouldn't get propagated. */ + Debug{&out} << ">" << Debug::nospace << Debug::hex << Vector2i(0xab, 0xcd) << Vector2i(12, 13); + CORRADE_COMPARE(out.str(), ">Vector(0xab, 0xcd) Vector(12, 13)\n"); +} + }}}} CORRADE_TEST_MAIN(Magnum::Math::Test::VectorTest) diff --git a/src/Magnum/Math/Vector.h b/src/Magnum/Math/Vector.h index 7c6d603d0..8fbf68205 100644 --- a/src/Magnum/Math/Vector.h +++ b/src/Magnum/Math/Vector.h @@ -1316,15 +1316,24 @@ template inline BitVector notEqual(const Vector #ifndef CORRADE_SINGLES_NO_DEBUG /** @debugoperator{Vector} */ template Debug& operator<<(Debug& debug, const Vector& value) { - /** @todo might make sense to propagate the flags also, for hex value - printing etc */ + /* Nested values should get printed with the same flags, so make all + immediate flags temporarily global -- except NoSpace, unless it's also + set globally */ + const Utility::Debug::Flags prevFlags = debug.flags(); + debug.setFlags(prevFlags | (debug.immediateFlags() & ~Utility::Debug::Flag::NoSpace)); + const bool packed = debug.immediateFlags() >= Debug::Flag::Packed; debug << (packed ? "{" : "Vector(") << Debug::nospace; for(std::size_t i = 0; i != size; ++i) { if(i != 0) debug << Debug::nospace << ","; debug << value[i]; } - return debug << Debug::nospace << (packed ? "}" : ")"); + debug << Debug::nospace << (packed ? "}" : ")"); + + /* Reset the original flags back */ + debug.setFlags(prevFlags); + + return debug; } /* Explicit instantiation for commonly used types */