Date: Fri, 26 Jul 2024 13:11:12 +0200
I got the idea to make a type to simplify forwarding, e.g. by doing
something like:
```c++
template <typename T>
class as_forward {
T&& val_;
public:
constexpr as_forward(...) ...
[[destructive]] constexpr T&& operator*() { return std::forward<T>(val_);
}
};
```
In which the `[[destructive]]`-attribute would be a marker for the compiler
that once this function is called, it should be deemed the end-of-scope for
the object (-s) it is called on and any usage of the variable afterwards
should make the program ill-formed (or at least, give a compiler warning
that can be made an error). However, I realize as I am writing this email
that a similar function would be of use for function parameters as well, so
if the attribute can be applied to parameters, we could have a
`std::move_d(...)` that behaves similarly.
It could help library writers to produce even safer C++-code, and would
open up for forwarding-types similar to the prototype above.
I have never written a proposal before, but would this be a library or
core-language proposal?
// With best regards,
Robin Savonen Söderholm
something like:
```c++
template <typename T>
class as_forward {
T&& val_;
public:
constexpr as_forward(...) ...
[[destructive]] constexpr T&& operator*() { return std::forward<T>(val_);
}
};
```
In which the `[[destructive]]`-attribute would be a marker for the compiler
that once this function is called, it should be deemed the end-of-scope for
the object (-s) it is called on and any usage of the variable afterwards
should make the program ill-formed (or at least, give a compiler warning
that can be made an error). However, I realize as I am writing this email
that a similar function would be of use for function parameters as well, so
if the attribute can be applied to parameters, we could have a
`std::move_d(...)` that behaves similarly.
It could help library writers to produce even safer C++-code, and would
open up for forwarding-types similar to the prototype above.
I have never written a proposal before, but would this be a library or
core-language proposal?
// With best regards,
Robin Savonen Söderholm
Received on 2024-07-26 11:11:24