From db2a696f810e41189bcdf5524696ff3d0cfbe5a9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 7 Feb 2017 11:40:07 +0200 Subject: Use target:as<> instead of static_cast for target casting --- build2/target | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'build2/target') diff --git a/build2/target b/build2/target index 2eb6a2c..48c80e7 100644 --- a/build2/target +++ b/build2/target @@ -112,8 +112,6 @@ namespace build2 optional* ext_; // Reference to value in target_key. public: - using action_type = build2::action; - // For targets that are in the src tree of a project we also keep the // corresponding out directory. As a result we may end up with multiple // targets for the same file if we are building multiple configurations of @@ -240,6 +238,8 @@ namespace build2 } public: + using action_type = build2::action; + // Reset the target before matching it to a rule. The default // implementation clears the auxilary data and prerequisite_targets. // @@ -540,9 +540,12 @@ namespace build2 private: recipe_type recipe_; - // Target type info. + // Target type info and casting. // public: + bool + is_a (const target_type& tt) const {return type ().is_a (tt);} + template T* is_a () {return dynamic_cast (this);} @@ -551,8 +554,15 @@ namespace build2 const T* is_a () const {return dynamic_cast (this);} - bool - is_a (const target_type& tt) const {return type ().is_a (tt);} + // Unchecked cast. + // + template + T& + as () {return static_cast (*this);} + + template + const T& + as () const {return static_cast (*this);} // Dynamic derivation to support define. // @@ -1074,14 +1084,13 @@ namespace build2 optional ext, tracer& t) { - return static_cast ( - insert (tt, - move (dir), - move (out), - move (name), - move (ext), - true, - t).first); + return insert (tt, + move (dir), + move (out), + move (name), + move (ext), + true, + t).first.template as (); } template @@ -1092,8 +1101,7 @@ namespace build2 const optional& ext, tracer& t) { - return static_cast ( - insert (T::static_type, dir, out, name, ext, true, t).first); + return insert (T::static_type, dir, out, name, ext, t); } template @@ -1103,8 +1111,7 @@ namespace build2 const string& name, tracer& t) { - return static_cast ( - insert (T::static_type, dir, out, name, nullopt, true, t).first); + return insert (dir, out, name, nullopt, t); } // Note: not MT-safe so can only be used during serial execution. @@ -1149,7 +1156,7 @@ namespace build2 mtime (bool load = true) const { const mtime_target& t (state_ == target_state::group - ? static_cast (*group) + ? group->as () : *this); if (load && t.mtime_ == timestamp_unknown) -- cgit v1.1