首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >内联使用静态数据初始化器

内联使用静态数据初始化器
EN

Stack Overflow用户
提问于 2014-06-17 03:13:04
回答 1查看 73关注 0票数 0

我在cpp_dec_float源文件中找到了这个部分:

代码语言:javascript
复制
struct initializer
  {
     initializer()
     {
        cpp_dec_float<Digits10, ExponentType, Allocator>::nan();
        cpp_dec_float<Digits10, ExponentType, Allocator>::inf();
        (cpp_dec_float<Digits10, ExponentType, Allocator>::min)();
        (cpp_dec_float<Digits10, ExponentType, Allocator>::max)();
        cpp_dec_float<Digits10, ExponentType, Allocator>::zero();
        cpp_dec_float<Digits10, ExponentType, Allocator>::one();
        cpp_dec_float<Digits10, ExponentType, Allocator>::two();
        cpp_dec_float<Digits10, ExponentType, Allocator>::half();
        cpp_dec_float<Digits10, ExponentType, Allocator>::double_min();
        cpp_dec_float<Digits10, ExponentType, Allocator>::double_max();
        cpp_dec_float<Digits10, ExponentType, Allocator>::long_double_max();
        cpp_dec_float<Digits10, ExponentType, Allocator>::long_double_min();
        cpp_dec_float<Digits10, ExponentType, Allocator>::long_long_max();
        cpp_dec_float<Digits10, ExponentType, Allocator>::long_long_min();
        cpp_dec_float<Digits10, ExponentType, Allocator>::ulong_long_max();
        cpp_dec_float<Digits10, ExponentType, Allocator>::eps();
        cpp_dec_float<Digits10, ExponentType, Allocator>::pow2(0);
     }
     void do_nothing(){}
  };

我希望使用其中的一些值,如zeroonetwohalf,而不是声明全局const变量。

可以内联地使用这些值吗?如果是这样的话,是怎么做的?

示例

代码语言:javascript
复制
#include <boost/multiprecision/number.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <iostream>

namespace mp = boost::multiprecision;

int main()
{
    typedef mp::number<mp::cpp_dec_float<100>> mp_type;
    mp_type test_num("7.0710678");

    test_num *= mp_type.two();

    std::cout << test_num.str( 0, std::ios_base::scientific ) << '\n';
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-17 03:17:38

boost::multiprecision::number以公共成员类型backend_type的形式重复其第一个模板参数。所以,

代码语言:javascript
复制
test_num = test_num * mp_type::backend_type::two();
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24255168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档