New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The ValueType parameter of std::any_cast is confusingly named #1202
Comments
The pointer variant of |
I'm preparing a patch that replaces ValueType with T and uses VT where the description seems to hint we're dealing with the actual ValueType. |
That sounds good to me - thanks. |
The parameter has a confusing name: It is not actually the value type contained in the 'any'. Where the new T clashes with an existing use of T, rename the latter to VT, since this is actually the value type of the 'any'. Fixes cplusplus#1202.
The parameter has a confusing name: It is not actually the value type contained in the 'any'. Where the new T clashes with an existing use of T, rename the latter to VT, since this is actually the value type of the 'any'. Fixes cplusplus#1202.
The parameter has a confusing name: It is not actually the value type contained in the 'any'. Where the new T clashes with an existing use of T, rename the latter to VT, since this is actually the value type of the 'any'. Fixes #1202.
This template parameter is confusing, because it's really the return type of the function, not the type of the contained value in the
any
(as shown by the fact the requirements say it must be a reference, or copy constructible). When the parameter is a reference the functions return by reference, not by value, andValueType
is not the type of the value in theany
. The parameter can beconst
but the value in theany
is not a const-qualified type.Elsewhere in the library "value type" is used for containers, iterators, and allocators, and must be an object type, not a reference type.
I suggest renaming this to make it clearer that it can be a reference, and is not the type of the value in the
any
.Result
orResultType
might be better. Or justType
orT
.For the
any_cast
overloads taking pointers theValueType
parameter is OK, as in that case it does refer to the type of the value in theany
.The text was updated successfully, but these errors were encountered: