-
Notifications
You must be signed in to change notification settings - Fork 1
comments. #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
comments. #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,32 +7,44 @@ using std::endl; | |
| using std::vector; | ||
| using std::for_each; | ||
|
|
||
| struct element { | ||
| //TODO: add all the relevant constructors. | ||
| double& x() { return points_.get_x()[index_]; } | ||
| double& y() { return points_.get_y()[index_]; } | ||
| Points* points_ = nullptr; | ||
| //TODO: perhaps make this private and give iterator friendship relations | ||
| std::size_t index_ = 0; | ||
| }; //end struct element | ||
|
|
||
| class Points { | ||
| typedef std::vector< double> Vector; | ||
| public: | ||
|
|
||
| typedef vector<double>::size_type size_type; | ||
| typedef typename Vector::size_type size_type; | ||
|
|
||
| class iterator { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ryan, do you think the iterator class should be defined outside of the container class?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I do. |
||
| public: | ||
| typedef iterator self_type; | ||
| typedef iterator value_type; | ||
| typedef iterator& reference; | ||
| typedef iterator* pointer; | ||
| //This can be a bit messy, strongly suggest using the boost::iterator_facade interface | ||
| //operator* returning the iterator is akward imho. Its not natural to write ********x in code and | ||
| //have it do what your code did.. | ||
| typedef element value_type; | ||
| typedef element& reference; | ||
| typedef element* pointer; | ||
|
|
||
| //typedef std::forward_iterator_tag iterator_category; | ||
| typedef vector<double>::difference_type difference_type; | ||
| iterator(Points& points, Points::size_type index) : | ||
| points_(points), index_(index) { } | ||
| self_type operator++() { self_type i = *this; index_++; return i; } | ||
| self_type operator++(int junk) { index_++; return *this; } | ||
| iterator& operator*() { return *this; } | ||
| iterator* operator->() { return this; } | ||
| bool operator==(const self_type& rhs) { return index_ == rhs.index_; } | ||
| bool operator!=(const self_type& rhs) { return index_ != rhs.index_; } | ||
| double& x() { return points_.get_x()[index_]; } | ||
| double& y() { return points_.get_y()[index_]; } | ||
| iterator(Points& points, Points::size_type index) : elt_(points, index){ } | ||
| //good | ||
| value_type operator++() { self_type i = *this; index_++; return i; } | ||
| reference operator++(int junk) { index_++; return *this; } | ||
| //operator--? | ||
| iterator& operator*() { return elt; } | ||
| //This should not be necessary, the language implements this for you.. | ||
| //iterator* operator->() { return this; } | ||
| bool operator==(const self_type& rhs) { return elt == rhs.elt; } | ||
| bool operator!=(const self_type& rhs) { return elt != rhs.elt; } | ||
| private: | ||
| Points& points_; | ||
| Points::size_type index_; | ||
| element elt; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea here also! thanks |
||
| }; | ||
|
|
||
| size_type size() const { return x.size(); } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I think it makes more sense to do this.