diff options
Diffstat (limited to 'gcc/cp/cp-tree.h')
-rw-r--r-- | gcc/cp/cp-tree.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 5304f6b..5cd2999 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -1932,6 +1932,38 @@ public: ~temp_override() { overridden_variable = saved_value; } }; +/* Wrapping a template parameter in type_identity_t hides it from template + argument deduction. */ +#if __cpp_lib_type_identity +using std::type_identity_t; +#else +template <typename T> +struct type_identity { typedef T type; }; +template <typename T> +using type_identity_t = typename type_identity<T>::type; +#endif + +/* Object generator function for temp_override, so you don't need to write the + type of the object as a template argument. + + Use as auto x = make_temp_override (flag); */ + +template <typename T> +inline temp_override<T> +make_temp_override (T& var) +{ + return { var }; +} + +/* Likewise, but use as auto x = make_temp_override (flag, value); */ + +template <typename T> +inline temp_override<T> +make_temp_override (T& var, type_identity_t<T> overrider) +{ + return { var, overrider }; +} + /* The cached class binding level, from the most recently exited class, or NULL if none. */ |