You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constexpr Lambda Expressions in C++ | Microsoft Docs
ms.custom
ms.date
07/19/2017
ms.technology
cpp-language
ms.topic
language-reference
dev_langs
C++
helpviewer_keywords
lambda expressions [C++], constexpr
ms.assetid
b56346cd-fbff-475f-aeaa-ed2010c6d6f7
author
mikeblome
ms.author
mblome
ms.workload
cplusplus
constexpr Lambda Expressions in C++
Visual Studio 2017 version 15.3 and later (available with /std:c++17): A lambda expression may be declared as constexpr or used in a contant expression when the initialization of each data member that it captures or introduces is allowed within a constant expression.
int y = 32;
auto answer = [y]() constexpr
{
int x = 10;
return y + x;
};
constexprintIncrement(int n)
{
return [n] { return n + 1; }();
}
A lambda is implicitly constexpr if its result satisfies the requirements of a constexpr function: