More Postfix Templates for C++

Postfix templates are great and since I couldn't find any information on how one could add custom templates I'll ask here. I'd love to see the following postfix templates:

  1. .move which inserts std::move
  2. .forward which inserts std::forward with a somewhat intelligent type deduction (i.e. decltype(var) if the variable is auto or the template type parameter of the variable in question).

Those templates woule be awesome (especially for TMP).

0
5 comments
Avatar
Permanently deleted user

Hello,

The 'move' postfix template is already in R++. If it's not available in some context, please send us a code snippet and we'll take a look. The 'forward' template will be in 2020.1 (https://youtrack.jetbrains.com/issue/RSCPP-22254).

1

Hey,

oh I didn't notice. 'move' didn't appear in dependent context for me (I think that's also mentioned in your link):

template <typename T>
auto f(T&& t)
{
auto my_var = some_type_t<T>{};
return another_type(my_var.
}

Only 'static_cast' and 'reinterpret_cast' are available.

On another note: what about 'std::ref' and 'std::move_if_noexcept'?

0

Thanks for creating the issues. Do those suggestions also pop up (in intelli sense) if their headers are not included (i.e. functional or utility)?

0

Yes, those suggestions pop up if corresponding headers are not included, and #include will be added after code completion invoked. E.g.

template<typename T>
struct some_type_t {};

template<typename T>
auto f()
{
   some_type_t<T> my_var1;
   my_var1. // complete 'cref' here
}

will become

#include <functional>

template<typename T>
struct some_type_t {};

template<typename T>
auto f()
{
   some_type_t<T> my_var1;
   std::cref(my_var1)
}

1

Please sign in to leave a comment.