【发布时间】:2020-05-13 04:17:14
【问题描述】:
在下面的代码 sn-p 中,我看到了这个Unit 类型但不知道什么时候使用它以及它在做什么?我读了这个https://github.com/facebook/folly/blob/master/folly/Unit.h,但仍然不知道如何在我的程序中使用这个单元。单元将提供哪些帮助的典型场景是什么?
Future<Unit> fut3 = std::move(fut2)
.thenValue([](string str) {
cout << str << endl;
})
.thenTry([](folly::Try<string> strTry) {
cout << strTry.value() << endl;
})
.thenError(folly::tag_t<std::exception>{}, [](std::exception const& e) {
cerr << e.what() << endl;
});
【问题讨论】:
-
通过阅读课程的文档您无法弄清楚什么?
-
不知道怎么用?你能举几个例子吗?
-
Unit 的工作方式类似于 void。除了 C++ 的不同之外,这感觉就像 stackoverflow.com/questions/1900962/void-in-constrast-with-unit 的副本。
-
这能回答你的问题吗? Void in constrast with Unit
-
标准有
std::monostate,它是 C++17 的现代 C++ 单元类型。在 C++17 之前(并且仍然存在),许多发现需要某种单元类型的人自己制作。