Skip to content

Commit be1c14b

Browse files
committed
add C++20 lambda template
1 parent 73dee3c commit be1c14b

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

snippets/snippet18.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"cpp_file": "snippet18.cpp",
3-
"compiler": "g92",
3+
"compiler": "clang900",
4+
"flags": "-std=c++2a",
45
"execute": true
56
}

snippets/snippet18.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include <cmath>
2+
#include <iostream>
23

34
int main() {
4-
auto y = [](auto x) {
5-
using T = decltype(x);
5+
auto y = []<typename T>(T x) {
66
T mean = 1.;
77
T width = 3.;
88
auto norm = 1. / std::sqrt(2. * M_PI);
99
auto arg = (x - mean) / width;
1010
return norm * std::exp(-.5 * arg * arg);
1111
}(.5);
12-
13-
return y;
12+
13+
std::cout << y;
1414
}

snippets/snippet18_cpplst.tex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
\begin{lstlisting}[title=\href{https://godbolt.org/z/3-FVEE}{\texttt{godbolt.org/z/3-FVEE}}]
1+
\begin{lstlisting}[title=\href{https://godbolt.org/z/NC6DKj}{\texttt{godbolt.org/z/NC6DKj}}]
22
#include <cmath>
3+
#include <iostream>
34

45
int main() {
5-
auto y = [](auto x) {
6-
using T = decltype(x);
6+
auto y = []<typename T>(T x) {
77
T mean = 1.;
88
T width = 3.;
99
auto norm = 1. / std::sqrt(2. * M_PI);
1010
auto arg = (x - mean) / width;
1111
return norm * std::exp(-.5 * arg * arg);
1212
}(.5);
13-
14-
return y;
13+
14+
std::cout << y;
1515
}
1616
\end{lstlisting}

0 commit comments

Comments
 (0)