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:
- .move which inserts std::move
- .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).
Please sign in to leave a comment.
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).
Hey,
oh I didn't notice. 'move' didn't appear in dependent context for me (I think that's also mentioned in your link):
Only 'static_cast' and 'reinterpret_cast' are available.
On another note: what about 'std::ref' and 'std::move_if_noexcept'?
I created issues https://youtrack.jetbrains.com/issue/RSCPP-28705 and https://youtrack.jetbrains.com/issue/RSCPP-28706.
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)?
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)
}