模板和 std::numeric_limits
我有一个名为 Atomic 的类,它基本上是一个 _Atomic_word
加上调用 gcc 原子内置函数的方法。
class Atomic{
mutable volatile _Atomic_word value_;
public:
Atomic(int value = 0): value_(value) {}
**** blah blah ****
};
我希望 std::numeric_limits
实例化为 std::numeric_limits
(例如在我的系统上 _Atomic_word
是只是 int 的 typedef)。
有办法做到这一点吗?
I have a class called Atomic which is basically an _Atomic_word
plus methods that call the gcc atomic builtins.
class Atomic{
mutable volatile _Atomic_word value_;
public:
Atomic(int value = 0): value_(value) {}
**** blah blah ****
};
I would like std::numeric_limits<Atomic>
to instantiate to std::numeric_limits<underlying integer type>
(e.g. on my system _Atomic_word
is just a typedef for int).
Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
std::numeric_limits
将以Atomic
作为类型进行实例化,您无法破坏它。但是,您可以将std::numeric_limits
专门用于Atomic
,如下所示,您显然将
UnderlyingType
公开为Atomic
中的类型。std::numeric_limits<Atomic>
will instantiate withAtomic
as the type, you can't subvert that. However you could specialisestd::numeric_limits
forAtomic
like thiswhere you obviously expose
UnderlyingType
as a type inAtomic
.