There aren't enough good samples in C++/CLI.
Any C# to C++/CLI converter should work for this (you can get a demo edition
of Instant C++ at our site - it converts C# to C++/CLI).

Signature
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
Java to VB & C#
Instant C#: convert VB to C#
Instant VB: convert C# to VB
Instant C++: VB, C#, or Java to C++/CLI
> Can someone point me to documentation or examples on how to implement an
> Enumerable interface in C++/CLI? I've found examples for C# but nothing for
> C++.
>
> I'm wrapping a native library that supplies iterators and I'd like to
> provide the .NET equivalent in the wrapper.
> Can someone point me to documentation or examples on how to implement
> an Enumerable interface in C++/CLI? I've found examples for C# but
> nothing for C++.
I found enough text in this online book to get me started, and I think I
can deduce the rest from the MSDN docs.
http://books.google.com/books?id=_DZpE7tzjKcC
http://msdn.microsoft.com/en-us/library/system.collections.ienumerable.aspx
> Can someone point me to documentation or examples on how to implement
> an Enumerable interface in C++/CLI? I've found examples for C# but
> nothing for C++.
>
> I'm wrapping a native library that supplies iterators and I'd like to
> provide the .NET equivalent in the wrapper.
something like this:
template <typename result, typename iterator>
ref class IteratorWrapper : public IEnumerable<result>
{
iterator m_begin, m_end, m_current;
public:
IteratorWrapper(iterator begin, iterator end)
: m_begin(begin), m_end(end), m_current(begin)
{}
bool MoveNext( void ) override { return m_end != ++m_current; }
property result Value {
result get() { return *m_current; }
}
};
Write a template helper function or two to get argument deduction:
template<typename T>
IEnumerable<T>^ WrapIterator(T* begin, T* end)
{
return gcnew IteratorWrapper<T, T*>(begin, end);
}
template<typename T>
value struct WrapCollection
{
template<typename T2>
IEnumerable<T>^ WrapIterator(T2* begin, T2* end)
{
return gcnew IteratorWrapper<T, T2*>(begin, end);
}
};
Now you can enumerate an array:
T[] a = new T(N);
IEnumerable<T>^ e = WrapIterator(a, a+N);
or a vector:
std::vector<T> v;
IEnumerable<T>^ e = WrapCollection<T>::WrapIterator(v.begin(), v.end());
and so on.
Ben Voigt [C++ MVP] - 07 May 2008 14:21 GMT
>> Can someone point me to documentation or examples on how to implement
>> an Enumerable interface in C++/CLI? I've found examples for C# but
[quoted text clipped - 7 lines]
> template <typename result, typename iterator>
> ref class IteratorWrapper : public IEnumerable<result>
oops, that should have been IEnumerator<result>, ditto for every other
mention of IEnumerable in my example
> {
> iterator m_begin, m_end, m_current;
[quoted text clipped - 37 lines]
> v.end());
> and so on.