Open ddobrev opened 7 years ago
More notes: Arrays do not always have a fixed size, sometimes delimiters are used instead. This basically suggests it's the user's responsibility to properly work with the array. Which leads us to approach:
The other way is to have an overload of CArray which returns an enumerator not based on a size. This way users can still look for the delimiter themselves.
In addition, we could make CArray itself IEnumerable with a default implementation which looks for null as the delimiter. GetEnumerator can have one more overload taking a lambda which determines where to end the iteration.
We could also feature a mechanism for users to manually determine how a returned array should be handled: by size or by a delimiter.
We don't know the size of an array returned from native code. There's nothing we can do except let users deal with it if they know that size. @tritao suggests we use a special class called CArray which is constructed with a single pointer and has a convenient method which takes a size and returns an iterator based on it.
There are two ways we can use this CArray:
The first way has the advantage of providing a simpler API users are familiar with. The second way has the advantage of consistency. We have so far put the decision off until the time comes to implement this.