How can I use for each cycle in GCC?
and how can i get the gcc version? (in code)
Use lambda like
// C++0x only. std::for_each(theContainer.begin(), theContainer.end(), [](someType x) { // do stuff with x. });
range-based for cycle supported by GCC since 4.6.
// C++0x only for (auto x : theContainer) { // do stuff with x. }
for each loop syntax is an extension of MSVC. It is not available in other compilers.
// MSVC only for each (auto x in theContainer) { // do stuff with x. }
But you could just use Boost.Foreach . It is portable and available without C ++ 0x.
// Requires Boost BOOST_FOREACH(someType x, theContainer) { // do stuff with x. }
See How to check the current version of GCC? on how to get the GCC version.
, ++ 0X . <algorithm> , . (++ 0x lambdas , ())
<algorithm>
struct Functor { void operator()(MyType& object) { // what you want to do on objects } } void Foo(std::vector<MyType>& vector) { Functor functor; std::for_each(vector.begin(), vector.end(), functor); }
. ++, .
Source: https://habr.com/ru/post/1760888/More articles:matlab to C ++: Unable to open include file: 'mclmcrrt.h': no such file or directory - matlab-deploymentIs OpenLaszlo DHTML ready for development? - ajaxos.walk () caching / acceleration - pythonКак я могу изменить сопоставления элементов управления/опции/командной строки в раскладке клавиатуры IntelliJ Emacs? - intellij-idealayer.zPosition does not work with non-sister UIViews - iphonesorting a list of tuples - pythonКак искать пользовательский начальный тег, используя Jericho в Java? - java20-bit integer math - mathWhat is the difference between UITouch and UIGestureRecognizer? - iphoneHow to get the model queue name for a given dynamic queue (WebSphere MQ)? - ibm-mqAll Articles