Lambda Expressions in C++

24.04.20 06:08 PM Comment(s) By Umar Lone

Changes to lambda expressions in C++17

C++17 added support for constexpr lambda expressions. You can optionally use constexpr specifier or omit it. The compiler will automatically ascertain if the lambda expression can be constexpr, based on the context of its usage.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void Scene::Collide()
{
	std::uniform_int_distribution<int> dist(0, NPC_TYPES - 1);
	std::uniform_int_distribution<int> distSideObjects(0, sideObjects.size() - 1);
	std::uniform_int_distribution<int> distTrafficObjects(0, trafficObjects.size() - 1);
	GameObject* pGo = nullptr;
	switch (dist(m_Engine))
	{
	case 0://Sideobject
		pGo = sideObjects[distSideObjects(m_Engine)];
		break;
	case 1://Traffic
		pGo = trafficObjects[distTrafficObjects(m_Engine)];
		break;
	default:
		break;
	}
	if (pGo != nullptr) {
		pGo->OnCollision(m_pPlayer);

	}
	std::this_thread::sleep_for(std::chrono::seconds(1));

}
Share -