Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何查看::concat 2个不同的范围视图?_C++_C++11_Range V3 - Fatal编程技术网

C++ 如何查看::concat 2个不同的范围视图?

C++ 如何查看::concat 2个不同的范围视图?,c++,c++11,range-v3,C++,C++11,Range V3,我正在尝试查看::concat 2个视图。我不明白我什么时候能做,什么时候不能做,为什么。任何帮助都会很好。这个问题听起来很相似,但并没有解决我的问题 我尝试了以下代码 #include <iostream> #include <range/v3/all.hpp> using namespace ranges; int main () { // 'string' of spaces auto spaces = view::repeat_n(' ',4);

我正在尝试查看::concat 2个视图。我不明白我什么时候能做,什么时候不能做,为什么。任何帮助都会很好。这个问题听起来很相似,但并没有解决我的问题

我尝试了以下代码

#include <iostream>
#include <range/v3/all.hpp>
using namespace ranges;

int main () {
  // 'string' of spaces   
  auto spaces = view::repeat_n(' ',4);  // 1
  // prints [ , , , ]
  std::cout << spaces  << std::endl;

  // 'string' of letters
  auto letters = view::iota('a', 'a' + 4); // 2
  // prints [a,b,c,d]   
  std::cout << letters  << std::endl;

  // 'string' from concat of letters and spaces   
  auto text = view::concat(letters,spaces); // 3
  // prints [a,b,c,d, , , , ]       
  std::cout << text  << std::endl;

  // 'vector<string>' repeat letters
  auto letter_lines = view::repeat_n(letters,3); // 4a
  // prints [[a,b,c,d],[a,b,c,d],[a,b,c,d]]
  std::cout << letter_lines  << std::endl;

  // 'vector<string>' repeat spaces
  auto space_lines = view::repeat_n(spaces,3);  // 4b
  // prints [[ , , , ],[ , , , ],[ , , ,]] 
  std::cout << space_lines  << std::endl;

  // 'vector<string>' concat 2 repeated letter_lines
  auto multi_letter_lines = view::concat(letter_lines,letter_lines); // 5
  // prints [[a,b,c,d],[a,b,c,d],[a,b,c,d],[a,b,c,d],[a,b,c,d],[a,b,c,d]]
  std::cout << multi_letter_lines << std::endl;

  // 'vector<string>' from concat of letter_lines, and spaces_lines
  // this doesn't work (well it compiles)
  auto text_lines = view::concat(letter_lines,space_lines);
  // this doesn't compile
  std::cout << text_lines  << std::endl;   //  6 ERROR
  // I expected [[a,b,c,d],[a,b,c,d],[a,b,c,d],[ , , , ],[ , , , ],[ , , , ]]

  // This works
  auto flat_text_lines = view::concat(letter_lines | view::join,
                                      space_lines | view::join); // 7
  // prints [a,b,c,d,a,b,c,d,a,b,c,d, , , , , , , , , , , , ]
  std::cout << flat_text_lines << std::endl;
  // but the structure is lost; it's a 'string', not a 'vector<string>'
}
#包括
#包括
使用名称空间范围;
int main(){
//空格的“字符串”
auto spaces=view::repeat_n(“”,4);//1
//印刷品[,]
标准::cout
note:   template argument deduction/substitution failed:
concat.cpp:21:19: note:   cannot convert ‘text_lines’ (type‘ranges::v3::concat_view<ranges::v3::repeat_n_view<ranges::v3::iota_view<char, int>>, ranges::v3::repeat_n_view<ranges::v3::repeat_n_view<char> > >’) to type ‘const ranges::v3::repeat_n_view<char>&’
      std::cout << text_lines  << std::endl;