本文整理汇总了C++中iter::zip_longest方法的典型用法代码示例。如果您正苦于以下问题:C++ iter::zip_longest方法的具体用法?C++ iter::zip_longest怎么用?C++ iter::zip_longest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iter
的用法示例。
在下文中一共展示了iter::zip_longest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
//Ryan's test
{
std::vector<int> ivec{1, 4, 9, 16, 25, 36};
std::vector<std::string> svec{"hello", "good day", "goodbye"};
for (auto e : zip_longest(ivec, svec)) {
std::cout << std::get<0>(e) << std::endl;
//has to deref iter and the optional object
std::cout << std::get<1>(e) << std::endl;
}
}
//Aaron's test
{
std::array<int,4> i{{1,2,3,4}};
std::vector<float> f{1.2,1.4,12.3,4.5,9.9};
std::vector<std::string> s{"i","like","apples","alot","dude"};
std::array<double,5> d{{1.2,1.2,1.2,1.2,1.2}};
std::cout << std::endl << "Variadic template zip_longest" << std::endl;
for (auto e : iter::zip_longest(i,f,s,d)) {
std::cout << std::get<0>(e)
<< std::get<1>(e)
<< std::get<2>(e)
<< std::get<3>(e) << std::endl;
**std::get<1>(e)=2.2f; //modify the float array
}
std::cout<<std::endl;
for (auto e : iter::zip_longest(i,s,f,d)) {
std::cout << std::get<0>(e)
<< std::get<1>(e)
<< std::get<2>(e)
<< std::get<3>(e) << std::endl;
}
std::cout << std::endl << "Try some weird range differences" << std::endl;
std::vector<int> empty{};
for (auto e : iter::zip_longest(empty,f,s,d)) {
std::cout << std::get<0>(e)
<< std::get<1>(e)
<< std::get<2>(e)
<< std::get<3>(e) << std::endl;
}
std::cout<<std::endl;
for (auto e : iter::zip_longest(f,empty,s,d)) {
std::cout << std::get<0>(e)
<< std::get<1>(e)
<< std::get<2>(e)
<< std::get<3>(e) << std::endl;
}
std::cout<<std::endl;
for (auto e : iter::zip_longest(f,s,i,d)) {
std::cout << std::get<0>(e)
<< std::get<1>(e)
<< std::get<2>(e)
<< std::get<3>(e) << std::endl;
}
std::cout<<std::endl;
}
return 0;
}
示例2: results
template <typename... Ts>
using const_opt_tuple = std::tuple<boost::optional<const Ts&>...>;
TEST_CASE("zip longest: correctly detects longest at any position",
"[zip_longest]") {
const std::vector<int> ivec{2, 4, 6, 8, 10, 12};
const std::vector<std::string> svec{"abc", "def", "xyz"};
const std::string str{"hello"};
SECTION("longest first") {
using TP = const_opt_tuple<int, std::string, char>;
using ResVec = std::vector<TP>;
auto zl = zip_longest(ivec, svec, str);
ResVec results(std::begin(zl), std::end(zl));
ResVec rc = {
TP{{ivec[0]}, {svec[0]}, {str[0]}},
TP{{ivec[1]}, {svec[1]}, {str[1]}},
TP{{ivec[2]}, {svec[2]}, {str[2]}},
TP{{ivec[3]}, {}, {str[3]}},
TP{{ivec[4]}, {}, {str[4]}},
TP{{ivec[5]}, {}, {} }
};
REQUIRE( results == rc );
}
SECTION("longest in middle") {
using TP = const_opt_tuple<std::string, int, char>;