I'm extracting a tuple with auto [...]
but I'm only using some of the tuple coordinates.
I wanted to know if there is some elegant way to avoid the unused-variable
compiler warning?
Here is my code.
#include <iostream>
#include <vector>
#include <tuple>
int main(int argc, char **argv)
{
std::vector<std::tuple<char,float,int>> myvec;
myvec.push_back(std::make_tuple('a',3.5,8));
myvec.push_back(std::make_tuple('b',1.5,4));
auto [c,f,_] = myvec[1];
std::cout << "char float is " << c << " " << f << "\n";
return 0;
}
And here is the compilation line + warning:
$ g++ -Wall -std=c++17 main.cpp -o main
main.cpp: In function ‘int main(int, char**)’:
main.cpp:10:13: warning: unused variable ‘_’ [-Wunused-variable]
auto [c,f,_] = myvec[1];
^
(I used a Haskell-like variable _
to self document the fact that the last int is a don't-care value).