-
Notifications
You must be signed in to change notification settings - Fork 0
/
coroutinefunc.cpp
37 lines (34 loc) · 1 KB
/
coroutinefunc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// coroutinefunc.cpp : Defines the entry point for the console application.
//
#include "func.h"
#include <iostream>
int main() {
{
func<int> f = []() { return 7; };
std::cout << f() << std::endl;
std::cout << f() << std::endl;
}
{
func<int, std::unique_ptr<int> const&> f = [](auto const& p) { return *p; };
std::cout << f(std::make_unique<int>(7)) << std::endl;
std::cout << f(std::make_unique<int>(-1)) << std::endl;
}
{
func<std::unique_ptr<int>, std::unique_ptr<int> const&> f = [](auto const& p) { return std::make_unique<int>(*p); };
std::cout << *f(std::make_unique<int>(7)) << std::endl;
std::cout << *f(std::make_unique<int>(-1)) << std::endl;
}
{
func<int, int> f = [](int i) -> int { throw i; };
try {
std::cout << f(7) << std::endl;
} catch (int i) {
std::cout << "Caught " << i << std::endl;
}
try {
std::cout << f(-1) << std::endl;
} catch (int i) {
std::cout << "Caught " << i << std::endl;
}
}
}