本文整理汇总了C++中iter类的典型用法代码示例。如果您正苦于以下问题:C++ iter类的具体用法?C++ iter怎么用?C++ iter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了iter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: neiBottom
void Simplex::neiBottom(iter s) {
if(s->getBottom()->whos(s) == 0)
s->getBottom()->setBottom(s);
else if(s->getBottom()->whos(s) == 1)
s->getBottom()->setLeft(s);
else
s->getBottom()->setRight(s);
}
开发者ID:cgurps,项目名称:Extrusion,代码行数:8,代码来源:Simplex.cpp
示例2: main
int main() {
std::vector<int> vec{1, 5, 6, 7, 2, 3, 8, 3, 2, 1};
std::cout << "Greater than 4 (function pointer)\n";
for (auto i : filter(greater_than_four, vec)) {
std::cout << i << '\n';
}
std::cout << "Less than 4 (lambda)\n";
for (auto i : filter([] (const int i) { return i < 4; }, vec)) {
std::cout << i << '\n';
}
LessThanValue lv(4);
std::cout << "Less than 4 (callable object)\n";
for (auto i : filter(lv, vec)) {
std::cout << i << '\n';
}
std::cout << "Nonzero ints filter(vec2)\n";
std::vector<int> vec2 {0, 1, 2, 0, 3, 0, 0, 0, 4, 5, 0};
for (auto i : filter(vec2)) {
std::cout << i << '\n';
}
std::cout << "odd numbers in range(10) temp\n";
for (auto i : filter([] (const int i) {return i % 2;}, iter::range(10))) {
std::cout << i << '\n';
}
std::cout << "range(-1, 2)\n";
for (auto i : filter(iter::range(-1, 2))) {
std::cout << i << '\n';
}
std::cout << "ever numbers in initializer_list\n";
for (auto i : filter([] (const int i) {return i % 2 == 0;},
{1, 2, 3, 4, 5, 6, 7}))
{
std::cout << i << '\n';
}
std::cout << "default in initialization_list\n";
for (auto i : filter({-2, -1, 0, 0, 0, 1, 2})) {
std::cout << i << '\n';
}
std::cout << "ever numbers in vector temporary\n";
for (auto i : filter([] (const int i) {return i % 2 == 0;},
std::vector<int>{1, 2, 3, 4, 5, 6, 7}))
{
std::cout << i << '\n';
}
return 0;
}
开发者ID:derekrose,项目名称:cppitertools,代码行数:57,代码来源:testfilter.cpp
示例3: solve
vec pgs::solve(const vec& q, iter it) const {
vec res = vec::Zero(q.size());
it.go([&] {
real eps = 0;
res.each([&](natural i) {
real old = res(i);
res(i) -= (q(i) + M.col(i).dot(res)) / M(i, i);
// projection
res(i) = std::max(0.0, res(i));
real delta = res(i) - old;
eps += delta * delta;
});
return std::sqrt( eps );
});
return res;
}
开发者ID:Jorjor70,项目名称:meuh,代码行数:25,代码来源:pgs.cpp
示例4: 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;
}
开发者ID:dmckeone,项目名称:cppitertools,代码行数:59,代码来源:testzip_longest.cpp
示例5: 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;
}
开发者ID:benjones,项目名称:cppitertools,代码行数:42,代码来源:testchain.cpp
示例6: solve
vec solve(const vec& c, const vec& b, const iter& it) {
natural m = c.size();
natural n = b.size();
vec at = vec::Zero( m + n );
vec delta = vec::Zero( m + n );
vec eps = vec::Constant(n, it.epsilon);
vec log_eps = eps.array().log();
vec exp;
auto kkt = [&](const math::vec& dx) {
assert(!nan(dx));
vec res = vec::Zero(m + n);
res.head(m) = Q * dx.head(m) - A.transpose() * exp.cwiseProduct( dx.tail(n) );
res.tail(n) = -exp.cwiseProduct( A * dx.head(m) ) - eps.cwiseProduct(dx.tail(n));
// core::log("res:", res.transpose());
assert(!nan(res));
return res;
};
vec rhs = vec::Zero( m + n );
math::iter sub;
sub.bound = 1 + std::log(m + n);
sub.bound = it.bound;
math::natural k = 0;
it.go([&] {
exp = at.tail(n).array().exp();
assert(!nan(exp));
rhs << -c - Q * at.head(m) + A.transpose() * exp,
-exp.cwiseProduct( b - A * at.head(m) ) - eps;
assert(!nan(rhs));
delta = math::minres(kkt).solve(rhs, sub);
at += delta;
++k;
return rhs.norm();
});
return at.head(m);
}
开发者ID:Jorjor70,项目名称:meuh,代码行数:53,代码来源:test_qp.cpp
示例7: main
int main() {
std::vector<itertest::MoveOnly> mv;
for (auto i : iter::range(3)) {
mv.emplace_back(i);
}
std::vector<int> v = {1,2,3,};
for (auto i : combinations_with_replacement(v,4)) {
for (auto j : i ) std::cout << j << " ";
std::cout<<std::endl;
}
itertest::DerefByValue dbv;
std::cout << "with deref by value iterator\n";
for (auto i : combinations_with_replacement(dbv, 2)) {
for (auto j : i ) std::cout << j << " ";
std::cout<<std::endl;
}
std::cout << "with container of move-only\n";
for (auto i : combinations_with_replacement(mv,2)) {
for (auto j : i ) std::cout << j << " ";
std::cout<<std::endl;
}
std::cout << "with temporary\n";
for (auto i : combinations_with_replacement(std::vector<int>{1,2,3},4)) {
for (auto j : i ) std::cout << j << " ";
std::cout<<std::endl;
}
std::cout << "with init list\n";
for (auto i : combinations_with_replacement({1,2,3},4)) {
for (auto j : i ) std::cout << j << " ";
std::cout<<std::endl;
}
std::cout << "with static array\n";
int arr[] = {1, 2, 3};
for (auto i : combinations_with_replacement(arr,4)) {
for (auto j : i ) std::cout << j << " ";
std::cout<<std::endl;
}
}
开发者ID:evgdolgop,项目名称:cppitertools,代码行数:44,代码来源:testcombinations_with_replacement.cpp
示例8: v
#include "helpers.hpp"
#include <vector>
#include <string>
#include <iterator>
#include "catch.hpp"
using iter::dropwhile;
using Vec = const std::vector<int>;
TEST_CASE("dropwhile: skips initial elements", "[dropwhile]") {
Vec ns{1,2,3,4,5,6,7,8};
auto d = dropwhile([](int i){return i < 5; }, ns);
Vec v(std::begin(d), std::end(d));
Vec vc = {5,6,7,8};
REQUIRE( v == vc );
}
TEST_CASE("dropwhile: doesn't skip anything if it shouldn't", "[dropwhile]") {
Vec ns {3,4,5,6};
auto d = dropwhile([](int i){return i < 3; }, ns);
Vec v(std::begin(d), std::end(d));
Vec vc = {3,4,5,6};
REQUIRE( v == vc );
}
TEST_CASE("dropwhile: skips all elements when all are true under predicate",
"[dropwhile]") {
开发者ID:tempbottle,项目名称:cppitertools,代码行数:30,代码来源:test_dropwhile.cpp
示例9: TEST_CASE
};
auto dec_ten = [](MyUnMovable& el) -> MyUnMovable& {
int va = el.get_val();
el.set_val(va - 10);
return el;
};
}
TEST_CASE("filtering doesn't dereference multiple times", "[imap][filter]") {
using iter::filter;
using iter::imap;
// source data
std::array<MyUnMovable, 3> arr = {{{41}, {42}, {43}}};
auto transformed1 = imap(inc_ten, arr);
auto filtered = filter(
[](const MyUnMovable& el) { return 52 != el.get_val(); }, transformed1);
auto transformed2 = imap(dec_ten, filtered);
std::vector<int> v;
for (auto&& el : transformed2) {
// I would use imap again instead of the loop if this wasn't an imap
// test
v.push_back(el.get_val());
}
std::vector<int> vc = {41, 43};
REQUIRE(v == vc);
开发者ID:ryanhaining,项目名称:cppitertools,代码行数:30,代码来源:test_mixed.cpp
示例10: 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'};
开发者ID:,项目名称:,代码行数:31,代码来源:
示例11: main
int main() {
std::vector<itertest::MoveOnly> mv;
for (auto i : iter::range(10)) {
mv.emplace_back(i);
}
std::vector<int> empty{};
std::vector<int> v1{1,2,3};
std::vector<int> v2{7,8};
std::vector<std::string> v3{"the","cat"};
std::vector<std::string> v4{"hi","what","up","dude"};
for (auto t : product(v1, mv)) {
std::cout << std::get<0>(t) << ", "
<< std::get<1>(t) << std::endl;
}
for (auto t : product(empty,v1)) {
std::cout << std::get<0>(t) << ", "
<< std::get<1>(t) << std::endl;
}
for (auto t : product(v1,empty)) {
std::cout << std::get<0>(t) << ", "
<< std::get<1>(t) << std::endl;
}
std::cout<<std::endl;
for (auto t : product(v1,v2)) {
std::cout << std::get<0>(t) << ", "
<< std::get<1>(t) << std::endl;
}
std::cout<<std::endl;
for (auto t : product(v1,v2,v3,v4)) {
std::cout << std::get<0>(t) << ", "
<< std::get<1>(t) << ", "
<< std::get<2>(t) << ", "
<< std::get<3>(t) << std::endl;
}
std::cout<<std::endl;
for (auto t : product(v1)) {
std::cout << std::get<0>(t) << std::endl;
}
std::cout<<std::endl;
for (auto t : product(v1,v4)) {
std::cout << std::get<0>(t) << ", "
<< std::get<1>(t) << std::endl;
}
std::cout << '\n';
for (auto t : product()) { t=t; }
for (auto t : product(std::string{"hi"}, v1)) {
std::cout << std::get<0>(t) << ", "
<< std::get<1>(t) << std::endl;
}
std::cout << '\n';
int arr[] = {1,2};
for (auto t : product(std::string{"hi"}, arr)) {
std::cout << std::get<0>(t) << ", "
<< std::get<1>(t) << std::endl;
}
std::cout << '\n';
for (auto&& ij: iter::product(iter::range(10), iter::range(5))) {
std::cout << std::get<0>(ij) << "," << std::get<1>(ij) << std::endl;
}
return 0;
}
开发者ID:evgdolgop,项目名称:cppitertools,代码行数:67,代码来源:testproduct.cpp
示例12: permutations
#include <permutations.hpp>
#include "helpers.hpp"
#include <vector>
#include <string>
#include <iterator>
#include "catch.hpp"
using iter::permutations;
using IntPermSet = std::multiset<std::vector<int>>;
TEST_CASE("permutations: basic test, 3 element sequence", "[permutations]") {
const std::vector<int> ns = {1, 7, 9};
auto p = permutations(ns);
IntPermSet v;
for (auto&& st : p) {
v.emplace(std::begin(st), std::end(st));
}
const IntPermSet vc = {
{1, 7, 9}, {1, 9, 7}, {7, 1, 9}, {7, 9, 1}, {9, 1, 7}, {9, 7, 1}};
REQUIRE(v == vc);
}
TEST_CASE(
"permutations: empty sequence has one empy permutation", "[permutations]") {
const std::vector<int> ns{};
auto p = permutations(ns);
开发者ID:Alexhuszagh,项目名称:cppitertools,代码行数:31,代码来源:test_permutations.cpp
示例13: v
#include <sliding_window.hpp>
#include <vector>
#include <array>
#include <string>
#include <utility>
#include "helpers.hpp"
#include "catch.hpp"
using iter::sliding_window;
using Vec = const std::vector<int>;
TEST_CASE("sliding_window: window of size 3", "[sliding_window]") {
Vec ns = { 10, 20, 30, 40, 50};
auto sw = sliding_window(ns, 3);
auto it = std::begin(sw);
REQUIRE( it != std::end(sw) );
{
Vec v(std::begin(*it), std::end(*it));
Vec vc = {10, 20, 30};
REQUIRE( v == vc );
}
++it;
REQUIRE( it != std::end(sw) );
{
Vec v(std::begin(*it), std::end(*it));
Vec vc = {20, 30, 40};
REQUIRE( v == vc );
}
开发者ID:hoverinc,项目名称:cppitertools,代码行数:31,代码来源:test_sliding_window.cpp
示例14: v
#include <iterator>
#include "catch.hpp"
using iter::zip;
using itertest::BasicIterable;
using itertest::SolidInt;
TEST_CASE("zip: Simple case, same length", "[zip]") {
using Tu = std::tuple<int, char, double>;
using ResVec = const std::vector<Tu>;
std::vector<int> iv{10, 20, 30};
std::string s{"hey"};
double arr[] = {1.0, 2.0, 4.0};
auto z = zip(iv, s, arr);
ResVec v(std::begin(z), std::end(z));
ResVec vc{Tu{10, 'h', 1.0}, Tu{20, 'e', 2.0}, Tu{30, 'y', 4.0}};
REQUIRE(v == vc);
}
TEST_CASE("zip: One empty, all empty", "[zip]") {
std::vector<int> iv = {1, 2, 3};
std::string s{};
auto z = zip(iv, s);
REQUIRE_FALSE(std::begin(z) != std::end(z));
auto z2 = zip(s, iv);
REQUIRE_FALSE(std::begin(z2) != std::end(z2));
}
TEST_CASE("zip: terminates on shortest sequence", "[zip]") {
开发者ID:Alexhuszagh,项目名称:cppitertools,代码行数:31,代码来源:test_zip.cpp
示例15: repeat
#include <repeat.hpp>
#include "helpers.hpp"
#include <vector>
#include <string>
#include <iterator>
#include "catch.hpp"
using iter::repeat;
TEST_CASE("repeat: one argument keeps giving value back", "[repeat]") {
auto r = repeat('a');
auto it = std::begin(r);
REQUIRE(*it == 'a');
++it;
REQUIRE(*it == 'a');
++it;
REQUIRE(*it == 'a');
++it;
REQUIRE(*it == 'a');
++it;
REQUIRE(*it == 'a');
}
TEST_CASE("repeat: can be used as constexpr", "[repeat]") {
static constexpr char c = 'a';
{
constexpr auto r = repeat(c);
constexpr auto i = r.begin();
开发者ID:Alexhuszagh,项目名称:cppitertools,代码行数:31,代码来源:test_repeat.cpp
示例16: main
int main() {
std::vector<int> ivec{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4};
for (auto& i : dropwhile([] (int i) {return i < 5;}, ivec)) {
std::cout << i << '\n';
i = 69;
}
assert(ivec.at(0) == 1);
assert(ivec.at(4) == 69);
for (auto i : dropwhile([] (int i) {return i < 5;}, range(10))) {
std::cout << i << '\n';
}
for (auto i : dropwhile([] (int i) {return i < 5;},
{1, 2, 3, 4, 5, 6, 7, 8, 9})) {
std::cout << i << '\n';
}
for (auto i : dropwhile([] (int i) {return i < 5;},
std::vector<int>{1, 2, 3, 4, 5, 6, 7, 8, 9})) {
std::cout << i << '\n';
}
return 0;
}
开发者ID:derekrose,项目名称:cppitertools,代码行数:25,代码来源:testdropwhile.cpp
示例17: main
int main()
{
std::vector<int> vec = {19, 45, 32, 10, 0, 90, 15, 1, 7, 5, 6, 69};
for (auto i : sorted(vec)) {
std::cout << i << '\n';
}
const std::vector<int> cvec(vec);
for (auto i : sorted(cvec)) {
std::cout << i << '\n';
}
std::cout << "Sort by first character only\n";
std::vector<std::string> svec = {"hello", "everyone", "thanks", "for",
"having", "me", "here", "today"};
for (auto s : sorted(svec,
[] (const std::string & s1, const std::string & s2) {
return s1[0] < s2[0]; })) {
std::cout << s << '\n';
}
for (auto i : sorted(
std::vector<int>{19, 45, 32, 10, 0, 90, 15, 1, 7, 5, 6, 69})) {
std::cout << i << '\n';
}
return 0;
}
开发者ID:derekrose,项目名称:cppitertools,代码行数:28,代码来源:testsorted.cpp
示例18: main
int main()
{
for (auto i : range(10)) {
std::cout << i << std::endl;
}
for (auto i : range(20, 30)) {
std::cout << i << std::endl;
}
for (auto i : range(50, 60, 2)) {
std::cout << i << std::endl;
}
std::cout << "Negative Tests\n";
for (auto i: range(-10, 0)) {
std::cout << i << std::endl;
}
for (auto i : range(-10, 10, 2)) {
std::cout << i << std::endl;
}
std::cout << "Tests where (stop - start)%step != 0" << std::endl;
for (auto i : range(1, 10, 2)) {
std::cout << i << std::endl;
}
for (auto i : range(-1, -10, -2)) {
std::cout << i << std::endl;
}
// invalid ranges:
std::cout << "Should not print anything after this line until exception\n";
for (auto i : range(-10, 0, -1)) {
std::cout << i << std::endl;
}
for (auto i : range(0, 1, -1)) {
std::cout << i << std::endl;
}
std::cout << "Should see exception now\n";
for (auto i : range(0, 10, 0) ) {
std::cout << i << std::endl;
}
return 0;
}
开发者ID:dmckeone,项目名称:cppitertools,代码行数:47,代码来源:testrange.cpp
示例19: testcase
void testcase(std::vector<DataType> data_vec,
std::vector<SelectorType> sel_vec)
{
for (auto e : compress(data_vec, sel_vec)) {
std::cout << e << '\n';
}
}
开发者ID:dmckeone,项目名称:cppitertools,代码行数:8,代码来源:testcompress.cpp
示例20: main
int main() {
std::vector<int> vec {1,2,3,4,5,6,7,8,9};
for (auto v : powerset(vec)) {
for (auto i : v) std::cout << i << " ";
std::cout << std::endl;
}
std::cout << "with temporary\n";
for (auto v : powerset(std::vector<int>{1,2,3})) {
for (auto i : v) std::cout << i << " ";
std::cout << std::endl;
}
std::cout << "with initializer_list\n";
for (auto v : powerset({1,2,3})) {
for (auto i : v) std::cout << i << " ";
std::cout << std::endl;
}
#if 0
#endif
return 0;
}
开发者ID:derekrose,项目名称:cppitertools,代码行数:21,代码来源:testpowerset.cpp
注:本文中的iter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论