The return type alias of a const overloaded function
I have the following overloaded function:
template<size_t N, typename T>
auto get(const T & _t) -> decltype(std::get<...>(_t)) {
...
}
template<size_t N, typename T>
auto get(T & _t) -> decltype(std::get<...>(_t)) {
...
}
First question:
the first one uses std::get(const tuple<_Elements...>& __t)
and the second one std::get(tuple<_Elements...>& __t)
??
now I want to alias the return type of my new function get
:
using type = typename decltype(aux::get<I>(data))::type;
which is used here? const or not? and how can i choose? I would like to alias like !! data
is not constant
source to share
Yes, the former uses overload const
and the latter doesn't const
. This is because _t
const
in the first case and not const
in the second.
Which one is used in a type alias depends on the type data
. Is it const
? If so, the overload const
is done with an alias. If not, then not const
one.
To get any type of "virtual value" you can use std::declval
. This code will match the version const
:
using type = typename decltype(aux::get<I>(std::declval<const YourTypeHere>()))::type;
source to share