当前位置: 首页>>代码示例>>C++>>正文


C++ iter类代码示例

本文整理汇总了C++中iter的典型用法代码示例。如果您正苦于以下问题:C++ iter类的具体用法?C++ iter怎么用?C++ iter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了iter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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 : filterfalse(greater_than_four, vec)) {
        std::cout << i << '\n';
    }

    std::cout << "Less than 4 (lambda)\n";
    for (auto i : filterfalse([] (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 : filterfalse(lv, vec)) {
        std::cout << i << '\n';
    }

    return 0;
}
开发者ID:grimreaper,项目名称:cppitertools,代码行数:21,代码来源:testfilterfalse.cpp

示例15: main

int main() {
    std::vector<int> vec1 = {1, 2, 3, 4, 5, 6};
    std::vector<int> vec2 = {10, 20, 30, 40, 50, 60};
    for (auto i : imap([] (int x, int y) {
    return x + y;
}, vec1, vec2)) {
        std::cout << i << '\n';
    }

    std::vector<int> vec3 = {100, 200, 300, 400, 500, 600};
    for (auto i : imap([] (int a, int b, int c) {
    return a + b + c;
},
vec1, vec2, vec3)) {
        std::cout << i << '\n';
    }

    for (auto i : imap([] (int i) {
    return i * i;
}, vec1)) {
        std::cout << i << '\n';
    }

    std::vector<int> vec{1, 2, 3, 4, 5};
    for (auto i : imap([] (int x) {
    return x * x;
}, vec)) {
        std::cout << i << '\n';
    }

    std::vector<int> vec4{1, 2, 3};
    for (auto i : imap([] (int a, int b) {
    return a + b;
}, vec, vec4)) {
        std::cout << i << '\n';
    }

    return 0;
}
开发者ID:n00btime,项目名称:cppitertools,代码行数:39,代码来源:testimap.cpp


注:本文中的iter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。