C++ Logo

std-proposals

Advanced search

Operator for reference casting

From: Jean-Baptiste Vallon Hoarau <jeanbaptiste.vallon_at_[hidden]>
Date: Fri, 15 Jan 2021 14:49:05 +0100
Hello everyone,

I think you are all aware how verbose perfect forwarding is. I haven't seen
any proposal that could tackle this (admittedly minor) issue so far, except
the one on hygienic macros.
So what if we had an operator for casting to a reference?
For example, given a value x, than the following could be equivalent :
x& -> static_cast<decltype(x)&>(x)
x&& -> static_cast<decltype(x)&&>(x)

This would make forwarding a lot less cumbersome to write/read (goodbye
decltype(x)(x), hello x&&). However, I don't see many use cases for
explicit lvalue cast, and this would be at odd with lambda capture syntax.

Let me know what you think.
-Jean-Baptiste

Received on 2021-01-15 07:49:18