Bug 1352863 - Add a CoordOf metafunction that maps point and rect types to their coordinate type. r=kats draft
authorBotond Ballo <botond@mozilla.com>
Fri, 19 May 2017 19:54:25 -0400
changeset 583904 65e4c255eeb5646e351692e6d4f91d3e6c8e5789
parent 583751 1a735bdbbfa9a11e78b7e977d45cf00af85e7b66
child 583905 5798103462e454dc61abb7c8a26b997f02c8be36
push id60596
push userbballo@mozilla.com
push dateWed, 24 May 2017 19:49:24 +0000
reviewerskats
bugs1352863
milestone55.0a1
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
layout/base/Units.h
--- 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