On Monday, 11 October 2021 at 00:19:44 UTC, apz28 wrote:
/* Getting this error
onlineapp.d(34): Error: none of the overloads of `toString` are
callable using argument types `(Buffer)`, candidates are:
onlineapp.d(19):`onlineapp.Foo.toString()`
onlineapp.d(26):`onlineapp.Foo.toSt
import std.range.primitives: isOutputRange;
@safe:
struct Buffer
{
@safe:
void put(char c)
{}
void put(scope const(char)[] s)
{}
}
struct Foo
{
@safe:
string toString()
{return null;}
ref Writer toString(
On Sunday, 10 October 2021 at 14:00:37 UTC, Elmar wrote:
On Sunday, 10 October 2021 at 13:56:06 UTC, rempas wrote:
Actually I know about BetterC and how to call C functions from
D and visa versa. I would also disagree that "BetterC" is
almost no improvement over C as about 90% of the language
On Sunday, 10 October 2021 at 13:52:57 UTC, Elmar wrote:
The language subset "BetterC" is required for calling D
functions from C though.
This is false.
You can use any D features when calling it from C, you just need
to provide an init and term function that is called from C that
runtime in
On Sunday, 10 October 2021 at 15:15:51 UTC, drug wrote:
It would be nice if one could use pattern-matching for it in
D. Is this possible?
As I know it's impossible, but you can use a regular template:
...
If anyone is interested in pattern matching, someone provides a
package "dpmatch" whi
On Sunday, 10 October 2021 at 15:15:51 UTC, drug wrote:
As I know it's impossible, but you can use a regular template:
```d
template isPointedStaticArray(T)
{
static if (isPointer!T)
enum isPointedStaticArray =
isStaticArray!(PointerTarget!T);
else
enum isPointedStaticA
On 10.10.2021 18:01, Elmar wrote:
Well, I just wondered why your code would compile and mine wouldn't. The
`version(all)` variant will not compile on my computer with `rdmd`
because `PointerTarget` only allows pointers.
It depends on compiler version. This variant is compiled on version
2.0
On Sunday, 10 October 2021 at 15:01:17 UTC, Elmar wrote:
```d
enum isPointedStaticArray(T) = is(PointerTarget!T : P[N], P,
size_t N);
```
```d
enum isPointedStaticArray(X : P*, P) =
.isStaticArray!(PointerTarget!X);
```
`isStaticArray` is a good example that makes me ask how to
outline
On Sunday, 10 October 2021 at 14:36:50 UTC, Elmar wrote:
On Sunday, 10 October 2021 at 14:08:13 UTC, drug wrote:
You just need to check if T is a pointer:
```D
import std;
alias DA = int[];
alias SA = int[3];
alias PSA = SA*;
alias PDA = DA*;
version(all)
enum isPointedStaticArray(T) = isPoi
On Sunday, 10 October 2021 at 12:56:30 UTC, Some Guy wrote:
But I did not understand what you meant by "enums hold values,
not types". Aren't types values at compile time?
Types can be template arguments, if that's what you mean, but
they aren't values.
On Sunday, 10 October 2021 at 14:08:13 UTC, drug wrote:
You just need to check if T is a pointer:
```D
import std;
alias DA = int[];
alias SA = int[3];
alias PSA = SA*;
alias PDA = DA*;
version(all)
enum isPointedStaticArray(T) = isPointer!T &&
isStaticArray!(PointerTarget!T);
else
enum is
You just need to check if T is a pointer:
```D
import std;
alias DA = int[];
alias SA = int[3];
alias PSA = SA*;
alias PDA = DA*;
version(all)
enum isPointedStaticArray(T) = isPointer!T &&
isStaticArray!(PointerTarget!T);
else
enum isPointedStaticArray(T) = isPointer!T && is(PointerTarget!T
On Sunday, 10 October 2021 at 13:56:06 UTC, rempas wrote:
Actually I know about BetterC and how to call C functions from
D and visa versa. I would also disagree that "BetterC" is
almost no improvement over C as about 90% of the language is
there!! C++ classes are also supported
Nice :-) , y
On Sunday, 10 October 2021 at 13:52:57 UTC, Elmar wrote:
The language subset "BetterC" is required for calling D
functions from C though. Unfortunately, the runtime features of
BetterC are limited and some of C's language features aren't
availabe like C99 variable-length-arrays. "BetterC" is
On Sunday, 10 October 2021 at 13:52:57 UTC, Elmar wrote:
Hopefully it will :-) .
D has some good C support. You can call any C function from `D`
by declaring it `extern(C) `.
The language subset "BetterC" is required for calling D
functions from C though. Unfortunately, the runtime features
On Sunday, 10 October 2021 at 13:10:27 UTC, rempas wrote:
Thanks, I'm converting a library from C to D so I have to fix
all the other bugs first to see If it's working but probably it
will. Have an amazing day my friend!
Hopefully it will :-) .
D has some good C support. You can call any C
On Sunday, 10 October 2021 at 11:26:18 UTC, Elmar wrote:
Hello rempas.
This is the way:
```d
import core.stdc.stdlib : malloc, free;
extern(C) void* function(ulong) mallocPointer = &malloc;
extern(C) void function(void*) freePointer = &free;
```
`function` in the type is already a function poi
On Sunday, 10 October 2021 at 12:19:39 UTC, Adam D Ruppe wrote:
On Sunday, 10 October 2021 at 12:01:33 UTC, rempas wrote:
[...]
The comma expression in C is a combination of two things but in
the context of another thing. Well that's not very good, but
like there's statements and express
On Sunday, 10 October 2021 at 12:13:47 UTC, Elmar wrote:
Hello rempas.
The comma-operator `,` is like `;` but results in an expression
value, not a statement like `;` would. The left side of `,` is
executed like a statement and the value of the right side of
`,` is returned. Comma-expression
PS: the title is a misnomer. `is(T : P*, P) && isStaticArray!P`
doesn't either compile when inlined because `P` is not defined
when not matched.
Hey D people.
Currently in my project I have worked on a unified type interface
for all arrays which requires fixed-size arrays to be stored as
pointer (in correspondence to dynamic and associative arrays) and
allow them being allocated with any selected allocator.
There can be code like thi
On Sunday, 10 October 2021 at 12:48:49 UTC, Adam D Ruppe wrote:
On Sunday, 10 October 2021 at 12:39:17 UTC, Some Guy wrote:
I have this enum to get the type
enums hold values, not types.
try alias instead
Thanks! `alias typeOfMember(T, string member) =
typeof(__traits(getMember, T, member)
On Sunday, 10 October 2021 at 12:39:17 UTC, Some Guy wrote:
I have this enum to get the type
enums hold values, not types.
try alias instead
It actually looks like I'm having problems wherever I try to pass
that enum as a template parameter.
I have this enum to get the type of a member field in a struct:
`enum typeOfMember(T, string member) = typeof(__traits(getMember,
T, member));`
I'm having problems when I try to used it though. For example:
```D
writeln(typeOfMember!(T, member).stringof); // Doesn't work:
Error: initializer m
On Sunday, 10 October 2021 at 12:01:33 UTC, rempas wrote:
return *ret = v, 1;
The comma expression in C is a combination of two things but in
the context of another thing. Well that's not very good, but like
there's statements and expressions. Statements do something but
do not have a va
On Sunday, 10 October 2021 at 12:01:33 UTC, rempas wrote:
This is the first time I'm finding something like that. I'm
having the following code in C:
```
if (0 == (i >> 7)) {
if (len < 1) return -1;
v = i;
return *ret = v, 1;
}
```
This is part of a function that returns an `in
This is the first time I'm finding something like that. I'm
having the following code in C:
```
if (0 == (i >> 7)) {
if (len < 1) return -1;
v = i;
return *ret = v, 1;
}
```
This is part of a function that returns an `int`. When I'm
running this in C, it works. However in D, I'
On Sunday, 10 October 2021 at 10:44:15 UTC, rempas wrote:
I'm having the following C code:
```
static void* (*ppmalloc)(size_t) = malloc;
static void (*ppfree)(void*) = free;
```
I want to covert this code in D so I try to do the following:
```
static void* function(size_t)*ppmalloc = malloc;
I'm having the following C code:
```
static void* (*ppmalloc)(size_t) = malloc;
static void (*ppfree)(void*) = free;
```
I want to covert this code in D so I try to do the following:
```
static void* function(size_t)*ppmalloc = malloc;
static void function(void*)*ppfree = free;
```
If I do th
On Sunday, 10 October 2021 at 08:54:55 UTC, evilrat wrote:
That's probably depends on what you are trying to achieve.
If you want to write code-like string that looks like a code
you can use token strings
https://dlang.org/spec/lex.html#token_strings
```d
string code = q{
float sqr(float
On Sunday, 10 October 2021 at 08:48:21 UTC, Imperatorn wrote:
For simple stuff you have .stringof
Thanks!
On Sunday, 10 October 2021 at 08:28:30 UTC, rempas wrote:
Is there a way to "stringnify" in Dlang? In C we would do
something like the following:
`#define STRINGIFY(x) #x`
What's the equivalent in D?
That's probably depends on what you are trying to achieve.
If you want to write code-like s
On Sunday, 10 October 2021 at 08:28:30 UTC, rempas wrote:
Is there a way to "stringnify" in Dlang? In C we would do
something like the following:
`#define STRINGIFY(x) #x`
What's the equivalent in D?
For simple stuff you have .stringof
Is there a way to "stringnify" in Dlang? In C we would do
something like the following:
`#define STRINGIFY(x) #x`
What's the equivalent in D?
35 matches
Mail list logo