C++ interfaces and D dynamic arrays

Void-995 void995 at gmail.com
Tue Jan 2 16:48:52 UTC 2018


Hi, everyone.

I would like to have an interface that can be implemented and/or 
used from C++ in D. One of the things I would like to keep is the 
nice feature of D dynamic arrays in terms of bounding checks and 
"length" property.

Let's assume:

extern (C++) interface ICppInterfaceInD {
   ref const(int[]) indices() const;
}

class A: ICppInterfaceInD {
   private int[] m_indices;

   extern (C++) ref const(int[]) indices() const {
     return m_indices;
   }
}

All I want is keeping const correctness like in C++ so no one can 
modify m_indices and use that as property within const pointer. I 
thought it may be passed to C++ as some struct of sort:

struct wrappedArrray(T) {
   size_t length;
   T* ptr;
}

but it just don't want to be friendly with me.

How should I rethink the interface with being D-way efficient 
when using that interface inside of D?



More information about the Digitalmars-d-learn mailing list