Range-based for loop for ObservableCollection
In the C++ SDK, the range-based for loop for ObservableCollection is not implemented.
Is there a specific reason for this, or is it simply not implemented?
Is there a specific reason for this, or is it simply not implemented?
Re: Range-based for loop for ObservableCollection
Yeah, I would love to have this too, but the problem is that ObservableCollection is a pointer, so the syntax would be a bit awkward and I am not sure that's good. Something like:
What do you think?
Code: Select all
for (T* item: *collection) {}
Re: Range-based for loop for ObservableCollection
Code: Select all
namespace Noesis
{
template<typename T>
class ObservableCollectionIterator
{
public:
using iterator_category = std::forward_iterator_tag;
using value_type = T*;
using difference_type = std::ptrdiff_t;
using pointer = T**;
using reference = T*&;
ObservableCollectionIterator(ObservableCollection<T>* collection, uint32_t index)
: mCollection(collection), mIndex(index)
{
}
T* operator*() const { return mCollection->Get(mIndex); }
ObservableCollectionIterator& operator++() { ++mIndex; return *this; }
bool operator==(const ObservableCollectionIterator& other) const
{
return mIndex == other.mIndex;
}
private:
ObservableCollection<T>* mCollection;
uint32_t mIndex;
};
template<typename T>
ObservableCollectionIterator<T> begin(ObservableCollection<T>* collection)
{
return { collection, 0 };
}
template<typename T>
ObservableCollectionIterator<T> begin(const ObservableCollection<T>* collection)
{
return { collection, 0 };
}
template<typename T>
ObservableCollectionIterator<T> begin(Ptr<ObservableCollection<T>>& collection)
{
return { collection->GetPtr(), 0 };
}
template<typename T>
ObservableCollectionIterator<T> begin(const Ptr<ObservableCollection<T>>& collection)
{
return { collection.GetPtr(), 0 };
}
template<typename T>
ObservableCollectionIterator<T> end(ObservableCollection<T>* collection)
{
return { collection, (uint32_t)collection->Count() };
}
template<typename T>
ObservableCollectionIterator<T> end(const ObservableCollection<T>* collection)
{
return { collection, (uint32_t)collection->Count() };
}
template<typename T>
ObservableCollectionIterator<T> end(Ptr<ObservableCollection<T>>& collection)
{
return { collection.GetPtr(), (uint32_t)collection->Count()};
}
template<typename T>
ObservableCollectionIterator<T> end(const Ptr<ObservableCollection<T>>& collection)
{
return { collection.GetPtr(), (uint32_t)collection->Count() };
}
}Code: Select all
for(auto item : collection) {}Re: Range-based for loop for ObservableCollection
Please, create a ticket for this. Thank you!
Re: Range-based for loop for ObservableCollection
Thanks for the ticket. We didn’t have time to address this in 3.2.8, but it’s planned for the next version.
One of the reasons we haven’t modified this API yet is because we have long-term plans to improve the Reflection architecture to support using custom containers (such as std::vector) in MVVM.
One of the reasons we haven’t modified this API yet is because we have long-term plans to improve the Reflection architecture to support using custom containers (such as std::vector) in MVVM.
Who is online
Users browsing this forum: Bing [Bot] and 3 guests