我正在读取一个wav文件,并最终将数据推送到std::array中。我需要对大块数据进行一些操作。所以我认为这是一个学习Eric Niebler的音域的好机会。
我在manual page under "custom ranges" section中看到了view_facade,但是我看到了这个问题:link。现在我不确定如何创建一个自定义的range类。有人能帮我解决这个问题吗?下面的代码显示了我试图实现的目标。
#include <iostream>
#include <range/v3/all.hpp>
using namespace ranges;
using namespace std;
struct A
{
static constexpr size_t MAX_SIZE = 100000;
A ()
{
for ( size_t i = 0; i < MAX_SIZE; i++)
data[i] = i;
size = MAX_SIZE;
}
auto begin() const { return data.begin(); }
auto end() const { return data.end(); }
std::array< double , MAX_SIZE > data;
size_t size;
};
int main()
{
A instance;
RANGES_FOR(auto chunk, view::all(instance) | view::chunk(256)) {
}
return 0;
}编译输出的一部分:
14:47:23: Running steps for project tryOuts...
14:47:23: Configuration unchanged, skipping qmake step.
14:47:23: Starting: "C:\Qt\Tools\mingw491_32\bin\mingw32-make.exe"
C:/Qt/Tools/mingw491_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/Erdem/Documents/build-tryOuts-Desktop_Qt_5_4_2_MinGW_32bit-Debug'
g++ -c -pipe -fno-keep-inline-dllexport -std=gnu++1y -pthread -lpthread -O3 -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -I"..\tryOuts" -I"." -I"..\..\..\..\range-v3-master\include" -I"D:\cvOutNoIPP\install\include" -I"..\..\..\..\Qt\5.4\mingw491_32\mkspecs\win32-g++" -o debug\main.o ..\tryOuts\main.cpp
In file included from ..\..\..\..\range-v3-master\include/range/v3/utility/iterator.hpp:28:0,
from ..\..\..\..\range-v3-master\include/range/v3/begin_end.hpp:24,
from ..\..\..\..\range-v3-master\include/range/v3/core.hpp:17,
from ..\..\..\..\range-v3-master\include/range/v3/all.hpp:17,
from ..\tryOuts\main.cpp:2:
..\..\..\..\range-v3-master\include/range/v3/utility/basic_iterator.hpp:445:22: error: 'constexpr const T& ranges::v3::basic_mixin<Cur>::get() const' cannot be overloaded
T const &get() const noexcept
^-更新
如果我添加CONFIG += c++14,代码几乎可以编译,除了下面的自动返回类型推导错误:
main.cpp:22:仅适用于-std=c++1y或-std=gnu++1y的推导返回类型
为了避免这些错误,我使用了配置+= c++1y.But,在这种情况下,我得到了一堆错误,我把它们放在了第一位。我从D语言中知道所谓的“伏地魔类型”很重要,我不想放弃返回类型的推导。我应该使用gcc中的哪个标志?
发布于 2015-11-20 11:31:58
我自己还在学习范围库,但我的理解是,公开与STL兼容的begin()和end()方法的东西可以用作视图。例如,对于您的Reader类,您可以使用
struct Reader {
// ...
auto begin() const { return rawData.begin(); }
auto end() const { return rawData.end(); }
};然后可以使用view::all()在Reader周围创建一个视图,如下所示
Reader r;
RANGES_FOR(auto chunk, view::all(r) | view::chunk(256)) {
...
}正如我所说的,我自己仍然在学习这个库,但希望这能有所帮助。
https://stackoverflow.com/questions/33818231
复制相似问题