gpt4 book ai didi

c++ - 内联使用静态数据初始值设定项

转载 作者:行者123 更新时间:2023-11-28 02:46:25 27 4
gpt4 key购买 nike

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

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 变量。

是否可以内联使用这些值?如果是,怎么办?

Example :

#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';
}

最佳答案

boost::multiprecision::number 将其第一个模板参数重复为公共(public)成员类型 backend_type。所以,

test_num = test_num * mp_type::backend_type::two();

关于c++ - 内联使用静态数据初始值设定项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24255168/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com