@@ -816,6 +816,42 @@ template <typename... Types> struct IsaAndPresentCheckPredicate {
816816 return isa_and_present<Types...>(Val);
817817 }
818818};
819+
820+ // ===----------------------------------------------------------------------===//
821+ // Casting Function Objects
822+ // ===----------------------------------------------------------------------===//
823+
824+ // / Usable in generic algorithms like map_range
825+ template <typename U> struct StaticCastFunc {
826+ template <typename T> decltype (auto ) operator()(T &&Val) const {
827+ return static_cast <U>(Val);
828+ }
829+ };
830+
831+ template <typename U> struct DynCastFunc {
832+ template <typename T> decltype (auto ) operator()(T &&Val) const {
833+ return dyn_cast<U>(Val);
834+ }
835+ };
836+
837+ template <typename U> struct CastFunc {
838+ template <typename T> decltype (auto ) operator()(T &&Val) const {
839+ return cast<U>(Val);
840+ }
841+ };
842+
843+ template <typename U> struct CastIfPresentFunc {
844+ template <typename T> decltype (auto ) operator()(T &&Val) const {
845+ return cast_if_present<U>(Val);
846+ }
847+ };
848+
849+ template <typename U> struct DynCastIfPresentFunc {
850+ template <typename T> decltype (auto ) operator()(T &&Val) const {
851+ return dyn_cast_if_present<U>(Val);
852+ }
853+ };
854+
819855} // namespace detail
820856
821857// / Function object wrapper for the `llvm::isa` type check. The function call
@@ -841,6 +877,20 @@ template <typename... Types>
841877inline constexpr detail::IsaAndPresentCheckPredicate<Types...>
842878 IsaAndPresentPred{};
843879
880+ // / Function objects corresponding to the Cast types defined above.
881+ template <typename From>
882+ inline constexpr detail::StaticCastFunc<From> StaticCastTo{};
883+
884+ template <typename From> inline constexpr detail::CastFunc<From> CastTo{};
885+
886+ template <typename From>
887+ inline constexpr detail::CastIfPresentFunc<From> CastIfPresentTo{};
888+
889+ template <typename From>
890+ inline constexpr detail::DynCastIfPresentFunc<From> DynCastIfPresentTo{};
891+
892+ template <typename From> inline constexpr detail::DynCastFunc<From> DynCastTo{};
893+
844894} // end namespace llvm
845895
846896#endif // LLVM_SUPPORT_CASTING_H
0 commit comments