草庐IT

Long-range

全部标签

c++ - std::_throw_out_of_range 不知从何而来

我是C++的绝对初学者。字面上地。才过了一个星期。今天我在写一个程序来测试需要多少次迭代才能使某个数字回文。这是代码:#include#include#include/*Thisprogramcalculatesthestepsneededtomakeacertainnumberpalindromic.Itisdesignedtooutputthevaluesfornumbers1to1000*/usingnamespacestd;classnumber{public:stringvalue;voidreverse();};voidnumber::reverse(){std::reve

c++ - 如何使用 boost-range 在函数中封装自定义迭代器

最近我使用boost-range来创建满足特定条件的元素的范围。在所有情况下,我一直使用相同类型的过滤范围,因此我试图将此行为封装在外部函数中。这就是我的问题开始的地方。考虑以下示例。#include#include#includeautomyFilter=[](conststd::vector&v,intr){returnv|boost::adaptors::filtered([&r](autov){returnv%r==0;});};intmain(intargc,constchar*argv[]){usingnamespaceboost::adaptors;std::vector

c++ - 如何隐藏 range-v3 的复杂范围类型?

我需要一个类,该类的方法可以使用range-v3库返回某种范围。为了实现这样一个类,我可以在该类的定义中正确地编写它的所有内容。例如:#include#include#includeclassAlpha{public:intx;};classBeta:publicAlpha{};classFoo{public:std::sets;autor(){returns|ranges::v3::view::transform([](Alpha*a){returnstatic_cast(a);})}};但是,在我的真实案例中,Foo::r函数非常复杂,我想隐藏它的实现。特别是,实现使用了一些额外的

c++ - 使 boost::python::range 接受...一个 boost::range

我有一个C++类,它使用boost::range提供返回范围的函数来公开集合。为了使用boost::python将此类导出到python,我使用函数boost::python::range,它可以接受两个参数:返回集合的开始和结束迭代器的类的成员函数。我想避免为每个集合手动编写开始/结束对,因为我已经提供了范围。但是我无法在boost::python::range上编写一个包装器,接受一个返回范围的成​​员函数作为参数。有任何想法吗?(实际上我有不止一个类,它们是模板化的,所以我的编译器说,模板函数将模板类的成员函数的地址作为模板参数将不起作用)如果可以用g++-4.6编译,我会接受c

C++:如何使用 boost::range 查找 max_element?

我正在尝试将迭代器返回到过滤范围内的最大元素。这是我目前所拥有的:#include#include#include#include#includeusingnamespaceboost::adaptors;usingnamespaceboost::lambda;usingnamespacestd;intmain(){vectorx={100,150,200,110};autoit=boost::max_element(x|indexed(0)|filtered(_1>100));/*problemhere*/cout我希望代码打印出vectorx中具有最大元素(即2)的索引,但不幸的是

c++ - 转换 int -> unsigned long long 是否由标准定义

我无法在标准中找到关于如何将int值转换为unsignedlonglong的确切规范。指定了各种类似的转换,如int->unsigned、unsigned->int(UBifnegative)、unsignedlonglong->int等例如GCC,-1被转换为0xffffffffffffffff,而不是0x00000000ffffffff。我可以依赖这种行为吗? 最佳答案 是的,这个定义很明确,它基本上是将maxunsignedlonglong+1添加到-1,它始终是maxunsignedlonglong。这包含在draftC++

c++ - range-v 3's ` partial_sum` 如何不与非拥有引用语义相矛盾?

考虑HowdoIwritearangepipelinethatusestemporarycontainers?.问题是如何使用一些给定的函数构建一个View来转换每个元素Tstd::vectorf(Tt);同时遵守therestriction(从那里的最佳答案借用)Aviewisalightweightwrapperthatpresentsaviewofanunderlyingsequenceofelementsinsomecustomwaywithoutmutatingorcopyingit.Viewsarecheaptocreateandcopy,andhavenon-owning

c++ - range-v3 和 view_facade,不能为 ForwardRange 建模

这个简化的测试用例(按照用户手册中的示例编写)无法编译#include#includeusingv=std::vector;classrows:publicranges::view_facade{public:rows()=default;explicitrows(constv&data):it_(data.begin()),end_(data.end()){}private:friendranges::range_access;v::const_iteratorit_;v::const_iteratorend_;constint&read()const{return*it_;}boo

c# - 正确地将 C++ long 转换为 C# int

我目前正在使用以非托管C++编写的业务逻辑库开发.NETFramework4.7.2应用程序。我需要使用非托管C++。我需要使用C++项目中的逻辑,不幸的是我无法正确转换程序的输入或输出参数。当我输入42并只想返回该值时,结果是17582022。这实际上应该是42。我的C++代码如下所示:MYCore头文件:#ifdefMYCORE_EXPORTS#defineMYCORE_API__declspec(dllexport)#endif#pragmaonce#includeusingnamespacestd;extern"C"{classMYCORE_APITestClass{priva

c++ - 为什么这个 EXC_BAD_ACCESS 发生在 long long 而不是 int 上?

我遇到了一个EXC_BAD_ACCESS,其中包含一段处理数据序列化的代码。该代码仅在设备(iPhone)上失败,在模拟器上不会。它还仅在某些数据类型上失败。这是重现问题的测试代码:templatevoidtest_alignment(){//allocatememoryandrecordtheoriginaladdressunsignedchar*origin;unsignedchar*tmp=(unsignedchar*)malloc(sizeof(unsignedshort)+sizeof(T));origin=tmp;//pushdatawithsizeof2bytes*((u