-
Notifications
You must be signed in to change notification settings - Fork 3
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
Change pair to struct with named members #1
Comments
Interesting discussion point. In my APIs I prefer pair/tuple over On the other hand, |
I agree about |
Structured bindings in C++17 should solve that. Otherwise, I think that maybe just a conversion operator could do it? #include <tuple>
struct MyReturnType {
void* a; int b; double c;
operator std::tuple<void*&, int&, double&>() { return std::tie(a, b, c); }
};
std::tuple<void*, int, double> foo1() { return std::make_tuple(nullptr, 3, 1.27); }
MyReturnType foo2() { return {nullptr, 3, 1.27}; }
int main() {
void* first;
int second;
double third;
std::tie(first, second, third) = foo1();
std::tie(first, second, third) = foo2();
} I tried to make the conversion operator const and return just a standard tuple, but neither Clang nor GCC wanted to eat it. |
Funny that in this case |
https://www.kdab.com/tuple-pair-cpp-apis/
The text was updated successfully, but these errors were encountered: