草庐IT

tuple_pi

全部标签

c++ - 将 std::variant 转换为模板类实例的 std::tuple

transform_v2t下面代码中的函数构建了模板类A实例的元组:templatestructA{Tval;};templateclassT,std::size_t...index>inlineconstexprautotransform_v2t(std::index_sequence){returnstd::make_tuple(T>()...);}templateclassT>inlineconstexprautotransform_v2t(){returntransform_v2t(std::make_index_sequence>());}typedefstd::varian

c++ - pi 计算的 OpenMP 并行化速度慢或错误

我在并行化我的蒙特卡洛方法来计算圆周率时遇到了问题。这是并行化的for循环:#pragmaompparallelforprivate(i,x,y)schedule(static)reduction(+:count)for(i=0;i问题是,如果我使用schedule(static),它会低估pi,如果我使用schedule(dynamic),它会比串行实现慢。我究竟做错了什么?我尝试了其他方法来修复它(例如:UsingOpenMPtocalculatethevalueofPI),但它仍然比串行实现慢得多。提前致谢 最佳答案 假设您正

c++ - Raspberry Pi ARM Float ABI 兼容性

我目前正在我的Ubuntu机器上对RaspberryPi执行一些交叉编译测试。我目前的理解是RaspberryPi支持硬件浮点,默认的RaspbianOS镜像是使用硬件浮点(armhf)构建的。正确吗?如果我使用“arm-linux-gnueabi”工具链(未指定任何ARM标志)构建我的应用程序,那么我的应用程序将使用软浮点ABI。正确吗?在这种情况下,我的所有依赖项也必须使用相同的ABI才能正确链接。正确吗?如果我的应用程序使用软浮点ABI,那么我的应用程序肯定链接到软浮点ABI共享标准库。当我在我的RaspberryPi上运行我的应用程序时,一切都按预期工作。如果Raspbian使

c++ - 在 boost :multiprecision 中定义多精度 pi

我在boost::multiprecision中需要任意(但固定)精度的pi(3.1415...)。boost::math::constants中的常量最多只能定义固定位数,如thisanswer中指出的那样,所以我需要自己计算。因为我经常使用这个数字并且有很多数字,所以我想在运行时只计算一次。拥有它的简单而快速的方法是什么?我想用typedefnumber>mpfloat;//PRECISIONiscompiletime.constintPI=atan(mpfloat(1))*4;但我不确定这是不是它的常见习语。 最佳答案 在c+

c++ - 带有模板参数的 make_tuple 不编译

考虑这段代码:#includeintmain(){inti;longk;autotup1=std::make_tuple(i);//Compilesautotup2=std::make_tuple(k);//Compilesautotup3=std::make_tuple(i);//Doesnotcompileautotup4=std::make_tuple(i+0);//Compilesautotup5=std::make_tuple(i);//Compiles}为什么autotup3=...不编译?显然,make_tuple(...)想要一个右值引用作为它的参数;但是为什么?(我使

c++ - 完美转发和 std::tuple

考虑以下代码:#include#include#include//A.templatevoidf(constchar*msg,Args&&...args){std::coutvoidf(constchar*msg,std::tuple&&t){std::coutg()const{returnstd::make_tuple(2,4,12345);}};intmain(){f("First",2,5,12345);f("Second",std::make_tuple(2,5,12345));boothe_boo;f("Third",the_boo.g());f("Fourth",std::

c++ - boost::bind 不适用于 boost::tuple::get<N>()

我正在尝试使用boost::bind和STL与boost::tuple,但每次我尝试编译时都会收到以下错误。error:callofoverloaded‘bind(,boost::arg&)’isambiguous你知道我在这里做错了什么吗?为什么只针对boost::arg?谢谢AFG#include#include#include#include#include#include#includeintmain(intargc,constchar**argv){usingnamespaceboost::assign;typedefboost::tupleeth_array;std::ve

c++ - 如何创建 std::tuple 的别名?

我正在学习C++,我想知道如何为std::tuple创建别名。我想做你可能用std::tuple做的事情,但使用另一个名字。可能吗?谢谢。 最佳答案 templateusingmy_tuple=std::tuple;Livedemolink. 关于c++-如何创建std::tuple的别名?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/25545334/

c++ - 计算 pi 的位数

我已经使用GMP库和C++编写了Gauss-Legendre算法的实现代码来计算pi的位数。它有正确的输出,但问题是我不知道输出在哪一点“变坏”,因为我必须在代码中指定精度。这是使用64位精度的输出:3.141592653589793238*35*,最后两位数字不正确。我的问题是,如果我想要pi的n位,b的精度是多少,算法的迭代次数是多少i需要吗?谢谢 最佳答案 Gauss-Legendre算法(又名AGM算法)要求全程精确。与牛顿法迭代不同,AGM迭代不能self纠正。因此,您从一开始就需要完全精确。此外,您还需要额外的保护数字。

c++ - 将 std::tuple<T...> 转换为 T

所以我得到了一个std::tuple,我想创建一个接受T...的函数指针,目前这就是我所拥有的;templateusingFunctionPointer=void(*)(Arguments...);usingFunctionPtr=FunctionPointer::type,typenamestd::tuple_element::type,typenamestd::tuple_element::type>;但是,如果不手动输入0,...,tuple_size::value中的每个索引,我似乎无法找到执行此操作的方法。.FunctionPtr在上下文中定义,其中V=std::tuple(