1

I've got this warning:

warning: decomposition declaration only available with -std=c++1z or -std=gnu++1

for this code:

#include<algorithm>
#include<vector>

int main(){
    std::vector<int> vect{ 10, 20, 30 };
    const auto [min, max] = std::minmax_element(vect.begin(), vect.end());

    return 0;
}

what does decomposition declaration in this context means?

dboy
  • 1,004
  • 2
  • 16
  • 24
  • 2
    Well, just add that to your compiler flags as suggested? It means your code uses a feature, which is only available in a different (newer) standard than the compilers default. – πάντα ῥεῖ Feb 08 '21 at 10:05
  • 1
    Namely, you use the so-called [structured binding declaration](https://en.cppreference.com/w/cpp/language/structured_binding) which was added to C++ by the C++17 standard. This was referred to as C++1z before its official publication. Additionally, you may be interested in this question: [What are the differences between -std=c++11 and -std=gnu++11?](https://stackoverflow.com/q/10613126/580083) plus this article: [History of C++](https://en.cppreference.com/w/cpp/language/history). – Daniel Langr Feb 08 '21 at 10:17

1 Answers1

3

what does it mean?

The warning means that you've used syntax / language feature that was introduced to the language in C++17 standard (whose working title was C++1z), but you are compiling for an older standard version.

what does decomposition declaration in this context means?

"Decomposition declaration" is another name for structured bindings which is the new(ish) language feature that is being used on the line:

const auto [min, max] = std::minmax_element(vect.begin(), vect.end());

The simplified grammar of structured bindings (i.e. decomposition declarations) is:

auto [ identifier-list ] = expression ;
dboy
  • 1,004
  • 2
  • 16
  • 24
eerorika
  • 232,697
  • 12
  • 197
  • 326
  • thanks for the answer, but apparently my question is misleading: I want to know what decomposition declaration in this context meant, not that what's follow. I've update the question. – dboy Feb 08 '21 at 14:44