问题标签 [boost-range]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - 如何避免在提升范围变换中复制
提升范围变换需要const &
参数中的范围。
编译并运行
如果boost::transform
's BinaryOperation
take&
而不是const &
forSinglePassRange1
那么我就不需要创建一个副本 ( auto tt = t0
) 并且只需使用to
而不是tt
. 有没有办法避免创建这种复制(同时仍然使用范围)?
提升范围变换的链接:http: //www.boost.org/doc/libs/1_53_0/libs/range/doc/html/range/reference/algorithms/mutating/transform.html
c++ - 使用 boost::any_range 有什么好处?
使用有什么好处boost::any_range
?这是一个例子:
但是使用满足 ForwardRange 概念的模板参数可以实现更高效的相同功能:
因此,我正在寻找值得使用 any_range 的场景。也许我错过了一些东西。
c++ - C++: how to find max_element using boost::range?
I am trying to return an iterator to the largest element in a filtered range. Here is what I have so far:
I expected the code to print out the index in the vector x which has the largest element (ie 2), but unfortunately it does not compile (Linux 64bit, GCC 4.7.2), the problem being in the line indicated above. The first compilation error I get from the compiler (amongst others) is the following:
/boost/tuple/detail/tuple_basic.hpp:396:36: error: assignment of read-only member ‘boost::tuples::cons::head’</p>
Any ideas what I am doing wrong? Or how else I can achieve what I am trying to do? Thanks in advance!
EDIT:
Changing the problematic line to :
seems to return the iterator to the largest element. However, is there a way to check that the iterator is within the range? Comparing it with boost::end(x) gives me an error. The only thing I can think of is to return
and check if boost::empty(another_range). Is this the only option? Thanks.
c++ - boost Range 库会成为下一个 C++ 标准的一部分吗?
我正在尝试确定是否可以开始在代码中使用基于范围的算法。如果它更有可能成为 c++ 标准的一部分,我可以在新代码中从 boost 中使用它。尽管它看起来比迭代器好得多,但它可能会让其他人难以审查和为项目做出贡献。我在这里的论文列表中没有找到。http://www.meetingcpp.com/
c++11 - 使用 boost::adaptor::indexed 的基于范围的 for 循环
C++11 基于范围的 for 循环取消引用迭代器。这是否意味着与 一起使用它没有意义boost::adaptors::indexed
?例子:
我总是可以使用计数器,但我喜欢索引迭代器。
- 是否可以通过基于范围的 for 循环以某种方式使用它们?
- 将基于范围的循环与索引一起使用的习惯用法是什么?(只是一个普通的柜台?)
c++ - 使用带有目录迭代器范围的提升范围适配器
编辑:根据乔纳森的回答,我在问题下方添加了一些解决方案
我想在给定目录中列出具有特定名称模式的常规文件。我从boost.filesystem (boost 1.53) 中提取了一个示例并对其进行了修改。这是我基本上想要的工作版本:
这会将所有以结尾的文件的条目附加.dat
到目录条目列表中。稍后我需要更多模式匹配。然后我尝试对范围做同样的事情,但失败了。我现在将任务简化为简单地复制所有也无法编译的目录条目:
我这样写是因为(来自 boost.filesystem 的 tut3.cpp)
directory_iterator::value_type 是 directory_entry
这样该副本就可以遍历范围,获取条目并将它们存储在我的列表中。但是,我从 gcc 收到很多错误消息:
我并不能真正过滤掉相关行,但我认为可以使用范围适配器过滤文件(毕竟我不只是想复制范围)。我的印象是,沿途的某个地方datFiles.begin()
不满足复制算法所需的概念。
我的一些解决方案
以下是我根据乔纳森的回答提出的一些解决方案(包括过滤)。
使用全局谓词函数bool isDatFile(const path& p)
:
不过,我更喜欢本地功能,所以我尝试了。这只是检查目录条目是否是常规文件,需要静态转换,因为is_regular_file
重载:
在范围适配器中检查正确的扩展也有点困难,所以我添加了一个本地函数:
最后是使用绑定的“单线”:
c++ - 如何迭代两个类似 STL 的容器(笛卡尔积)
我想通过 BOOST 减少以下内容
我的意思是将 2 个循环封装在一个构造中(使用 Boost.Foreach、Boost.Range、Boost.Iterator 等)。以下是我想看到的(只是想法,不完全是我想看到的)
怎么做?
编辑:顺便说一句,在python中你可以只写
c++ - c ++:使用具有二进制函数的升压范围转换适配器
假设我有两个 std::vectors x 和 y 以及一个二元函数 F。我想创建一个新对象 z(不一定是向量),其属性是 z 的第 i 个元素将 F 应用于x 和 y 的第 i 个元素。暂时我用
这当然需要为 z 分配内存。然而,我的目标是避免这种内存分配,并对转换进行惰性评估,类似于 boost::adaptors::transformed 对一元函数所做的事情。换句话说,z 的类型是某种 boost::range。有什么简单的方法可以做到这一点,还是我必须编写自己的范围类?提前致谢!
c++ - 在 C++ 接口中使用 Boost.Range
我有一个多态接口
两个范围内的元素属于相同类型(例如int
),但由my_range()
和 by返回的类型some_range()
不同,例如一个可以是 a filtered counting range
,另一个可以是 a transformed filtered counting range
。对于接口,我需要一种Range
类型。
我试过使用boost::any_range
,但性能明显更差。我想避免将范围元素复制到 avector
并返回向量。
有没有替代品any_range
和复制品?
visual-c++ - 如何将 MFC CString 与 boost 字符串算法库一起使用
初步说明:string_algo 工作得很好std::wstring
,当然,如果我需要来自 string_algo 的算法,我可以(并且确实)首先将 CString 对象转换为 std::wstring。如果我可以直接放入 CString 对象,那就太好了——与现有代码的集成会容易得多!
我想做的事:
正如这里所建议的,我尝试另外包括boost/range/mfc.hpp
让Boost.Range 适应 MFC。(虽然我并没有完全理解这个标题,但它似乎对 CString 没有任何作用,只对集合类。)
使用 Visual Studio 2005 提升 1.44.0
测试代码如下所示:
我得到的错误如下所示: