- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
鉴于这个最小的代码示例,我在其中从 std::chrono::nanoseconds 构造了一个 time_point:
#include <chrono>
int
main()
{
std::chrono::time_point<std::chrono::system_clock> t{std::chrono::nanoseconds{10}};
(void)t;
}
根据我的阅读,这应该没问题 specification : 纳秒是持续时间,time_point 支持从持续时间构造。实际上,使用 x86_64 clang 11.0.0 可以很好地编译:
但是,在我的 Mac 上编译时,我收到以下错误:
clang++ -g -Wall -Werror -std=c++17 test.cc -o test
test.cc:6:54: error: no matching constructor for initialization of 'std::chrono::time_point<std::chrono::system_clock>'
std::chrono::time_point<std::chrono::system_clock> t{std::chrono::nanoseconds{10}};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/chrono:1355:28: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::chrono::nanoseconds' (aka 'duration<long long, ratio<1LL, 1000000000LL> >') to
'const std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000> > >' for 1st argument
class _LIBCPP_TEMPLATE_VIS time_point
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/chrono:1355:28: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'std::chrono::nanoseconds' (aka 'duration<long long, ratio<1LL, 1000000000LL> >') to
'std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1, 1000000> > >' for 1st argument
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/chrono:1369:70: note: candidate constructor not viable: no known conversion from 'duration<[...], ratio<[...], 1000000000>>' to 'const duration<[...], ratio<[...], 1000000>>' for 1st argument
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/chrono:1374:5: note: candidate template ignored: could not match 'time_point' against 'duration'
time_point(const time_point<clock, _Duration2>& t,
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/chrono:1368:61: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
^
1 error generated.
这是我正在使用的 clang:
$ clang++ --version
Apple clang version 12.0.0 (clang-1200.0.26.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
有人可以帮助我了解我是在处理 Apple clang 编译器中的编译器错误,还是在处理 x86_64 clang 中不受严格支持的问题?
更新
霍华德的回答指出了我的问题并提供了解决方案。只是为了使事情明确并可能避免混淆其他人,这是我最初的问题,从上面引用:
Can someone help me understand whether I'm dealing with a compiler bugin the Apple clang compiler or whether I'm getting away with somethingin the x86_64 clang that isn't strictly supported?
这道题的正确答案是“两者都不是”。我最初在 Linux 上用 libstd c++ 编写代码,它以纳秒为 time_point 的默认持续时间。我没有意识到这一点,但我的代码隐含地假定了这一点。当我尝试在 Apple clang 中构建从纳秒持续时间构建 time_point 的相同代码时,它无法编译,因为那里的 time_point 默认为微秒。因此,编译器警告我截断,这很有帮助,当然不是编译器错误。一旦我按照 Howard 的建议做了并用纳秒明确地实例化了我的所有 time_points,我在任何一个系统上都不再有问题。
最佳答案
在 macOS 上,system_clock::duration
是 微秒
。 chrono 库可防止您意外地将 nanoseconds
截断为 microseconds
并丢失信息。您可以手动进行截断(例如使用 duration_cast
),或者您可以更改 time_point
的类型,以便它可以存储 nanoseconds
:
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>
t{std::chrono::nanoseconds{10}};
在 C++20 中,上面的行可以简化为:
std::chrono::sys_time t{std::chrono::nanoseconds{10}};
t
的类型和值将保持不变。 sys_time
只是一个基于 system_clock
的 time_point
的类型别名。
关于clang++ - Apple clang:为什么我不能从 std::chrono::nanoseconds 创建 time_point,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65397041/
一直以来中国版Apple Watch心不支持心电图功能,不过近日Apple Watch心电图终于在国行版上线了!那么Apple Watch心国内版心电图要如何使用呢?下面一起来看看吧! App
我正在尝试将“使用 Apple 登录”添加到我现有的 App ID。检查启用它的选项后,显示以下弹出窗口:带有此消息: If you're enabling an App ID for the fir
我有一个并发症,可能需要每 5 分钟更新一次。这很容易总结为每天 120 次更新。有没有办法只在用户唤醒 watch 时更新? 最佳答案 我认为您的问题的答案是否,目前没有办法只在用户唤醒 watch
我们正在测试新 Sign in with Apple我们的应用程序的功能,并且在初始请求时,我们会提供用户的全名和电子邮件地址(如果用户启用了这些选项)。 但是在随后的请求中,此数据不仅提供 iden
在我的苹果 watch 扩展中,我想使用长按手势功能。是否有任何 api 等效于 UILongPressGestureRecognizer。我的要求是,在 watch 扩展上,我有表格想要长按单元格,
有没有办法以编程方式显示苹果 map 中多个点之间的路线,如谷歌地图? 最佳答案 正如 MKMapItem 文档所述: If you specify the MKLaunchOptionsDirect
我一直在互联网上关注很多教程来学习如何设置并发症。按预期设置并发症我没有问题。 直到初始时间线条目过期。 12 小时后,我不知道如何更新它以保持并发症的存在。我将在下面分享我拥有的所有内容,希望有人可
我看到一本书的描述...... 书上说 /^Apple/ 会匹配字符串开头有一个 Apple 的字符串。所以它将匹配 Apple Apple1 AppleApple AppleABC ...... 书
众所周知,您可以禁止从允许接收 Apple 通知的应用程序接收通知。但是有谁知道禁用是在本地进行的(忽略 Apple 发送到应用程序的通知),还是 Apple 停止从它的服务器向您发送通知? 最佳答案
我有一个 Apple id,我正在构建一个使用 Apple 推送通知服务的应用程序,但我对此有点困惑。 Apple 执行此过程是否收费?它可以在安装了我的应用程序的特定数量的设备上运行是否有任何限制?
我正在制作一个音频播放器应用。 在苹果的音乐应用中,如果音乐专辑或播客没有插图,则显示音符图像或播客图标图像而不是插图。 我想做同样的事情。 我可以在我的应用程序中使用苹果音乐应用程序中的图像吗? 苹
我有一个自定义框架,我正在归档以在另一个项目中使用。更新到 Xcode11 后,我在使用该框架的项目中收到以下错误。 找不到目标“x86_64-apple-ios-simulator”的模块“MyCu
我有一个在 iOS 上运行良好的应用程序,但是当使用催化剂运行时,如果我在 macOS 上滑动到另一个虚拟桌面,然后再返回大约 10 次,它会间歇性地崩溃。它主要发生在 UICollectionVie
我正在使用 Xcode 开发 Apple Watch 应用程序。我想在屏幕的左上角放置一些文本,与列出时间的位置相邻。 当我将标签向上拖动到屏幕的一部分时,它会自动向下对齐。 我看到大多数 Apple
我似乎找不到在哪里设置我的 Apple Watch 应用程序的产品名称。我确实看到了产品名称选项,但更新它没有任何作用。也看不到文档中的任何内容 最佳答案 为了让您的应用程序名称在 iPhone 上的
问题:如何在我的服务器产品的安装程序中安全地包含推送通知所需的 SSL 证书? 背景:Apple 推送通知要求客户端 SSL 证书位于向 Apple 发出调用的服务器上。 我的产品采用传统的客户端/服
我已经在我的网站上实现了 Sign In with Apple。但问题是它只适用于我开发者的 Apple ID。 我尝试在同一环境中使用我的个人 Apple ID,并且登录过程也运行良好。 但是,当真
我的苹果触摸图标中的白色背景变黑了??我的白色背景不透明。该图标有一个白色三角形、红色圆圈和黑色文本。我唯一能辨认出来的是白色三角形和红色圆圈。知道是什么导致了这种情况以及如何使图标保持白色背景吗?
我正在考虑制作一个使用加速度计的 watchOS2 应用程序。如果应用程序在后台运行,它是否仍然能够接收来自加速度计或 CMMotionManager 的输入? 最佳答案 只有当 watchOS2 应
我想切换 Apple App Loader 使用的 Apple ID。 我找不到更改应用程序本身使用的帐户的方法。谷歌搜索没有带来任何有用的信息。当我启动加载程序应用程序时,它给我一个错误:“...您
我是一名优秀的程序员,十分优秀!