2

I seem to have an issue with qtcreator not autocompleting my code, which is getting pretty annoying.

Currently is it not able to autocomplete when i try to use structure bindings in for loops like this..

std::vector<pair<string,AudioFile<double>>> list_of_files;
// Some init of list_of_file


for (const auto& [name,file]: this->list_of_files) // red line under this.. does seem to like structure bindings?
{
    file.printSummary(); // qtcreator don't offer any autocomplete options?

}

qtcreator basically complains about everything about the code posted above..

But when I write it like this:

for (int i = 0 ; i <list_of_file.size() ; i++) // No red lines under this.. 
{
  list_of_files[i].second.printSummary() // Autocompletes without any problems.
}

qtcreator does not complain about this code, and seem to autocomplete it just fine.. So why is it causing so many problems with c++17 style?

Any fixes for this?

Lamda
  • 914
  • 3
  • 13
  • 39
  • Is it only the QtCreator *editor* which complains? Or do you get errors when building? If the former, then it's probably because the editor haven't been updated yet (or you're using an old version). If the latter, then your compiler doesn't support C++17 and you might need to explicitly enable it. – Some programmer dude Nov 18 '17 at 12:49
  • Are you using Qt's own code model or the clang code model? You can check in Tools -> Options -> C++ -> Code Model. Although technically it doesn't really matter since neither support C++17 yet. – nwp Nov 18 '17 at 12:54
  • @Someprogrammerdude I haven't tried other editors, and I recently upgraded qtcreator to newest version 5.9.2. The code compiles, no errors. The works as it should in both loops. – Lamda Nov 18 '17 at 12:56
  • @nwp it looks like I don't use clang at the moment.. Any editors that currently supports it.. This is getting quite annoying.. – Lamda Nov 18 '17 at 12:58
  • You can enable the clang code model through Help -> About Plugins -> add checkmark to ClangCodeModel. You get slower but more correct highlighting and code completion, but no C++17 yet. And yes, it *is* very annoying, especially when using for example `std::string_view`. – nwp Nov 18 '17 at 13:02
  • what if one updated clang and made qtcreator use the updated version instead? that should work right? – Lamda Nov 19 '17 at 09:24

1 Answers1

0

A temporary solution for this seem to be something like this - which autocompletions does not complain about, and seem to suit my definition of (readability):

for ( const auto &elements : this->list_of_files)
{
   auto name = std::get<0>(elements);
   auto file = std::get<1>(elements);
}
Lamda
  • 914
  • 3
  • 13
  • 39