J
john.burton
I used to use c++ a lot but recently I've been using java and pythons
and I'm finding it a lot harder to think of the best way to do
something in C++
Imagine I want a function that returns a "list" of selected users from
a big list of users, or a database or something based on some
selection.
In python I might use a generator function which yielded the next
relevent user each time it was called. In java I'd probably return an
Iterator which iterated through the selected users probably using an
instance of an inner class to implement the iterator that just iterated
through the items I wanted.
It's not so clear how I'd best do this in C++?
C++ iterators are totally different things to java iterators and it
doesn't seem at all elegent to define a new type of iterator which only
iterates though selected items.
I could create a new list and return that by value but that seems
somewhat inefficient so say the least. Returning any kind of reference
to an existing list seems fraught with memory management issues over
how to create and delete the memory.
What's the best way to do this in C++? I hope this makes some sense...
and I'm finding it a lot harder to think of the best way to do
something in C++
Imagine I want a function that returns a "list" of selected users from
a big list of users, or a database or something based on some
selection.
In python I might use a generator function which yielded the next
relevent user each time it was called. In java I'd probably return an
Iterator which iterated through the selected users probably using an
instance of an inner class to implement the iterator that just iterated
through the items I wanted.
It's not so clear how I'd best do this in C++?
C++ iterators are totally different things to java iterators and it
doesn't seem at all elegent to define a new type of iterator which only
iterates though selected items.
I could create a new list and return that by value but that seems
somewhat inefficient so say the least. Returning any kind of reference
to an existing list seems fraught with memory management issues over
how to create and delete the memory.
What's the best way to do this in C++? I hope this makes some sense...