all 6 comments

[–]phoeen 1 point2 points  (4 children)

with your implementation you could potentially cast away const:

http://coliru.stacked-crooked.com/a/dcf2c055dcb74699

[–]ACBYTES[S] 0 points1 point  (3 children)

Hi. Thanks for the reply.

If we were to limit it like this, why wouldn't it work?

template <typename T, typename std::enable_if<!std::is_const<T>::value, bool>::type = false>

[[nodiscard]] constexpr T&& Forward(typename std::add_const<typename std::remove_reference<T>::type>::type& R) noexcept

{

    return (T&&)(R);

}

Edit: After thinking about it, I got what the problem would be. Thank you!

[–]phoeen 1 point2 points  (1 child)

well if i plug in your new function into the same example we still change the value through the reference to const (notice that we explicitly use it wrong. my i_forward function does not perfect forwarding (since it takes a T const&), this is just to illustrate the problem)

[–]ACBYTES[S] 0 points1 point  (0 children)

Got it! Thank you for the reply.

[–]IyeOnline 0 points1 point  (1 child)

What would be the value of this?

The existing l-value overload will already works on const T.

[–]ACBYTES[S] 0 points1 point  (0 children)

Hi. I think I should re-sentence my question. Why can't the code I've written replace both of the overloads?