Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
March 11, 2005 Exporting Templates in Static Libraries | ||||
---|---|---|---|---|
| ||||
Hi, I'm wondering is it possible to export templates in an static library using the export commands? Do I need a factory function like a class does? Thanks |
March 12, 2005 Re: Exporting Templates in Static Libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to lkd | "lkd" <lkd_member@pathlink.com> wrote in message news:d0ta3g$rg6$1@digitaldaemon.com... > Hi, I'm wondering is it possible to export templates in an static library > using > the export commands? Do I need a factory function like a class does? > > Thanks Do you mean a template instance? A template itself is not stored in object code. Assuming you do mean template instance I would guess the rules are the same as if the code hadn't been in a template. But I don't know for sure. Can you give more details about what you are trying to do? |
March 12, 2005 Re: Exporting Templates in Static Libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | In article <d0vblr$4ha$1@digitaldaemon.com>, Ben Hinkle says... > > >"lkd" <lkd_member@pathlink.com> wrote in message news:d0ta3g$rg6$1@digitaldaemon.com... >> Hi, I'm wondering is it possible to export templates in an static library >> using >> the export commands? Do I need a factory function like a class does? >> >> Thanks > >Do you mean a template instance? A template itself is not stored in object code. Assuming you do mean template instance I would guess the rules are the same as if the code hadn't been in a template. But I don't know for sure. Can you give more details about what you are trying to do? > > Yeah, I'm just basically making a simple array template to Redim 2D, 3D, and 4D arrays. I'm trying to compile the following code into a library and use a module that just has the interface to access it. Source: module arr; template Arr(T) { //1D Array T[] Redim(int elems) {T arr[] = new T[elems]; return arr;} //2D Array T[][] Redim(int rows, int cols) { T arr[][]; arr.length = rows; for(int i = 0; i < rows; i++) { arr[i].length = cols; } return arr; } //3D Array T[][][] Redim(int x, int y, int z) { T arr[][][]; arr.length = x; for(int i = 0; i < y; i++) { arr[i].length = y; for(int j = 0; j < z; j++) { arr[i][j].length = z; } } return arr; } } Interface: module arr; template Arr(T) { //1D Array T[] Redim(int elems); //2D Array T[][] Redim(int rows, int cols); //3D Array T[][][] Redim(int x, int y, int z); } Will this work? |
March 12, 2005 Re: Exporting Templates in Static Libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to lkd | >>Do you mean a template instance? A template itself is not stored in object code. Assuming you do mean template instance I would guess the rules are the same as if the code hadn't been in a template. But I don't know for sure. Can you give more details about what you are trying to do? > >Yeah, I'm just basically making a simple array template to Redim 2D, 3D, and 4D arrays. I'm trying to compile the following code into a library and use a module that just has the interface to access it. [snip] >Will this work? Not as written. The template body has to be imported as well (by analogy in C++ a template has to be in the header files) so that the user's code can instatiate the template. If you don't want to expose the template body you can either instantiate the template with some types and expose those instances or you can write some backend routines that aren't exposed and have the exposed template call those routines. I think the simplest solution for your example is to leave the template as it is and import the source and forget about the interface module. That is keeping with D's single-source model unless there are reasons to go to a body/interface model. -Ben |
March 13, 2005 Re: Exporting Templates in Static Libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | In article <d0vu8f$na8$1@digitaldaemon.com>, Ben Hinkle says... > >>>Do you mean a template instance? A template itself is not stored in object code. Assuming you do mean template instance I would guess the rules are the same as if the code hadn't been in a template. But I don't know for sure. Can you give more details about what you are trying to do? >> >>Yeah, I'm just basically making a simple array template to Redim 2D, 3D, and 4D arrays. I'm trying to compile the following code into a library and use a module that just has the interface to access it. >[snip] >>Will this work? > >Not as written. The template body has to be imported as well (by analogy in C++ a template has to be in the header files) so that the user's code can instatiate the template. If you don't want to expose the template body you can either instantiate the template with some types and expose those instances or you can write some backend routines that aren't exposed and have the exposed template call those routines. I think the simplest solution for your example is to leave the template as it is and import the source and forget about the interface module. That is keeping with D's single-source model unless there are reasons to go to a body/interface model. > >-Ben > > Had a feeling that wouldn't work. I'll just keep the source. Thanks. |
Copyright © 1999-2021 by the D Language Foundation