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 template
keyword is needed to call tuple.get_ref() and union.get_ref() etc
#124
Comments
Some possible thoughts from discussion with @quisquous.
my_tuple.get_ref(5_t); But it's a bit unlucky to need to use another type like that. But being able to deduce the template parameter is required to avoid the
const auto& get_ref(size_t i) const& noexcept {
switch (i) {
case 0: return get_ref_impl<0>();
case 1: return get_ref_impl<1>();
case 2: return get_ref_impl<2>();
...
case 100: return get_ref_impl<100>();
...
case SIZE_T_MAX: return get_ref_impl<SIZE_T_MAX>();
}
} Which could be generated by a recursive macro easily enough, I think. It generates quite a bit of code though.
|
The switch idea probably doesn't work. It would have to be evaluated as constexpr in order to return different types. So we could Though I wonder if we can make a type that consteval-constructs from a number literal? Looks like no. I was hoping it would deduce the template value from the constructor argument. template <int I>
struct NumType {
consteval NumType(int i) {} // Provides CTAD-based implicit conversion.
static constexpr int value = I;
};
int f(NumType<0>) { return 0; }
int f(NumType<1>) { return 1; }
int main() {
return f(1);
}
Function parameters can't be constexpr so it can't tell that the value is a literal. template<int I>
NumType(int i) -> NumType<i>;
|
See also https://stackoverflow.com/questions/37231651/implicitly-convert-number-to-integral-const which does this for a free function.. with macros. Not what we want. |
This is awkward...
Not only this but the compiler errors on MSVC and GCC complain about the
()
missing arguments (cuz we haveget_ref()
methods on some types that take an argument?) instead of complaining about missingtemplate
. Only Clang gets this right..I wish we could pass the index as a parameter but I don't think that we can, we have to walk up N base classes in tuple, and the methods can't be consteval or anything like that.
Do we move to a global get_ref? :/ That's really unlucky if so. And it's not needed for vec/array/slice/indexing things.
The text was updated successfully, but these errors were encountered: