Skip to content

Instantly share code, notes, and snippets.

@RklAlx
Created September 27, 2013 12:04
Show Gist options
  • Save RklAlx/6727597 to your computer and use it in GitHub Desktop.
Save RklAlx/6727597 to your computer and use it in GitHub Desktop.
std::for_each
//MAX using Lambda
std::vector<int> m_MsgTypeMaximumSize;
m_MsgTypeMaximumSize.push_back(7);
m_MsgTypeMaximumSize.push_back(5);
m_MsgTypeMaximumSize.push_back(20);
m_MsgTypeMaximumSize.push_back(1);
m_MsgTypeMaximumSize.push_back(3);
int max = 0;
for_each(m_MsgTypeMaximumSize.begin(), m_MsgTypeMaximumSize.end(), [&max] (int y)
{
max = max>y ? max : y;
});
printf("%d\n",max);
//prints: 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment