Browse Source

Math: add explicit boolean conversion to BoolVector.

pull/187/head^2
Vladimír Vondruš 10 years ago
parent
commit
cf185b00fa
  1. 26
      src/Magnum/Math/BoolVector.h
  2. 11
      src/Magnum/Math/Test/BoolVectorTest.cpp

26
src/Magnum/Math/BoolVector.h

@ -134,13 +134,33 @@ template<std::size_t size> class BoolVector {
return !operator==(other);
}
/** @brief Whether all bits are set */
/**
* @brief Boolean conversion
*
* Equivalent to @ref all().
* @see @ref any(), @ref none()
*/
explicit operator bool() const { return all(); }
/**
* @brief Whether all bits are set
*
* @see @ref none(), @ref any(), @ref operator bool()
*/
bool all() const;
/** @brief Whether no bits are set */
/**
* @brief Whether no bits are set
*
* @see @ref all(), @ref any(), @ref operator bool()
*/
bool none() const;
/** @brief Whether any bit is set */
/**
* @brief Whether any bit is set
*
* @see @ref all(), @ref none(), @ref operator bool()
*/
bool any() const { return !none(); }
/** @brief Bitwise inversion */

11
src/Magnum/Math/Test/BoolVectorTest.cpp

@ -43,6 +43,7 @@ struct BoolVectorTest: Corrade::TestSuite::Tester {
void compare();
void compareUndefined();
void convertBool();
void all();
void none();
void any();
@ -70,6 +71,7 @@ BoolVectorTest::BoolVectorTest() {
&BoolVectorTest::compare,
&BoolVectorTest::compareUndefined,
&BoolVectorTest::convertBool,
&BoolVectorTest::all,
&BoolVectorTest::none,
&BoolVectorTest::any,
@ -193,6 +195,15 @@ void BoolVectorTest::compareUndefined() {
CORRADE_VERIFY(a != c);
}
void BoolVectorTest::convertBool() {
/* The ! operation should *just work* using the bool conversion operator */
CORRADE_VERIFY(BoolVector19(0xff, 0xff, 0x07));
CORRADE_VERIFY(!BoolVector19(0xff, 0xff, 0x04));
/* Implicit conversion is not allowed */
CORRADE_VERIFY(!(std::is_convertible<BoolVector19, bool>::value));
}
void BoolVectorTest::all() {
CORRADE_VERIFY(BoolVector19(0xff, 0xff, 0x07).all());

Loading…
Cancel
Save