1. How can I separate class methods from the declaration block? And how can I implement them in a separate module?

module frame;
class Test
{
public:
        int x;
        this();
}

Test.this()
{
        x = 34;
} // does not work

In this scenario I would like to take the constructor to a different module called "construct".


2. For practice, I want to implement a few containers in native D using DUB. The project aims to create libraries for different data structures. I'm thinking that I should make packages for different containers and have them under source/. For example, source/forward_list, source/queue, source/set etc.

Would you like to suggest me a good project structures for this? Imagine I am making a package called forward_list. Under the directory forward_list/, I have modules.d that imports dedicated modules for useful methods like push_back, insert_after, front, sort, merge etc. Is it an acceptable practice to declare classes in package.d? So it becomes

//module package.d;
class forward_list
{
public:
        int x;
        merge();

        this(){}
        this(int x){ this.x = x; }
}

//module merge.d;
import package.d

forward_list.merge(Object o){
        //..
}

Reply via email to