Bug 1352863 - Add a CoordOf metafunction that maps point and rect types to their coordinate type. r=kats
The approach taken is to implement the metafunction by specialization as usual,
and then wrap it into an alias template. This avoids having to write "typename"
and "::Type" at the use site.
MozReview-Commit-ID: VLOxb4Gu0z
--- a/layout/base/Units.h
+++ b/layout/base/Units.h
@@ -666,11 +666,37 @@ gfx::ScaleFactor<src, dst> MaxScaleRatio
}
template<class src, class dst>
gfx::ScaleFactor<src, dst> MinScaleRatio(const gfx::SizeTyped<dst>& aDestSize, const gfx::SizeTyped<src>& aSrcSize) {
return gfx::ScaleFactor<src, dst>(std::min(aDestSize.width / aSrcSize.width,
aDestSize.height / aSrcSize.height));
}
+template <typename T>
+struct CoordOfImpl;
+
+template <typename Units>
+struct CoordOfImpl<gfx::PointTyped<Units>> {
+ typedef gfx::CoordTyped<Units> Type;
+};
+
+template <typename Units>
+struct CoordOfImpl<gfx::IntPointTyped<Units>> {
+ typedef gfx::IntCoordTyped<Units> Type;
+};
+
+template <typename Units>
+struct CoordOfImpl<gfx::RectTyped<Units>> {
+ typedef gfx::CoordTyped<Units> Type;
+};
+
+template <typename Units>
+struct CoordOfImpl<gfx::IntRectTyped<Units>> {
+ typedef gfx::IntCoordTyped<Units> Type;
+};
+
+template <typename T>
+using CoordOf = typename CoordOfImpl<T>::Type;
+
} // namespace mozilla
#endif