Why is the callback called only once?
bool callback() { static bool res = false; res = !res; return res; } int main(int argc, char* argv[]) { vector<int> x(10); bool result=false; for_each(x.begin(),x.end(),var(result)=var(result)||bind(callback)); return 0; }
short circuit bind returns a short circuit|| expression .
bind
||
One way to ensure that it is bindalways called is to move it to the left side ||or change ||to &&, depending on what you are trying to do with result.
&&
result
In your specific example, Boost.Lambda doesn't actually give you anything. Get rid of the lambda parts and you might see what happens next:
for (int i = 0; i < 10; ++i) result = result || callback();
, , || , .
Source: https://habr.com/ru/post/1705061/More articles:Какой лучший способ позволить пользователю выбрать подкаталог в С#? - c#Как получить строку столбца indentity после вставки с помощью LINQ - .netHow can I preload web application classes in the JVM at startup? - javaПочему мой код возвращает ошибку "missing: after property id" в JavaScript? - jsonSerializing an arraylist in C # - c #Redirect the URL to go to the tomcat servlet using Apache / mod_proxy - tomcatInternet Explorer 8 and XMLHttpRequest prototypes - javascriptWhat is the best way to display additional information on a web page? Pop up when pressed or hover? - htmlHow to handle a massive factory in a cleaner way - c #Классические библиотеки ASP Twitter - vbscriptAll Articles