digitalmars.D - templates and functions
- Daniel (23/23) Sep 08 2011 Hi,
- Simen Kjaeraas (7/31) Sep 08 2011 A!X some_function(X)() {
- Daniel (16/16) Sep 26 2011 Thx, Simen.
- Daniel (18/18) Sep 26 2011 Sorry, minor mistakes ;)
- David Nadlinger (11/15) Sep 26 2011 You are probably looking for
Hi,
I'm trying to reimplement something like this C++ code in D:
template<Class T>
Class A {
...
}
template<Class T>
A<T> some_function() {
...
}
While I can implement the class:
class A(X) {
...
}
I fail with the function, due to the fact that I don't know/find the correct
syntax for this. The version
A(X) some_function() {
}
fails with the message
function declaration without return type. (Note that constructors are always
named 'this')
which is understandable. Any idea how the correct syntax is?
Thanx, daniel
Sep 08 2011
On Thu, 08 Sep 2011 18:53:55 +0200, Daniel <daniel.lincke pik-potsdam.de>
wrote:
Hi,
I'm trying to reimplement something like this C++ code in D:
template<Class T>
Class A {
...
}
template<Class T>
A<T> some_function() {
...
}
While I can implement the class:
class A(X) {
...
}
I fail with the function, due to the fact that I don't know/find the
correct
syntax for this. The version
A(X) some_function() {
}
fails with the message
function declaration without return type. (Note that constructors are
always
named 'this')
which is understandable. Any idea how the correct syntax is?
A!X some_function(X)() {
//...
}
--
Simen
Sep 08 2011
Thx, Simen.
Unfortunately, this works only for concretet types, but not for type parameters.
Example:
class Test(A) {
A do_nothing(A x) {
return x;
}
}
/* WORKS */
Id_Func!int test() {
return new Test!(int);
}
/* Error : undefined identifier A */
Id_Func!A test() {
return new Test!(A);
}
Sep 26 2011
Sorry, minor mistakes ;)
Again:
Thx, Simen.
Unfortunately, this works only for concretet types, but not for type parameters.
Example:
class Test(A) {
A do_nothing(A x) {
return x;
}
}
/* WORKS */
Test!int test() {
return new Test!(int);
}
/* Error : undefined identifier A */
Test!A test() {
return new Test!(A);
}
Sep 26 2011
On 9/26/11 6:00 PM, Daniel wrote:
/* Error : undefined identifier A */
Test!A test() {
return new Test!(A);
}
You are probably looking for
Test!A test(A)() …,
which is equivalent to
template test(A) {
Test!A test() { … }
}
.
Also, you might want to ask questions like this on the
digitalmars.D.learn sub-newsgroup.
David
Sep 26 2011








David Nadlinger <see klickverbot.at>