can't take the address of
a template without instantiating it first. To make your
example work, replace `` with `!int`, like
this:
spawn(!int, biz);
All right. It seems I cannot pass on an object. So I store the
object in a global and access it from the callback function
passed
!int(123);" out of the main
function. Compiler complains about static this. Okay, then the
code outside the main function now looks this way:
class Biz(T) {
private T value;
this(T value) {
this.value = value;
}
}
static void addToBiz(T)(Biz!T biz)
{
// ...
}
or I found this in the Internet:
https://stackoverflow.com/questions/14395018/aliases-to-mutable-thread-local-data-not-allowed
But this change, did not help:
spawn(!int, cast(shared) biz);
Then I moved "Biz!int biz = new Biz!int(123);" out of the main
function. Compiler complains abo
On Wednesday, 8 November 2023 at 16:30:49 UTC, Bienlein wrote:
Hello,
I get the error "`addToBiz(T)(Biz!T biz)` is not an lvalue and
cannot be modified" when compiling the code below. Can't find a
way how to do it right. Am a D newbie and would appreciate some
help.
[...]
static void
Hello,
I get the error "`addToBiz(T)(Biz!T biz)` is not an lvalue and
cannot be modified" when compiling the code below. Can't find a
way how to do it right. Am a D newbie and would appreciate some
help.
Thank you, Bienlein
class Biz(T) {
private T value;
this(T value)
On Wednesday, 14 September 2022 at 18:02:07 UTC, JG wrote:
[snip]
Maybe others know better but I would have thought the only way
is to use globals to do this. Often c libraries that I have
used get round this by taking a function and a pointer and then
the library calls your function
On Wednesday, 14 September 2022 at 17:23:47 UTC, jmh530 wrote:
There is a C library I sometimes use that has a function that
takes two function pointers. However, there are some
calculations that are shared between the two functions that
would get pointed to. I am hoping to only need to do
There is a C library I sometimes use that has a function that
takes two function pointers. However, there are some calculations
that are shared between the two functions that would get pointed
to. I am hoping to only need to do these calculations once.
The code below sketches out the general
On Friday, 5 November 2021 at 06:19:16 UTC, Li30U wrote:
...e.g.
```d
// ...
mixin ("ReturnType /*...snip...*/ " ~ member ~ "()(Parameters!
/*...snip...*/
```
Note the `()` before parameter list. This would make your member
function a function template, for which attributes wi
to the function. How
can one pass the attributes of a function to another function?
There's https://dlang.org/spec/traits.html#getFunctionAttributes
. Or you could define your functions as function templates,
letting the compiler infer attributes. Especially as it looks
like you function's attributes may
I am creating a templated object that is a storehouse for a heap
object and executes their methods and returns an array of
results. With the help of a template, I want to achieve this, but
I want to assign the same attributes to the function. How can one
pass the attributes of a function
On Friday, 18 September 2020 at 18:20:41 UTC, Andrey Zherikov
wrote:
How can I rewrite foo() function as a free-function that won't
cause struct copying?
I found solution:
struct S
{
int i = -1;
this(int n) {i=n;writeln(," ",i,"
",__PRETTY_FUNCTION__);}
On Friday, 18 September 2020 at 18:43:38 UTC, H. S. Teoh wrote:
Why can't you return by ref, which would also avoid the copying?
ref S foo(return ref S s) { return s; }
Compiler errors out:
onlineapp.d(9): Error: function onlineapp.foo(return ref S s) is
not callable using argument
On Fri, Sep 18, 2020 at 06:20:41PM +, Andrey Zherikov via
Digitalmars-d-learn wrote:
> How can I rewrite foo() function as a free-function that won't cause
> struct copying? My simplified code is:
>
> struct S
> {
> ref S foo() return
>
How can I rewrite foo() function as a free-function that won't
cause struct copying? My simplified code is:
struct S
{
ref S foo() return
{
return this;
}
}
void main()
{
S().foo().foo().foo();
}
If I write it like "auto foo(S s) { ret
On Tuesday, 13 December 2016 at 05:13:01 UTC, Nikhil Jacob wrote:
I mistook the original statement to mean that an impure
function can be called from a pure function with some manual
overrides.
Thank you for the clarification.
Yeah you can't do that, except in a debug statement. You can
On Tuesday, 13 December 2016 at 04:48:11 UTC, Nikhil Jacob wrote:
In the D spec for pure functions it says that a pure function
can override
"can override an impure function, but an impure function cannot
override a pure one"
Can anyone help me how to do this ?
what this means
On Tuesday, 13 December 2016 at 05:10:02 UTC, Nicholas Wilson
wrote:
On Tuesday, 13 December 2016 at 04:48:11 UTC, Nikhil Jacob
wrote:
In the D spec for pure functions it says that a pure function
can override
"can override an impure function, but an impure function
cannot override a
In the D spec for pure functions it says that a pure function can
override
"can override an impure function, but an impure function cannot
override a pure one"
Can anyone help me how to do this ?
On 1/17/16 1:27 AM, Jon D wrote:
My underlying question is how to compose functions taking functions as
arguments, while allowing the caller the flexibility to pass either a
function or delegate.
Simply declaring an argument as either a function or delegate seems to
prohibit the other
My underlying question is how to compose functions taking
functions as arguments, while allowing the caller the flexibility
to pass either a function or delegate.
Simply declaring an argument as either a function or delegate
seems to prohibit the other. Overloading works. Are there better
On Sunday, 17 January 2016 at 06:27:41 UTC, Jon D wrote:
My underlying question is how to compose functions taking
functions as arguments, while allowing the caller the
flexibility to pass either a function or delegate.
[...]
Templates are an easy way.
---
auto call(F, Args...)(F fun, auto
On Sunday, 17 January 2016 at 06:49:23 UTC, rsw0x wrote:
On Sunday, 17 January 2016 at 06:27:41 UTC, Jon D wrote:
My underlying question is how to compose functions taking
functions as arguments, while allowing the caller the
flexibility to pass either a function or delegate
On Saturday, 11 April 2015 at 19:08:50 UTC, Marco Leise wrote:
Am Sat, 11 Apr 2015 18:28:35 +
schrieb Paul D Anderson claude.re...@msnmail.com:
Is there a way to return the name of a function (a string)
from a pointer to that function?
Function pointer example from D Reference:
---
int
Am Sat, 11 Apr 2015 18:28:35 +
schrieb Paul D Anderson claude.re...@msnmail.com:
Is there a way to return the name of a function (a string) from a
pointer to that function?
Function pointer example from D Reference:
---
int function() fp;
void test()
{
static int a = 7
Paul D Anderson:
Is there a way to return the name of a function (a string) from
a pointer to that function?
Perhaps creating a string[void*] AA and initializing with all the
function pointers you care about.
Bye,
bearophile
Is there a way to return the name of a function (a string) from a
pointer to that function?
Function pointer example from D Reference:
---
int function() fp;
void test()
{
static int a = 7;
static int foo() { return a + 3; }
fp = foo;
}
void bar()
{
test();
int i = fp
Am 10.10.2013 17:45, schrieb Namespace:
On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote:
Namespace:
You mean like this?
void foo(T)(extern(C) void function(T*) func) {
}
That prints: Error: basic type expected, not extern
In theory that's correct, in practice
On 10/13/13 16:43, Benjamin Thaut wrote:
Am 10.10.2013 17:45, schrieb Namespace:
On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote:
Namespace:
You mean like this?
void foo(T)(extern(C) void function(T*) func) {
}
That prints: Error: basic type expected
Am 13.10.2013 17:17, schrieb Artur Skawina:
On 10/13/13 16:43, Benjamin Thaut wrote:
Am 10.10.2013 17:45, schrieb Namespace:
On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote:
Namespace:
You mean like this?
void foo(T)(extern(C) void function(T*) func
On 10/10/13 20:54, Dicebot wrote:
On Thursday, 10 October 2013 at 17:47:54 UTC, Namespace wrote:
import std.stdio;
void foo1(void function(void*) fp) { }
void foo2(void function(int) fp) { }
void foo3(void*) { }
void main()
{
foo1((void* ptr) = ( assert(ptr is null
On Friday, 11 October 2013 at 15:55:17 UTC, Artur Skawina wrote:
It's probably not just incompetence (the compiler is able to
figure this
out in other contexts), but a deliberate choice. Having
function types
depend on their bodies would not be a good idea. Eg
int c;
auto f
I have this function:
void foo(T)(void function(T*) test) { }
And want to call it with a C function:
foo!(SDL_Surface)(SDL_FreeSurface);
but I get:
Fehler 1 Error: foo (void function(SDL_Surface*) test) is not
callable using argument types (extern (C) void
function
On Thursday, 10 October 2013 at 14:13:47 UTC, Namespace wrote:
I have this function:
void foo(T)(void function(T*) test) { }
And want to call it with a C function:
foo!(SDL_Surface)(SDL_FreeSurface);
but I get:
Fehler 1 Error: foo (void function(SDL_Surface*) test
Am 10.10.2013 16:13, schrieb Namespace:
I have this function:
void foo(T)(void function(T*) test) { }
And want to call it with a C function:
foo!(SDL_Surface)(SDL_FreeSurface);
but I get:
Fehler1Error: foo (void function(SDL_Surface*) test) is not
callable using
On Thursday, 10 October 2013 at 14:40:09 UTC, Namespace wrote:
Example? I do not use lambdas often.
void foo(T)(void function(T*) test)
{
}
extern(C) void bar(int*) { }
void main()
{
foo( (int* a) = bar(a) );
}
I don't know to what extent IFTI can work here though.
On Thursday, 10 October 2013 at 14:28:20 UTC, Dicebot wrote:
On Thursday, 10 October 2013 at 14:13:47 UTC, Namespace wrote:
I have this function:
void foo(T)(void function(T*) test) { }
And want to call it with a C function:
foo!(SDL_Surface)(SDL_FreeSurface);
but I get
On Thursday, 10 October 2013 at 14:44:00 UTC, Dicebot wrote:
On Thursday, 10 October 2013 at 14:40:09 UTC, Namespace wrote:
Example? I do not use lambdas often.
void foo(T)(void function(T*) test)
{
}
extern(C) void bar(int*) { }
void main()
{
foo( (int* a) = bar(a) );
}
I don't
On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote:
Namespace:
You mean like this?
void foo(T)(extern(C) void function(T*) func) {
}
That prints: Error: basic type expected, not extern
In theory that's correct, in practice the compiler refuses
Namespace:
/d917/f732.d(8): Error: basic type expected, not extern
/d917/f732.d(8): Error: semicolon expected to close alias
declaration
/d917/f732.d(8): Error: no identifier for declarator void
function(T*)
It seems that even the new alias syntax doesn't support the
extern :-) Perhaps
On Thursday, 10 October 2013 at 15:15:45 UTC, bearophile wrote:
Namespace:
You mean like this?
void foo(T)(extern(C) void function(T*) func) {
}
That prints: Error: basic type expected, not extern
In theory that's correct, in practice the compiler refuses
import std.stdio;
void foo1(void function(void*) fp) { }
void foo2(void function(int) fp) { }
void foo3(void*) { }
void main()
{
foo1((void* ptr) = ( assert(ptr is null) ));
foo2((int a) = ( a + 1 )); /// Fails: Error: function foo2
(void function(int) fp) is not callable using
On Thursday, 10 October 2013 at 17:47:54 UTC, Namespace wrote:
import std.stdio;
void foo1(void function(void*) fp) { }
void foo2(void function(int) fp) { }
void foo3(void*) { }
void main()
{
foo1((void* ptr) = ( assert(ptr is null) ));
foo2((int a) = ( a + 1 )); /// Fails: Error
On 10/10/13, bearophile bearophileh...@lycos.com wrote:
Perhaps this bug is not yet in Bugzilla.
I'm pretty sure I saw it filed somewhere. Can't find it though..
Andrej Mitrovic:
I'm pretty sure I saw it filed somewhere. Can't find it though..
I have just added the new test case :-)
http://d.puremagic.com/issues/show_bug.cgi?id=6754
Bye,
bearophile
deduce the template function from arguments types.
import std.stdio;
void main()
{
test!(dchar, int)('b', 6, 'a', 54);
}
template test(Types...)
{
void test(T...)(const Types v, const T values...)
Do you need that last elipsis? I thought you didn't, but not sure
this doesn't compile? Dmd 2.062 says that it
cannot deduce the template function from arguments types.
import std.stdio;
void main()
{
test!(dchar, int)('b', 6, 'a', 54);
}
template test(Types...)
{
void test(T...)(const Types v, const T values...)
Do you need that last elipsis? I thought you
Thank you for the help. Bug report at http://d.puremagic.com/issues/
show_bug.cgi?id=10156
Can anyone tell me why this doesn't compile? Dmd 2.062 says that it
cannot deduce the template function from arguments types.
import std.stdio;
void main()
{
test!(dchar, int)('b', 6, 'a', 54);
}
template test(Types...)
{
void test(T...)(const Types v, const T values
On Wed, 22 May 2013 21:16:44 -0400, Jonathan Crapuchettes
jcrapuchet...@gmail.com wrote:
Can anyone tell me why this doesn't compile? Dmd 2.062 says that it
cannot deduce the template function from arguments types.
import std.stdio;
void main()
{
test!(dchar, int)('b', 6, 'a', 54
On 21/09/12 21:59, Ellery Newcomer wrote:
solution is to use std.traits, but can someone explain this to me?
import std.stdio;
void main() {
auto a = {
writeln(hi);
};
pragma(msg, typeof(a)); // void function()
pragma(msg, is(typeof(a) == delegate)); // nope
solution is to use std.traits, but can someone explain this to me?
import std.stdio;
void main() {
auto a = {
writeln(hi);
};
pragma(msg, typeof(a)); // void function()
pragma(msg, is(typeof(a) == delegate)); // nope!
pragma(msg, is(typeof(a) == function)); // nope!
}
On 09/21/2012 12:59 PM, Ellery Newcomer wrote:
solution is to use std.traits, but can someone explain this to me?
import std.stdio;
void main() {
auto a = {
writeln(hi);
};
pragma(msg, typeof(a)); // void function()
pragma(msg, is(typeof(a) == delegate)); // nope!
pragma(msg, is(typeof
Ellery Newcomer:
import std.stdio;
void main() {
auto a = {
writeln(hi);
};
pragma(msg, typeof(a)); // void function()
pragma(msg, is(typeof(a) == delegate)); // nope!
pragma(msg, is(typeof(a) == function)); // nope!
}
There is a subtle difference between function
On 09/21/2012 01:10 PM, Ali Çehreli wrote:
You have probably tried the following already:
pragma(msg, is(typeof(a) == void function()));
No, but that's also not very generic.
void main() {
auto a = {
return 1;
};
pragma(msg, is(typeof(a) == void function
On 09/21/2012 01:17 PM, bearophile wrote:
pragma(msg, is(typeof(a) == function)); // nope!
code in pyd suggests this evaluated to true once upon a time.
On 09/21/2012 10:41 PM, Ellery Newcomer wrote:
On 09/21/2012 01:17 PM, bearophile wrote:
pragma(msg, is(typeof(a) == function)); // nope!
code in pyd suggests this evaluated to true once upon a time.
I don't think it ever did. It is just very easy to get wrong.
On Friday, September 21, 2012 12:59:31 Ellery Newcomer wrote:
solution is to use std.traits, but can someone explain this to me?
import std.stdio;
void main() {
auto a = {
writeln(hi);
};
pragma(msg, typeof(a)); // void function()
pragma(msg, is(typeof(a) == delegate)); // nope
I was trying to write a PRNG, and I wanted to give it two seed
methods. The first is to seed from a unique UIntType, and the
other is to seed from an entire range of seeds. Like so:
void seed(UIntType value = default_seed)
{...}
void seed(Range)(Range range)
if (isInputRange!Range)
On Thu, 26 Jul 2012 19:18:21 +0200, monarch_dodra monarchdo...@gmail.com
wrote:
So here are my two questions:
1) Is what I was originally trying to do actually illegal, or is it some
sort of compiler limitation? TDPL implies this should work perfectly
fine...
Compiler limitation. It's
On Thursday, 26 July 2012 at 17:57:31 UTC, Simen Kjaeraas wrote:
On Thu, 26 Jul 2012 19:18:21 +0200, monarch_dodra
monarchdo...@gmail.com wrote:
2) Is there a correct workaround?
Exactly what you did. Though, for brevity, you would write this:
void seed(T : UIntType)(T value = default_seed)
On 07/26/2012 11:14 AM, monarch_dodra wrote:
On Thursday, 26 July 2012 at 17:57:31 UTC, Simen Kjaeraas wrote:
On Thu, 26 Jul 2012 19:18:21 +0200, monarch_dodra
monarchdo...@gmail.com wrote:
2) Is there a correct workaround?
Exactly what you did. Though, for brevity, you would write this:
)) {}
Could you call this function like this:
foo(3);
The answer is no. The compiler translates this to:
foo!(typeof(3))(3);
And typeof(3) is not uint, it's int.
In contrast,
void foo(T : uint)(T value) {}
foo(3);
is also translated to
foo!(typeof(3))(3);
and the compiler
On Thursday, 26 July 2012 at 18:21:18 UTC, Ali Çehreli wrote:
Search for specialization in the following resources:
Oh... Specialization.
What with D's ability to conditionally implement, I had
completely forgotten about specialization. So that's how it's
done in D. Cool.
Thanks a lot.
On 2012-07-26 19:57, Simen Kjaeraas wrote:
2) Is there a correct workaround?
Exactly what you did. Though, for brevity, you would write this:
void seed(T : UIntType)(T value = default_seed)
Since a template function is actually not wanted this would be the
correct workaround:
void seed
On 7/26/12, Jacob Carlborg d...@me.com wrote:
void seed () (UIntType value = default_seed)
Less typing as well.
Yep. It's funny how this works at all. I mean a template with no
template parameters is somehow still a template. :)
On Thursday, July 26, 2012 21:49:35 Andrej Mitrovic wrote:
On 7/26/12, Jacob Carlborg d...@me.com wrote:
void seed () (UIntType value = default_seed)
Less typing as well.
Yep. It's funny how this works at all. I mean a template with no
template parameters is somehow still a template.
67 matches
Mail list logo