CPP/C++0x/Lambda

From ProgrammingExamples
< CPP
Revision as of 13:39, 13 July 2012 by Daviddoria (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Lambda.cpp

#include <iostream>
#include <unordered_set>
 
// must use -std=c++0x flag
 
int main(int argc, char* argv[])
{
  // Create a set
  std::unordered_set<unsigned int> S;
 
  // Add 10 elements to the set
  for(unsigned int i = 0; i < 10; i++)
  {
    S.insert(i);
  }
 
  // Output all of the elements in the set
  for(auto it1 = S.cbegin(); it1 != S.cend(); it1++)
  {
    std::cout << " " << *it1;
  }
 
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
Project(Lambda)
ADD_EXECUTABLE(Lambda Lambda.cpp)