Advertisement
spacechase0

Lambda

Feb 19th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. void SceneGame::SortObjects()
  2. {
  3.     auto sorterRaw = []( ObjectPtr it1, ObjectPtr it2 ) -> bool
  4.                      {
  5.                         auto obj1 = static_cast< DepthObject* >( it1.get() );
  6.                         auto obj2 = static_cast< DepthObject* >( it2.get() );
  7.                        
  8.                         if ( obj1->GetDepth() == obj2->GetDepth() )
  9.                         {
  10.                             return false;
  11.                         }
  12.                        
  13.                         return obj1->GetDepth() > obj2->GetDepth();
  14.                      };
  15.    
  16.     using namespace std::placeholders;
  17.     auto sorter = std::bind( sorterRaw, _1, _2 );
  18.    
  19.     std::sort( objects.begin(), objects.end(), sorter );
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement