iterator

Removing item from generic list java? [closed]

余生长醉 提交于 2021-02-11 17:46:34
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . Improve this question I need to remove an item from a generic list in java, but I don't know how to do this. If it was a list of int, I would just set it to zero, if it was strings I would set it to null. How can I do this with a generic list, and I can't use an methods of Arraylist or anything

Difference between Python's Generators and Iterators

时光怂恿深爱的人放手 提交于 2021-02-11 16:18:17
问题 What is the difference between iterators and generators? Some examples for when you would use each case would be helpful. 回答1: iterator is a more general concept: any object whose class has a __next__ method ( next in Python 2) and an __iter__ method that does return self . Every generator is an iterator, but not vice versa. A generator is built by calling a function that has one or more yield expressions ( yield statements, in Python 2.5 and earlier), and is an object that meets the previous

Difference between Python's Generators and Iterators

青春壹個敷衍的年華 提交于 2021-02-11 16:16:05
问题 What is the difference between iterators and generators? Some examples for when you would use each case would be helpful. 回答1: iterator is a more general concept: any object whose class has a __next__ method ( next in Python 2) and an __iter__ method that does return self . Every generator is an iterator, but not vice versa. A generator is built by calling a function that has one or more yield expressions ( yield statements, in Python 2.5 and earlier), and is an object that meets the previous

Difference between Python's Generators and Iterators

岁酱吖の 提交于 2021-02-11 16:15:35
问题 What is the difference between iterators and generators? Some examples for when you would use each case would be helpful. 回答1: iterator is a more general concept: any object whose class has a __next__ method ( next in Python 2) and an __iter__ method that does return self . Every generator is an iterator, but not vice versa. A generator is built by calling a function that has one or more yield expressions ( yield statements, in Python 2.5 and earlier), and is an object that meets the previous

Why does a Python iterator need a dunder iter function?

﹥>﹥吖頭↗ 提交于 2021-02-11 14:21:33
问题 According to the documentation, a container that needs to be iterable should supply an __iter__() function to return an iterator. The iterator itself is required to follow the iterator protocol, meaning that it has to provide __iter__() that returns itself, and __next__() that provides the next item, or raises a StopIterator exception. Now I understand why both of those would be required in a container that does its own iteration, since you have to both provide an iterator and a next item:

Why does a Python iterator need a dunder iter function?

我的未来我决定 提交于 2021-02-11 14:21:13
问题 According to the documentation, a container that needs to be iterable should supply an __iter__() function to return an iterator. The iterator itself is required to follow the iterator protocol, meaning that it has to provide __iter__() that returns itself, and __next__() that provides the next item, or raises a StopIterator exception. Now I understand why both of those would be required in a container that does its own iteration, since you have to both provide an iterator and a next item:

Error C2676: std::set::const_iterator doesn't have operator+ function?

断了今生、忘了曾经 提交于 2021-02-10 20:09:42
问题 std::set<int> s = { 1,2,3,4,5 }; std::set<int> s2(s.begin(), s.begin() + 2); I want to assgin several values of s into s2 . But got below compile error: Error C2676 binary ' + ': ' std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> ' does not define this operator or a conversion to a type acceptable to the predefined It seems std::set::const_iterator doesn't have operator+ method. 回答1: It seems std::set::const_iterator doesn't have operator+ method. You are right about

Error C2676: std::set::const_iterator doesn't have operator+ function?

巧了我就是萌 提交于 2021-02-10 20:08:38
问题 std::set<int> s = { 1,2,3,4,5 }; std::set<int> s2(s.begin(), s.begin() + 2); I want to assgin several values of s into s2 . But got below compile error: Error C2676 binary ' + ': ' std::_Tree_const_iterator<std::_Tree_val<std::_Tree_simple_types<_Ty>>> ' does not define this operator or a conversion to a type acceptable to the predefined It seems std::set::const_iterator doesn't have operator+ method. 回答1: It seems std::set::const_iterator doesn't have operator+ method. You are right about

Is there any reason why there is no std::iterator for std::tuple in c++?

人走茶凉 提交于 2021-02-09 11:13:45
问题 It seems natural to have an std::iterator for std::tuple . However it is not implemented, so programmers implement there own versions. One is for example found at Jonathan Müller's Blog. Do I overlook something? Is there any reason why there is no "official version" for an tuple_iterator? 回答1: std::tuple is not a container, at least not in the sense of the standard library containers. It cannot be iterated with the usual methods because it holds objects of different types. Standard containers

Can a vector be moved and modified without an extra allocation?

孤街醉人 提交于 2021-02-08 15:10:53
问题 Consider the following code: let u: Vec<u8> = (64..74).collect(); let v: Vec<u8> = u.iter().map(|i| i + 1).collect(); u was not moved, therefore v was inevitably newly allocated. But if I do the following: let w: Vec<u8> = u.into_iter().map(|i| i + 1).collect(); u was moved and w is the name of its transformation. Here is some pseudo-code representing what I mean: mark u as "moved" for i = 0..10: u[i] += 1 w = u There is (in my opinion) no need for a new allocation, since we map a type to