本文整理汇总了C++中iter::chain方法的典型用法代码示例。如果您正苦于以下问题:C++ iter::chain方法的具体用法?C++ iter::chain怎么用?C++ iter::chain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iter
的用法示例。
在下文中一共展示了iter::chain方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
{
std::vector<int> ivec{1, 4, 7, 9};
std::vector<int> lvec{100, 200, 300, 400, 500, 600};
for (auto e : chain(ivec, lvec)) {
std::cout << e << std::endl;
}
}
{
std::vector<int> empty{};
std::vector<int> vec1{1,2,3,4,5,6};
std::array<int,4> arr1{{7,8,9,10}};
std::array<int,3> arr2{{11,12,13}};
std::cout << std::endl << "Chain iter test" << std::endl;
for (auto i : iter::chain(empty,vec1,arr1)) {
std::cout << i << std::endl;
}
std::cout<<std::endl;
for (auto i : iter::chain(vec1,empty,arr1)) {
std::cout << i << std::endl;
}
std::cout<<std::endl;
for (auto i : iter::chain(vec1,arr1,empty)) {
std::cout << i << std::endl;
}
std::cout<<std::endl;//modifying the range
for (auto & i : iter::chain(vec1,arr1,arr2)) {
i = 0;//0 out the whole thing
}
std::cout<<std::endl;
for (auto i : iter::chain(vec1,arr1,arr2)) {
std::cout << i << std::endl;
}
//test only works with perfect forwarding
std::cout<<std::endl;
for (auto i : chain(il{1,2,3,4,5},il{6,7,8,9},il{10,11,12})) {
std::cout << i << std::endl;
}
}
return 0;
}
示例2: v
#include <vector>
#include <iterator>
#include <utility>
#include "catch.hpp"
using iter::chain;
using itertest::SolidInt;
using itertest::BasicIterable;
using Vec = const std::vector<char>;
TEST_CASE("chain: three strings", "[chain]") {
std::string s1{"abc"};
std::string s2{"mno"};
std::string s3{"xyz"};
auto ch = chain(s1, s2, s3);
Vec v(std::begin(ch), std::end(ch));
Vec vc{'a', 'b', 'c', 'm', 'n', 'o', 'x', 'y', 'z'};
REQUIRE(v == vc);
}
TEST_CASE("chain: with different container types", "[chain]") {
std::string s1{"abc"};
std::list<char> li{'m', 'n', 'o'};
std::vector<char> vec{'x', 'y', 'z'};
auto ch = chain(s1, li, vec);
Vec v(std::begin(ch), std::end(ch));
Vec vc{'a', 'b', 'c', 'm', 'n', 'o', 'x', 'y', 'z'};