How do I call invoke_result correctly for a member function? Or specifically for an operator member function. I tried std::invoke_result<T::operator[], size_type> to no success. What would be the correct syntax in this case?
Don't. Use decltype(std::declval<T&>()[size_type{}]) or something similar (adjust the value category and the cv-qualification as needed).
invoke_result is for when you have an invocable/callable object. You don't have one, so don't try to hammer square pegs into round holes.
What about as follows ?
std::invoke_result<decltype(&T::operator[]), T, size_type>
But this syntax should works with a single, and not template, operator[].
In case of template or overload, you should avoid std::invoke_result and follows the decltype() way suggested by T.C.
Or, maybe, you can wrap the call in a lambda function and apply std::invoke_result to the lambda (if you really, really want to use std::invoke_result).
Regarding the std::invoke_result syntax, take in count that a pointer to a member function is a completely different things, compared to a pointer to a regular function. Anyway, you can roughly see it as a pointer to a regular function receiving an additional argument (in first position) corresponding to the object that call its method.
So, in your example, the first T argument represent the object of type T that call its operator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With