I'm trying to write a template function like the below... is it
possible without using string mixins?
void fun( alias(?) field, alias p1, alias p2)()
{
if(p1.field)
use(p2.field);
}
called with something like
static foreach( list of fields){
fun!(field, p1, p2)();
}
I have no
Looking through Phobos code there's a bunch functions defined
with dummy template types:
void whatever(TDummy = void)( int x, ...) //TDummy is never used
Why not just use an empty template parameter list?
void whatever()(int x, ...)
My gut tells me that his is a workaround for an old
I'm trying to get a list of all the types defined in a module at
compile time (enums, structs, classes). I attempted to use the
isAggregateType trait, but it choked when it was passed modules
that had been imported (object, and the others explicitly
imported).
My next attempt was to try to
On Tuesday, 19 November 2019 at 01:55:17 UTC, Paul Backus wrote:
On Monday, 18 November 2019 at 21:48:00 UTC, Ben Jones wrote:
template notmodule(alias T){
alias notmodule = __traits(isModule, T);
}
[...]
I get errors:
```
(on the alias notmodule line) Error: trait isModule is either
The following result doesn't make sense to me... how does
isInstanceOf return false?
```
import std.traits;
import std.stdio;
import std.typecons;
auto f(T)(T t){
return Nullable!T(t);
}
void main(){
auto f3 = f(3);
writeln(typeof(f3).stringof);
Hi all,
I'm getting unexpected results while trying to process symbols
from a module, some of which are enums.
Depending on whether or not I comment out the first static
foreach loop below, fullyQualifiedName gives me different results
in the second loop.
In either case, I'm surprised I
What's the easiest way to use the FMA instruction (fused multiply
add that has nice rounding properties)? The FMA function in
Phobos just does a*b +c which will round twice.
Do any of the intrinsics libraries include this? Should I write
my own inline ASM?
On Friday, 10 January 2020 at 00:08:44 UTC, Johan wrote:
On Friday, 10 January 2020 at 00:02:52 UTC, Johan wrote:
[...]
You have to tell LDC that you are compiling for a CPU that has
FMA capability (otherwise it will insert a call to a "fma"
runtime library function that most likely you are
On Thursday, 9 January 2020 at 20:57:10 UTC, Ben Jones wrote:
What's the easiest way to use the FMA instruction (fused
multiply add that has nice rounding properties)? The FMA
function in Phobos just does a*b +c which will round twice.
Do any of the intrinsics libraries include this?
I'm trying to define some structs that contain sumTypes (using
the sumtype library) that refer to each other, but I get a
recursive template instantiation error. It looks like typically
recursion is handled in that library with the This type, but I
don't see how that would apply here. Any
On Thursday, 30 April 2020 at 16:55:36 UTC, Robert M. Münch wrote:
For ressource management I mostly use this pattern, to ensure
the destructor is run:
void myfunc(){
MyClass X = new MyClass(); scope(exit) X.destroy;
}
I somewhere read, this would work too:
void myfunc(){
auto MyClass X =
On Thursday, 7 May 2020 at 23:07:40 UTC, Ali Çehreli wrote:
The trouble seems to be when slicing the entire tuple. Even in
that case, printing a warning would not be desired in some
situations ironically in generic code where e.g. T[0..$] may
appear, which is the same as T[].
Ali
I agree
I was doing some metaprogramming where I wanted to make a slice
of a type:
alias Tbasic = int;
pragma(msg, Tbasic);
alias Tbasica = Tbasic[];
pragma(msg, Tbasica);
//prints int, int[]
And things worked fine until I attempted the same thing on what
happened to be a tuple of 1 element:
On Thursday, 7 May 2020 at 14:53:10 UTC, Steven Schveighoffer
wrote:
As others have recommended, I suggest using TaggedAlgebraic. I
recently have been using it to create an algebraic type to hold
a MYSQL value, so I can migrate the mysql-native library to be
@safe (mysql-native currently
On Tuesday, 1 September 2020 at 01:26:30 UTC, Paul Backus wrote:
Aside from using SumType directly in the function signature,
another workaround is to use a wrapper struct instead of an
alias:
struct AliasType(Args...) {
SumType!Args data;
alias data this;
}
I have an alias that looks like
static if(...){
alias AliasType = SumType!(...);
}
which I use in a template constraint for a function template:
bool func(T: AliasType!Args, Args...)(T t){ ... }
When I try to call func with an AliasType object, the argument
deduction fails with a message
On Wednesday, 30 September 2020 at 18:18:48 UTC, Basile B. wrote:
On Tuesday, 29 September 2020 at 17:08:40 UTC, Frak wrote:
Hi folks,
I've this:
/Users/frak/dlang/ldc-1.23.0/bin/../import/std/traits.d(3711):
Deprecation: function
`std.typecons.Nullable!long.Nullable.get_` is deprecated -
On Tuesday, 14 July 2020 at 20:37:53 UTC, Marcone wrote:
import std: isUpper, writeln;
void main(){
writeln(isUpper('A'));
}
Why I get this error? How can I use isUpper()?
import std.uni: isUpper; // or import std.ascii : isUpper
import std.stdio : writeln;
import std pulls in all
This seems like very surprising behavior to me. Is it a bug?
import std.typecons;
alias NT = Nullable!(Tuple!(int, double));
pragma(msg, isTuple!NT); //prints true!
Are there suffices (suffixes?) for character literals?
Is there a more succinct of writing "the literal 'x' as a dchar"
than dchar('x')?
I didn't see anything
https://dlang.org/spec/lex.html#characterliteral but figured I'd
ask the community
On Wednesday, 2 December 2020 at 12:59:52 UTC, Paul Backus wrote:
No, this is not a bug, because Nullable!T currently has an
implicit conversion to T via `alias this`. [1] However, this
implicit conversion is deprecated, and will be removed in a
future release. Once that happens, `isTuple!NT`
I'm trying to write a function template with 1 parameter whose
type is inferred, but with the other parameters variadic.
Basically, I want to do this:
auto f(Ts..., Inferred)(Inferred inf){}
and call it with f!(X,Y,Z)(w) //inferred will be typeof(w), Ts...
== (X, Y, Z)
which I can't do
On Saturday, 7 November 2020 at 21:04:19 UTC, starcanopy wrote:
void main() {
f!(int, float, char)("Hello, world!");
}
https://run.dlang.io/is/e8FGrF
Ah, I had discovered a different error when I tried that. Thanks!
I have a struct which I would like to have a public opIndex which
returns by value (so client code can't modify my internal array),
and a private version which allows the implementing code to
modify stuff with `this[whatever] = whatever`.
I tried to to write 2 versions of opIndex:
```
public
On Tuesday, 4 January 2022 at 18:26:41 UTC, Ali Çehreli wrote:
On 1/4/22 10:13 AM, Ben Jones wrote:
> So I think I need to specify that I want to explicitly
include libc when
> I link it. `-lc` didn't seem to work.
Did you add -lc and -lpthread on the linker line?
> ld build/*.o -L.
On Tuesday, 4 January 2022 at 18:45:37 UTC, Ben Jones wrote:
On Tuesday, 4 January 2022 at 18:37:25 UTC, Adam D Ruppe wrote:
On Tuesday, 4 January 2022 at 18:13:56 UTC, Ben Jones wrote:
clang -c -o source/assignment1.o source/assignment1.c
you might have better luck just telling clang to
On Tuesday, 4 January 2022 at 18:37:25 UTC, Adam D Ruppe wrote:
On Tuesday, 4 January 2022 at 18:13:56 UTC, Ben Jones wrote:
clang -c -o source/assignment1.o source/assignment1.c
you might have better luck just telling clang to link it too
like
clang source/assignment1.o -lphobos2 build/*.o
I have a somewhat unusual use case and I'm having trouble getting
everything to link properly.
I'm writing an assignment for a course I'm teaching and I've
written the skeleton code in D, and students are going to
implement one function in C, which my skeleton code will call.
The tricky
On Tuesday, 4 January 2022 at 19:14:04 UTC, Adam D Ruppe wrote:
On Tuesday, 4 January 2022 at 19:10:25 UTC, Ben Jones wrote:
All good, except now simpledisplay is segfaulting on
XDisplayConnection.get again
run it in the debugger; do a -g build and run it in gdb or lldb
and do check the
On Tuesday, 4 January 2022 at 21:34:46 UTC, Adam D Ruppe wrote:
On Tuesday, 4 January 2022 at 21:22:26 UTC, Ben Jones wrote:
* frame #0: 0x
That's null, meaning the library wasn't loaded.
simpledisplay actually doesn't need -lX11 since it always
dynamic loads the
On Tuesday, 4 January 2022 at 20:28:00 UTC, Ben Jones wrote:
On Tuesday, 4 January 2022 at 19:14:04 UTC, Adam D Ruppe wrote:
[...]
Crashes on `display = XOpenDisplay(displayName);` :
```
* thread #1, queue = 'com.apple.main-thread', stop reason =
EXC_BAD_ACCESS (code=1, address=0x0)
*
On Wednesday, 5 January 2022 at 03:38:54 UTC, Tejas wrote:
On Tuesday, 4 January 2022 at 18:13:56 UTC, Ben Jones wrote:
The tricky part is that the lab machines that the students
will be using don't have a D compiler installed (they're
Fedora machines, and I didn't see a dmd package in their
I'm trying to use Adam's simpledisplay on a mac with XQuartz
which is installed + running. When I try to create a window, it
crashes when calling `XDisplayConnection.get()`. I'm just
building dub and have added `"arsd-official:simpledisplay"` as a
dependency. Before I installed XQuartz, it
On Tuesday, 16 November 2021 at 14:38:47 UTC, Adam Ruppe wrote:
1) run xquartz separately to ensure it is up
2) set hte DISPLAY=:0 environment variable before starting the
sdpy app
Adding DISPLAY:0 fixed it, thanks. If I get time, I'll take a
look at the objective C stuff, but that's a big
On Wednesday, 8 December 2021 at 17:44:47 UTC, Adam D Ruppe wrote:
On Wednesday, 8 December 2021 at 17:19:32 UTC, Ben Jones wrote:
Gotcha, thanks. I tried using `S.field` before and that didn't
work, `__traits(child)` was the key.
Since I reuse the field a few times I tried to alias the
On Wednesday, 8 December 2021 at 18:23:25 UTC, Adam D Ruppe wrote:
On Wednesday, 8 December 2021 at 18:07:32 UTC, Ben Jones wrote:
I went with the mixin approach, which seems to work fine except
that I couldn't declare the mixin inside a function, so the
definition is pretty far away from
On Wednesday, 8 December 2021 at 17:29:19 UTC, H. S. Teoh wrote:
On Wed, Dec 08, 2021 at 05:19:32PM +, Ben Jones via
Digitalmars-d-learn wrote:
I'm trying to use a property member of a struct as a template
alias parameter and I don't really understand how to fix the
error message I'm
I'm trying to use a property member of a struct as a template
alias parameter and I don't really understand how to fix the
error message I'm seeing (I also tried the simpler case of a
plain struct member, and that didn't work either). Is what I'm
trying to do possible? It seems like maybe
On Wednesday, 8 December 2021 at 17:19:32 UTC, Ben Jones wrote:
I considered just having a `ref int` parameter, but I didn't
think that would work if I was actually calling a property
function, rather than just modifying a struct member.
I also tried to use a template mixin, but couldn't
I'm trying to build a wrapper around a lib written in C by having
importC compile the .c files, and then providing a nice D API on
top. My dub config file seems to be finding the C files to
compile without issue, but it's not passing the include dirs for
the preprocessor to find headers. Is
On Friday, 22 July 2022 at 16:57:21 UTC, Steven Schveighoffer
wrote:
It's specifically undefined behavior by the spec, but in
practice, I think it will work, as long as the block you have
isn't marked as not allowing interior pointers.
See:
I'm looking to store a pointer to one of 2 unrelated (no
inheritance relationship) classes and use the LSb to track which
type I have. Is this going to cause any problems with the GC?
For one of the classes I'll have a "pointer" to 1 byte past the
start of the object. It seems like
On Tuesday, 10 May 2022 at 05:45:25 UTC, ag0aep6g wrote:
`x` is a type, period.
You can use void initialization to declare values of types that
don't have an `init` value: `x value = void;`
As for an alternative to the brute force `__traits(compiles,
...)`, you can check if `T.init` is a
On Tuesday, 10 May 2022 at 16:05:15 UTC, H. S. Teoh wrote:
Using wrapper structs, etc., for this is IMO total overkill.
Just use an enum for your token types. Something like this
would suffice:
That's basically what sumtype is going to do for me, but
(hopefully) more safely. Also, the token
On Wednesday, 11 May 2022 at 12:29:05 UTC, Basile B. wrote:
How about being more explicit in the UDA ?
The idea would be to associate the enum value to a type or not:
I think that could work but would require some major changes to
my existing code. Also, I think I'd prefer:
```
@Token{
I have a struct template that takes an alias parameter and I'm
trying to distinguish between type parameters and enum values.
std.traits.isType works for this except for one edge case:
```
import std.traits;
import std.stdio;
struct S{}
enum x;
enum y = 5;
struct Wrap(alias T) {
static
On Monday, 9 May 2022 at 21:58:59 UTC, Ali Çehreli wrote:
On 5/9/22 14:24, Ben Jones wrote:
> Is there a trait that can tell if you
> can initialize a variable of a certain type?
Not answering that question but the 'is' expression seems to
work in this case:
static if(is (T)) {
On Thursday, 25 August 2022 at 15:19:56 UTC, Steven Schveighoffer
wrote:
On 8/25/22 10:44 AM, MichaelBi wrote:
On Thursday, 25 August 2022 at 14:37:01 UTC, Steven
Schveighoffer wrote:
On 8/25/22 10:19 AM, MichaelBi wrote:
Is there a reason you want to use DMD specifically? If you use
On Friday, 9 September 2022 at 13:40:45 UTC, Alain De Vos wrote:
I find documentation of vibe.d between worse and bad, while the
framework is relative OK.
There are a few good links on the internet.
I post two of them.
Feel free to add other web links in order to increase our
knowledge.
On Tuesday, 13 September 2022 at 14:06:42 UTC, Injeckt wrote:
Hi, I'm trying to check if destructor has been called, but when
I'm deleting class object I didn't get any calls from
destructor.
myclass.d
~this() {
this.log("\nDestructor\n");
this._free_trash();
}
On Friday, 14 October 2022 at 17:41:42 UTC, Yura wrote:
...
Check out MIR https://github.com/libmir
On Friday, 20 January 2023 at 18:58:16 UTC, seany wrote:
Hi I am googling to find some vibe.d and mongoDB tutorial. Are
their some available? Thank you
There's a couple of examples like this one in main vibe repo in
the examples directory:
I'm trying to update an app from an older version of Vibe.d to a
newer version that supports modern Mongo (0.9.7-alpha2)
I'm replacing an older call to collection.update() to
collection.updateOne() instead. I had to change the options
parameter to an updated struct, and it now compiles, but
On Friday, 21 April 2023 at 20:46:36 UTC, Ben Jones wrote:
I'm trying to update an app from an older version of Vibe.d to
a newer version that supports modern Mongo (0.9.7-alpha2)
[...]
Update: https://github.com/vibe-d/vibe.d/pull/2729
On Saturday, 11 February 2023 at 05:02:49 UTC, Steven
Schveighoffer wrote:
Reported
https://issues.dlang.org/show_bug.cgi?id=23687
Assuming this is a compiler bug and it gets fixed, does this seem
like something worth trying to add to std.range?
I'm trying to write a range adaptor for linked list types. The
range type seems to work OK, but my helper function to deduce the
node type has a compiler error. My hunch is that `nextField`
loses its association with T when I'm trying to pass it as a
template parameter inside the helper
On Thursday, 25 May 2023 at 00:39:02 UTC, anonymouse wrote:
I think I misunderstood what was being asked here.
My particular use case is to step using * rather than +, so
something like for(i = 1; i < N; i *= 2). `sequence` worked for
what I was doing well enough
On Wednesday, 14 June 2023 at 09:28:57 UTC, Cecil Ward wrote:
I’m thinking that I might had to end up writing a partial,
rather rough parser for parts of the D language. Could I get
some suggestions for help that I might find in the way of
software components? D has a very powerful regex
58 matches
Mail list logo