Browse Source

GCC 4.4 compatibility: explicit std::reference_wrapper constructor.

Surely a way to make that utility class useful.
Vladimír Vondruš 12 years ago
parent
commit
4a5ee634b4
  1. 6
      src/Magnum/MeshTools/Test/CombineIndexedArraysTest.cpp
  2. 3
      src/Magnum/SceneGraph/AbstractCamera.hpp
  3. 3
      src/Magnum/SceneGraph/FeatureGroup.hpp
  4. 33
      src/Magnum/SceneGraph/Object.hpp
  5. 39
      src/Magnum/SceneGraph/Test/ObjectTest.cpp
  6. 3
      src/Magnum/Shapes/ShapeGroup.cpp

6
src/Magnum/MeshTools/Test/CombineIndexedArraysTest.cpp

@ -52,7 +52,8 @@ void CombineIndexedArraysTest::wrongIndexCount() {
Error::setOutput(&ss);
std::vector<UnsignedInt> a{0, 1, 0};
std::vector<UnsignedInt> b{3, 4};
std::vector<UnsignedInt> result = MeshTools::combineIndexArrays({a, b});
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
MeshTools::combineIndexArrays({std::ref(a), std::ref(b)});
CORRADE_COMPARE(ss.str(), "MeshTools::combineIndexArrays(): the arrays don't have the same size\n");
}
@ -62,7 +63,8 @@ void CombineIndexedArraysTest::indexArrays() {
std::vector<UnsignedInt> b{3, 4, 3};
std::vector<UnsignedInt> c{6, 7, 6};
std::vector<UnsignedInt> result = MeshTools::combineIndexArrays({a, b, c});
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
std::vector<UnsignedInt> result = MeshTools::combineIndexArrays({std::ref(a), std::ref(b), std::ref(c)});
CORRADE_COMPARE(result, (std::vector<UnsignedInt>{0, 1, 0}));
CORRADE_COMPARE(a, (std::vector<UnsignedInt>{0, 1}));
CORRADE_COMPARE(b, (std::vector<UnsignedInt>{3, 4}));

3
src/Magnum/SceneGraph/AbstractCamera.hpp

@ -97,7 +97,8 @@ template<UnsignedInt dimensions, class T> void AbstractCamera<dimensions, T>::dr
std::vector<std::reference_wrapper<AbstractObject<dimensions, T>>> objects;
objects.reserve(group.size());
for(std::size_t i = 0; i != group.size(); ++i)
objects.push_back(group[i].object());
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
objects.push_back(std::ref(group[i].object()));
std::vector<typename DimensionTraits<dimensions, T>::MatrixType> transformations =
scene->transformationMatrices(objects, _cameraMatrix);

3
src/Magnum/SceneGraph/FeatureGroup.hpp

@ -42,7 +42,8 @@ template<UnsignedInt dimensions, class T> AbstractFeatureGroup<dimensions, T>::A
template<UnsignedInt dimensions, class T> AbstractFeatureGroup<dimensions, T>::~AbstractFeatureGroup() {}
template<UnsignedInt dimensions, class T> void AbstractFeatureGroup<dimensions, T>::add(AbstractFeature<dimensions, T>& feature) {
features.push_back(feature);
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
features.push_back(std::ref(feature));
}
template<UnsignedInt dimensions, class T> void AbstractFeatureGroup<dimensions, T>::remove(AbstractFeature<dimensions, T>& feature) {

33
src/Magnum/SceneGraph/Object.hpp

@ -44,7 +44,8 @@ template<UnsignedInt dimensions, class T> void AbstractObject<dimensions, T>::se
references.reserve(objects.size());
for(auto it = objects.begin(); it != objects.end(); ++it) {
CORRADE_INTERNAL_ASSERT(*it != nullptr);
references.push_back(**it);
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
references.push_back(std::ref(**it));
}
setClean(references);
@ -67,7 +68,8 @@ template<UnsignedInt dimensions, class T> auto AbstractObject<dimensions, T>::tr
references.reserve(objects.size());
for(auto it = objects.begin(); it != objects.end(); ++it) {
CORRADE_INTERNAL_ASSERT(*it != nullptr);
references.push_back(**it);
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
references.push_back(std::ref(**it));
}
return transformationMatrices(references, initialTransformationMatrix);
@ -210,7 +212,8 @@ template<class Transformation> auto Object<Transformation>::doTransformationMatr
castObjects.reserve(objects.size());
/** @todo Ensure this doesn't crash, somehow */
for(auto it = objects.begin(); it != objects.end(); ++it)
castObjects.push_back(static_cast<Object<Transformation>&>(it->get()));
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
castObjects.push_back(std::ref(static_cast<Object<Transformation>&>(it->get())));
return transformationMatrices(std::move(castObjects), initialTransformationMatrix);
}
@ -230,7 +233,8 @@ template<class Transformation> auto Object<Transformation>::transformationMatric
references.reserve(objects.size());
for(auto it = objects.begin(); it != objects.end(); ++it) {
CORRADE_INTERNAL_ASSERT(*it != nullptr);
references.push_back(**it);
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
references.push_back(std::ref(**it));
}
return transformationMatrices(references, initialTransformationMatrix);
@ -313,11 +317,13 @@ template<class Transformation> std::vector<typename Transformation::DataType> Ob
CORRADE_INTERNAL_ASSERT(parent->counter == 0xFFFFu);
parent->counter = UnsignedShort(jointObjects.size());
parent->flags |= Flag::Joint;
jointObjects.push_back(*parent);
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
jointObjects.push_back(std::ref(*parent));
}
/* Else go up the hierarchy */
} else *it = *parent;
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
} else *it = std::ref(*parent);
/* Cycle if reached end */
if(it == objects.end()) it = objects.begin();
@ -364,7 +370,8 @@ template<class Transformation> std::vector<typename Transformation::DataType> Ob
references.reserve(objects.size());
for(auto it = objects.begin(); it != objects.end(); ++it) {
CORRADE_INTERNAL_ASSERT(*it != nullptr);
references.push_back(**it);
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
references.push_back(std::ref(**it));
}
return transformations(std::move(references), initialTransformation);
@ -416,7 +423,8 @@ template<class Transformation> typename Transformation::DataType Object<Transfor
/* Else compose transformation with parent, go up the hierarchy */
} else {
jointTransformations[joint] = Implementation::Transformation<Transformation>::compose(parent->transformation(), jointTransformations[joint]);
o = *parent;
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
o = std::ref(*parent);
}
}
}
@ -426,7 +434,8 @@ template<class Transformation> void Object<Transformation>::doSetClean(const std
castObjects.reserve(objects.size());
/** @todo Ensure this doesn't crash, somehow */
for(auto it = objects.begin(); it != objects.end(); ++it)
castObjects.push_back(static_cast<Object<Transformation>&>(it->get()));
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
castObjects.push_back(std::ref(static_cast<Object<Transformation>&>(it->get())));
setClean(std::move(castObjects));
}
@ -447,7 +456,8 @@ template<class Transformation> void Object<Transformation>::setClean(std::vector
Object<Transformation>* parent = o.parent();
while(parent && !(parent->flags & Flag::Visited) && parent->isDirty()) {
objects.push_back(*parent);
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
objects.push_back(std::ref(*parent));
parent = parent->parent();
}
}
@ -483,7 +493,8 @@ template<class Transformation> void Object<Transformation>::setClean(const std::
references.reserve(objects.size());
for(auto it = objects.begin(); it != objects.end(); ++it) {
CORRADE_INTERNAL_ASSERT(*it != nullptr);
references.push_back(**it);
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
references.push_back(std::ref(**it));
}
setClean(std::move(references));

39
src/Magnum/SceneGraph/Test/ObjectTest.cpp

@ -181,19 +181,22 @@ void ObjectTest::transformations() {
#endif
/* Scene alone */
CORRADE_COMPARE(s.transformations({s}, initial), std::vector<Matrix4>{initial});
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
CORRADE_COMPARE(s.transformations({std::reference_wrapper<Object3D>(s)}, initial), std::vector<Matrix4>{initial});
/* One object */
Object3D first(&s);
first.rotateZ(Deg(30.0f));
Object3D second(&first);
second.scale(Vector3(0.5f));
CORRADE_COMPARE(s.transformations({second}, initial), std::vector<Matrix4>{
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
CORRADE_COMPARE(s.transformations({std::ref(second)}, initial), std::vector<Matrix4>{
initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f))
});
/* One object and scene */
CORRADE_COMPARE(s.transformations({second, s}, initial), (std::vector<Matrix4>{
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
CORRADE_COMPARE(s.transformations({std::ref(second), std::reference_wrapper<Object3D>(s)}, initial), (std::vector<Matrix4>{
initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)),
initial
}));
@ -201,13 +204,15 @@ void ObjectTest::transformations() {
/* Two objects with foreign joint */
Object3D third(&first);
third.translate(Vector3::xAxis(5.0f));
CORRADE_COMPARE(s.transformations({second, third}, initial), (std::vector<Matrix4>{
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
CORRADE_COMPARE(s.transformations({std::ref(second), std::ref(third)}, initial), (std::vector<Matrix4>{
initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)),
initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)),
}));
/* Three objects with joint as one of them */
CORRADE_COMPARE(s.transformations({second, third, first}, initial), (std::vector<Matrix4>{
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
CORRADE_COMPARE(s.transformations({std::ref(second), std::ref(third), std::ref(first)}, initial), (std::vector<Matrix4>{
initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)),
initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)),
initial*Matrix4::rotationZ(Deg(30.0f)),
@ -226,7 +231,8 @@ void ObjectTest::transformationsRelative() {
third.translate(Vector3::xAxis(5.0f));
/* Transformation relative to another object */
CORRADE_COMPARE(second.transformations({third}), std::vector<Matrix4>{
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
CORRADE_COMPARE(second.transformations({std::ref(third)}), std::vector<Matrix4>{
Matrix4::scaling(Vector3(0.5f)).inverted()*Matrix4::translation(Vector3::xAxis(5.0f))
});
@ -238,7 +244,8 @@ void ObjectTest::transformationsRelative() {
orphan1.scale(Vector3::xScale(3.0f));
Object3D orphan2(&orphanParent);
orphan2.translate(Vector3::zAxis(5.0f));
CORRADE_COMPARE(orphan1.transformations({orphan2}), std::vector<Matrix4>{
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
CORRADE_COMPARE(orphan1.transformations({std::ref(orphan2)}), std::vector<Matrix4>{
Matrix4::scaling(Vector3::xScale(3.0f)).inverted()*Matrix4::translation(Vector3::zAxis(5.0f))
});
}
@ -250,7 +257,8 @@ void ObjectTest::transformationsOrphan() {
/* Transformation of objects not part of the same scene */
Scene3D s;
Object3D orphan;
CORRADE_COMPARE(s.transformations({orphan}), std::vector<Matrix4>());
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
CORRADE_COMPARE(s.transformations({std::ref(orphan)}), std::vector<Matrix4>());
CORRADE_COMPARE(o.str(), "SceneGraph::Object::transformations(): the objects are not part of the same tree\n");
}
@ -266,7 +274,8 @@ void ObjectTest::transformationsDuplicate() {
Matrix4 firstExpected = Matrix4::rotationZ(Deg(30.0f));
Matrix4 secondExpected = Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f));
Matrix4 thirdExpected = Matrix4::rotationZ(Deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f));
CORRADE_COMPARE(s.transformations({second, third, second, first, third}), (std::vector<Matrix4>{
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
CORRADE_COMPARE(s.transformations({std::ref(second), std::ref(third), std::ref(second), std::ref(first), std::ref(third)}), (std::vector<Matrix4>{
secondExpected, thirdExpected, secondExpected, firstExpected, thirdExpected
}));
}
@ -396,7 +405,8 @@ void ObjectTest::setCleanListHierarchy() {
childThree->rotate(Deg(90.0f), Vector3::yAxis());
/* Clean the object and all its dirty parents (but not children) */
Scene3D::setClean({*childTwo});
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
Scene3D::setClean({std::reference_wrapper<Object3D>(*childTwo)});
CORRADE_VERIFY(!scene.isDirty());
CORRADE_VERIFY(!childOne->isDirty());
CORRADE_VERIFY(!childTwo->isDirty());
@ -410,13 +420,15 @@ void ObjectTest::setCleanListHierarchy() {
/* If the object itself is already clean, it shouldn't clean it again */
childOne->cleanedAbsoluteTransformation = Matrix4(Matrix4::Zero);
CORRADE_VERIFY(!childOne->isDirty());
Scene3D::setClean({*childOne});
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
Scene3D::setClean({std::reference_wrapper<Object3D>(*childOne)});
CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero));
/* If any object in the hierarchy is already clean, it shouldn't clean it again */
CORRADE_VERIFY(!childOne->isDirty());
childTwo->setDirty();
Scene3D::setClean({*childTwo});
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
Scene3D::setClean({std::reference_wrapper<Object3D>(*childTwo)});
CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero));
}
@ -444,7 +456,8 @@ void ObjectTest::setCleanListBulk() {
CORRADE_VERIFY(c.isDirty());
CORRADE_VERIFY(d.isDirty());
CORRADE_VERIFY(e.isDirty());
Object3D::setClean({a, b, c, d, e});
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
Object3D::setClean({std::ref(a), std::ref(b), std::ref(c), std::reference_wrapper<Object3D>(d), std::ref(e)});
CORRADE_VERIFY(!a.isDirty());
CORRADE_VERIFY(!b.isDirty());
CORRADE_VERIFY(!c.isDirty());

3
src/Magnum/Shapes/ShapeGroup.cpp

@ -35,7 +35,8 @@ template<UnsignedInt dimensions> void ShapeGroup<dimensions>::setClean() {
std::vector<std::reference_wrapper<SceneGraph::AbstractObject<dimensions, Float>>> objects;
objects.reserve(this->size());
for(std::size_t i = 0; i != this->size(); ++i)
objects.push_back((*this)[i].object());
/* GCC 4.4 has explicit constructor for std::reference_wrapper. WHY ON EARTH. WHY. */
objects.push_back(std::ref((*this)[i].object()));
SceneGraph::AbstractObject<dimensions, Float>::setClean(objects);
}

Loading…
Cancel
Save