C
Christian Schmidt
Hi all,
I'm trying to implement a std::vector-like wrapper for IList.
The hard part seems to be operator[], because it returns an unmanaged
reference. Probably I have to use pin_ptr to achieve this, but I don't
know how.
Can anybody help?
Thanks,
Christian
template <typename T>
class IListWrapper {
public:
IListWrapper(IList<T>^ _list) : list(_list) { }
T& operator[](unsigned i) { return list->default; }
const T& operator[](unsigned i) { return list->default; }
unsigned size() const { return list->Count; }
void push_back(const ItemType& item) { list->Add(item); }
protected:
gcroot<IList<ItemType>^> list;
};
void main() {
IListWrapper<double> list(gcnew List<double>(10));
list[3] = 7.5;
}
I'm trying to implement a std::vector-like wrapper for IList.
The hard part seems to be operator[], because it returns an unmanaged
reference. Probably I have to use pin_ptr to achieve this, but I don't
know how.
Can anybody help?
Thanks,
Christian
template <typename T>
class IListWrapper {
public:
IListWrapper(IList<T>^ _list) : list(_list) { }
T& operator[](unsigned i) { return list->default; }
const T& operator[](unsigned i) { return list->default; }
unsigned size() const { return list->Count; }
void push_back(const ItemType& item) { list->Add(item); }
protected:
gcroot<IList<ItemType>^> list;
};
void main() {
IListWrapper<double> list(gcnew List<double>(10));
list[3] = 7.5;
}