I am attempting to create a table struct with generic column types using templates. The subTable() member function subsets the table, however I am getting a template recursion error. I know where the problem is from, I don't know how to resolve it. I am modelling it after the matrix example in Ali Çehreli book: http://ddili.org/ders/d.en/templates_more.html

import std.stdio;

template ColumnTable(T...){
        struct ColumnTable{
        private:
                typeof(T) data;
                string[] names;
                struct Range{
                        size_t begin;
                        size_t end;
                }
        // This function is the source of the issue
        auto subTable(Range rowRange, Range columnRange)(){
                auto new_data = data[columnRange.begin .. columnRange.end];
auto output = ColumnTable!(new_data)(new_data); // This is the problem string[] new_names = names[columnRange.begin .. columnRange.end];
                output.setNames(new_names);
                return output;
        }
        public:
                this(T...)(T args){
                        data = args;
                        foreach(i, arg; T){
                                names ~= args[i].stringof;
                        }
                }
                void setNames(string[] names){
                        this.names = names;
                }
                void test(){
                        writeln(subTable!(Range(0, 2), Range(0, 2))());
                }
        }
}


void main(){
        string[] names = ["tariq", "sharma", "peter", "rakel"];
        double[] salary = [44.5, 32.2, 40.1, 28.1];
        int[] age = [24, 20, 22, 25, 19];
        writeln(ColumnTable!(names, salary, age)(names, salary, age));
}

Reply via email to