模板和std :: numeric_limits [英] Templates and std::numeric_limits

查看:194
本文介绍了模板和std :: numeric_limits的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个叫Atomic的类,它基本上是一个 _Atomic_word 加上调用gcc原子内建的方法。

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 ****
};

我想要 std :: numeric_limits< Atomic> 实例化为 std :: numeric_limits<基础整数类型> (例如在我的系统上 _Atomic_word 对于int)。

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).

有办法吗?

推荐答案

p> std :: numeric_limits< Atomic> 将实例化为 Atomic 作为类型,不能颠覆。但是你可以像这样 c 专门化 std :: numeric_limits c>

std::numeric_limits<Atomic> will instantiate with Atomic as the type, you can't subvert that. However you could specialise std::numeric_limits for Atomic like this

template<>
class numeric_limits< Atomic > : public numeric_limits< Atomic::UnderlyingType >
{
};

其中你显然会将 UnderlyingType Atomic

这篇关于模板和std :: numeric_limits的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆