-
Notifications
You must be signed in to change notification settings - Fork 143
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
Derive iterators from std::iterator #408
Derive iterators from std::iterator #408
Conversation
@@ -189,7 +190,7 @@ namespace modm | |||
* | |||
* \todo check if a simpler implementation is possible | |||
*/ | |||
class const_iterator | |||
class const_iterator : public std::iterator<std::bidirectional_iterator_tag, T> |
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.
std::iterator
has been deprecated in C++17. See this for more information. Please use the recommended method from the article with type aliases in the iterator class.
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.
Didn't it's deprecated. I'm building in C++17 and didn't get any warning...
@@ -258,7 +259,7 @@ namespace modm | |||
/** | |||
* \brief Forward iterator | |||
*/ | |||
class iterator | |||
class iterator : public std::iterator<std::forward_iterator_tag, T> |
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.
It would make sense to have a random access iterator here, but that would require extending the iterator class with operators []
, +
, -
, +=
, -=
. Otherwise things like std::sort don't work which need random access.
These container implementations were originally written for xpcc before we had a standard library on all platforms and when there was no C++11. Now modm uses the standard library which provides vector, list and forward_list. I don't see why someone should prefer the modm equivalents for these three cases. I'm not sure it's worth the effort to fix them.
@salkinium We should consider to deprecate or remove the containers the standard library already provides.
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.
I would strongly prefer either using the std libc++ and/or integrating a third party one like ETL. Definitely not interested in fixing/maintaining our containers, that's something that other libs can do way better.
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.
Is there a specific reason for using these containers instead of the standard ones, @mikewolfram? Avoiding heap? Size/efficiency concerns? What do these containers do better?
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.
Well, since I expected those containers to be used in modm, I wanted to use them as well for keeping it simple.
I've been already looking into ETL and was thinking about using some of it.
I'd still like to merge this, perhaps after clarification about the deprecation, since it solves a real problem without breaking anything, even if we plan to deprecate this at some undetermined point in the future. |
If you'd ask me, maybe take this PR as is. Even the std::iterator class is marked deprecated, the compiler doesn't warn about it. Once the containers are replaced with STL or ETL, the "problem" would be gone. |
I'm inclined to agree, I was asking @chris-durand to clarify, since he knows more about C++ than me. |
You could merge this as is. std::iterator was deprecated because it can be confusing to read if you use all 5 template parameters. This is not an issue here. |
If I'd decide to work on replacing modm with STL/ETL containers, what would be your preferred idea? Add ETL as a module in ext folder, configure it via settings in project.xml file? And then let the user decide whether to use STL or ETL? Having typedefs to STL or ETL depending on that decision? |
There are several ways to add ETL: You could do it only in your project, by adding the include path collector value in <lbuild>
<collectors>
<collect name="modm:build:path.include">../path/to/etl</collect>
</collectors>
</lbuild> Or if you wanted to intergrate it into modm, you would add it into modm has a bit of an issue where its use of C++ library code hasn't been updated in a long time, there's currently not a lot of stdc++ library code used (except for template/compile time stuff) and thus not a lot to replace here. A lot of (pointer, size) is passed around manually in the HAL, not sure what the exact implications of using I would like to see more of the C++ std lib integrated into modm, just sometimes a bit unclear what the trade-offs are in terms of speed/code size. That's where I see ETL being useful, albeits it's still targeting C++03 which is getting quite old by now. |
Oh and definitely no shimming of ETL to be STL compatible, it's already difficult to impossible to actually port the stdlib (Filesystems anyone? No? What about time/calendar? Ok, but threading? RLY?) so I'm not keen on mixing this up even more. Any modules in modm would explicitly depend on |
…algorithms from STL.
09ae44a
to
f12252b
Compare
Anything come of this? During my work on #395, I've come to realize just how limited the STL containers are (lacking a fixed size std::queue for example) and how out-of-date our containers are (lacking |
Not yet. I'm busy to meet the next project milestone and have to delay such things until later this year. |
...to make the containers work with algorithms from STL.
Currently modm containers won't work with algorithms like std::remove_if(). This fix resolves it.