Re: Setting import paths - project (dub) and also rdmd or dmd

2022-10-01 Thread David via Digitalmars-d-learn
Thank you Steven and Christian. I had a look at both those methods, creating a local dmd.conf file almost worked but it wasn't a simple modification, I was hoping it would be as simple as just adding the extra path but it seems that I needed to add the whole path from the existing dmd.conf

Re: Poste some interesting vibe.d webpages

2022-09-20 Thread David via Digitalmars-d-learn
On Wednesday, 14 September 2022 at 19:34:01 UTC, Alain De Vos wrote: Although the framework is good. There is no community. Or general acceptance. Which is a pitty. Currently I ask myself how to do "sessions" with vibe.d. Hi Alain, I'm new to D and looking at vibe as well but I'm not as far

Setting import paths - project (dub) and also rdmd or dmd

2022-09-19 Thread David via Digitalmars-d-learn
Hi, New to D (and enjoying the learning..) I've probably missed something obvious but I'm slightly confused with the best way to achieve a simple build. I like to keep my reusable modules in a directory outside of the project directory so I can use them on another project for example. I

Re: Dynamically allocated Array mutable but non resizeable

2021-06-15 Thread Jalil David Salamé Messina via Digitalmars-d-learn
On Monday, 14 June 2021 at 17:34:00 UTC, Steven Schveighoffer wrote: D doesn't have head-const. So you must hide the mutable implementation to get this to work. You'd want to do this anyway, since you don't want to directly use the pointer for anything like indexing (it should first validate

Dynamically allocated Array mutable but non resizeable

2021-06-14 Thread Jalil David Salamé Messina via Digitalmars-d-learn
I'm searching for a way to do something like this in D: ```cpp struct MyStruct { const size_t length; int *const data; MyStruct(size_t n) : length(n) { data = new int[length]; } } ``` This way it is mutable, but non resizeable: ```cpp MyStruct s = MyStruct(10); s.data[0] = 42;

Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-17 Thread David via Digitalmars-d-learn
On Wednesday, 17 March 2021 at 15:16:36 UTC, Jacob Carlborg wrote: On Wednesday, 17 March 2021 at 13:52:48 UTC, Guillaume Piolat wrote: On Sunday, 14 March 2021 at 11:33:00 UTC, David wrote: Anyone else done this? Pointers welcome. Sorry for delay. Just add "dflags-osx-ldc":

Re: Can't call splitter with range struct

2021-03-16 Thread David Skluzacek via Digitalmars-d-learn
On Tuesday, 16 March 2021 at 07:43:18 UTC, drug wrote: That means that you GZippedRange should provide opSlice operator and should be a narrow string (string of char or wchar) Yes, I should have looked more carefully at the doc, I was assuming splitter would accept a simple input range, but

Can't call splitter with range struct

2021-03-15 Thread David Skluzacek via Digitalmars-d-learn
I came across this problem as I was trying to see if could write a quick range-based solution with std.zlib to do what was asked about in a different Learn forum post - read a gzipped file. This seems like it should work: import std.stdio, std.algorithm, std.zlib; import std.range.primitives;

Re: How do I load dylib (i.e. phobos and druntime for ldc) in Macos sandboxed app?

2021-03-14 Thread David via Digitalmars-d-learn
On Sunday, 14 March 2021 at 11:40:25 UTC, David wrote: This is more a macos thing than a D thing but still relevant. In another thread I was asking about cleaning up a D dylib for using in Excel. Ldc was suggested though first I have to figure out how to make the phobos and druntime loadable

How do I load dylib (i.e. phobos and druntime for ldc) in Macos sandboxed app?

2021-03-14 Thread David via Digitalmars-d-learn
This is more a macos thing than a D thing but still relevant. In another thread I was asking about cleaning up a D dylib for using in Excel. Ldc was suggested though first I have to figure out how to make the phobos and druntime loadable from within the sandbox. (I've posted in a new topic as

Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-14 Thread David via Digitalmars-d-learn
On Sunday, 14 March 2021 at 01:38:23 UTC, David Skluzacek wrote: On Thursday, 11 March 2021 at 22:10:04 UTC, David wrote: I wasn't aware that object files could be manipulated like the strip manual page - thx for the heads up. With the caveats that the linked post is almost 14 years old, I

Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-14 Thread David via Digitalmars-d-learn
On Sunday, 14 March 2021 at 00:00:59 UTC, Adam D. Ruppe wrote: On Saturday, 13 March 2021 at 23:41:28 UTC, David wrote: So Excel complains that it can't load my library - presumably because libphobos2 and libdruntime are not in the sandbox.ly You *might* be able to compile with --link

Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-13 Thread David Skluzacek via Digitalmars-d-learn
On Thursday, 11 March 2021 at 22:10:04 UTC, David wrote: I wasn't aware that object files could be manipulated like the strip manual page - thx for the heads up. With the caveats that the linked post is almost 14 years old, I can't try this command myself, and the ldc solution is probably

Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-13 Thread David via Digitalmars-d-learn
On Friday, 12 March 2021 at 00:12:37 UTC, Guillaume Piolat wrote: Create a exports.lst file with: _addDD_D as the only line there. Build with: "lflags-osx-ldc": [ "-exported_symbols_list", "exports.lst", "-dead_strip" ], Thx that's really helpful. I've hit a snag with LDC. After

Re: Storing interfaces as void[]

2021-03-12 Thread David Zhang via Digitalmars-d-learn
On Friday, 12 March 2021 at 22:18:59 UTC, tsbockman wrote: Why do you think you need a `void[]` slice? I think `void*` pointers are sufficient. This handles all normal data types, as long as they are allocated on the GC heap: I wanted to have the registry own the structs' memory, though

Re: Storing interfaces as void[]

2021-03-12 Thread David Zhang via Digitalmars-d-learn
On Friday, 12 March 2021 at 18:14:12 UTC, Imperatorn wrote: On Friday, 12 March 2021 at 17:57:06 UTC, David Zhang wrote: On Friday, 12 March 2021 at 17:46:22 UTC, Imperatorn wrote: On Friday, 12 March 2021 at 17:37:43 UTC, David Zhang wrote: [...] Have you tried using Variant or jsvar

Re: Storing interfaces as void[]

2021-03-12 Thread David Zhang via Digitalmars-d-learn
On Friday, 12 March 2021 at 18:50:26 UTC, tsbockman wrote: The idea is to implement a service locator s.t. code like this is possible: // struct (I didn't mention this in the top post, my mistake) auto log = Logger() api_registry.register!Logger(log); // class/interface

Re: Storing interfaces as void[]

2021-03-12 Thread David Zhang via Digitalmars-d-learn
On Friday, 12 March 2021 at 17:46:22 UTC, Imperatorn wrote: On Friday, 12 March 2021 at 17:37:43 UTC, David Zhang wrote: I want to store interfaces as untyped void[], then cast them back to the interface at a later time. However, it appears to produce garbage values on get(). Is this even

Storing interfaces as void[]

2021-03-12 Thread David Zhang via Digitalmars-d-learn
I want to store interfaces as untyped void[], then cast them back to the interface at a later time. However, it appears to produce garbage values on get(). Is this even possible, and if so, what is happening here? The alternative would be a struct { CheckedPtr self; api_fns } e.g. void

Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-11 Thread David via Digitalmars-d-learn
On Thursday, 11 March 2021 at 18:35:37 UTC, Imperatorn wrote: On Thursday, 11 March 2021 at 17:00:06 UTC, David wrote: On Thursday, 11 March 2021 at 14:49:32 UTC, Imperatorn wrote: On Thursday, 11 March 2021 at 10:29:55 UTC, David wrote: On Thursday, 11 March 2021 at 08:40:58 UTC, Imperatorn

Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-11 Thread David via Digitalmars-d-learn
On Thursday, 11 March 2021 at 14:49:32 UTC, Imperatorn wrote: On Thursday, 11 March 2021 at 10:29:55 UTC, David wrote: On Thursday, 11 March 2021 at 08:40:58 UTC, Imperatorn wrote: On Thursday, 11 March 2021 at 08:34:48 UTC, David wrote: I thought it would be fun to convert some old C++/C

Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-11 Thread David via Digitalmars-d-learn
On Thursday, 11 March 2021 at 14:35:45 UTC, rikki cattermole wrote: Pipe it to grep should work | grep -v "__D2" Thanks - though I'm trying to suppress the symbols being generated in the library. A colleague says it can be done in ldc but not dmd. I'll think I'll try that out.

Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-11 Thread David via Digitalmars-d-learn
On Thursday, 11 March 2021 at 08:40:58 UTC, Imperatorn wrote: On Thursday, 11 March 2021 at 08:34:48 UTC, David wrote: I thought it would be fun to convert some old C++/C quant utils to D. I'm starting with a simple library that I call from vba in Excel on macos: [...] *trigger warning

Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-11 Thread David via Digitalmars-d-learn
00018660 T _thread_scanAll 00018480 T _thread_scanAllType 00019658 T _thread_suspendAll Is there a way of not exposing the symbols that aren't mine? - I only need a simple C interface. Thx David

Re: Memory allocation

2021-02-23 Thread David via Digitalmars-d-learn
On Wednesday, 24 February 2021 at 06:14:58 UTC, Imperatorn wrote: On Tuesday, 23 February 2021 at 19:44:39 UTC, David wrote: Not sure if `learn` is the right topic or not to post this.. I've been going through Bob Nystrom's "Crafting Interpreters" for a bit of fun and over the w

Memory allocation

2021-02-23 Thread David via Digitalmars-d-learn
Not sure if `learn` is the right topic or not to post this.. I've been going through Bob Nystrom's "Crafting Interpreters" for a bit of fun and over the weekend put together a toy allocator in D - free and gc not yet done. It's single threaded and unsurprisingly faster than malloc for small

How to use import std.algorithm.iteration.permutations?

2020-04-19 Thread David Zaragoza via Digitalmars-d-learn
David

Re: Using std.net.curl

2020-02-29 Thread David Anderson via Digitalmars-d-learn
On Saturday, 29 February 2020 at 07:35:10 UTC, Boris Carvajal wrote: On Saturday, 29 February 2020 at 03:53:37 UTC, David Anderson wrote: I want to capture that text in a variable, but the upload function returns void. How can I get the text returned by the web server to be stored

Using std.net.curl

2020-02-28 Thread David Anderson via Digitalmars-d-learn
I'm working with std.net.curl. Using curl on the command line I can do this: curl -T file.txt http://localhost:9998/tika and it returns text as a result. When I attempt to do the same thing in D code as follows: import std.net.curl; upload("file.txt",

Re: ld errors in osx Catalina

2019-10-09 Thread David Briant via Digitalmars-d-learn
On Wednesday, 9 October 2019 at 15:42:42 UTC, David Briant wrote: On Wednesday, 9 October 2019 at 10:33:21 UTC, David Briant wrote: [...] If I uninstall clang using conda I now get: (base) Davids-MacBook:fred david$ dub Performing "debug" build using /Library/D/dmd/bin/dmd f

Re: ld errors in osx Catalina

2019-10-09 Thread David Briant via Digitalmars-d-learn
On Wednesday, 9 October 2019 at 10:33:21 UTC, David Briant wrote: I've accidentally upgraded to Catalina - a little earlier than planned as I had hoped not to be trail blazing! My problem is this, in a bash shell and a new directory when I run $ dub init ... answering the questions that dub

Re: formatting a float or double in a string with all significant digits kept

2019-10-09 Thread David Briant via Digitalmars-d-learn
articles that explain the common issues of floating point representation in detail. -- David

ld errors in osx Catalina

2019-10-09 Thread David Briant via Digitalmars-d-learn
-MacBook:fred david$ dub Performing "debug" build using /Library/D/dmd/bin/dmd for x86_64. fred ~master: building configuration "application"... Linking... ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libpthread.tbd, file was built for unsupporte

Re: do mir modules run in parallell

2019-10-06 Thread David via Digitalmars-d-learn
libraries. Best, Ilya thanks! I will try it out accordingly. Bests, David

Re: do mir modules run in parallell

2019-10-05 Thread David via Digitalmars-d-learn
On Saturday, 5 October 2019 at 04:38:34 UTC, 9il wrote: On Friday, 4 October 2019 at 20:32:59 UTC, David wrote: Hi I am wondering if MIR modules run in parallel by default or if I can enforce it by a compiler flag? Thanks David Hey David, Do you mean unittests run in parallel or mir

do mir modules run in parallell

2019-10-04 Thread David via Digitalmars-d-learn
Hi I am wondering if MIR modules run in parallel by default or if I can enforce it by a compiler flag? Thanks David

Re: How to create an overwriteable struct that is always const?

2019-06-02 Thread David Zhang via Digitalmars-d-learn
Ah, fair enough.

Re: How to create an overwriteable struct that is always const?

2019-06-01 Thread David Zhang via Digitalmars-d-learn
On Saturday, 1 June 2019 at 13:00:50 UTC, ag0aep6g wrote: How is setting/replacing different from modifying? e.g.: S s; this() { s = ...; } update(S s) { this.s = s; } mod(int i) { s.i = i; } // illegal Kinda like how strings can be copied and assigned to, but not

Re: How to create an overwriteable struct that is always const?

2019-06-01 Thread David Zhang via Digitalmars-d-learn
On Saturday, 1 June 2019 at 16:30:12 UTC, Jonathan M Davis wrote: If any member variable of a struct is const, then you can't modify that member ever, and assignment isn't possible unless you override opAssign so that it overwrites only the mutable members. It's very rare that it makes sense

How to create an overwriteable struct that is always const?

2019-06-01 Thread David Zhang via Digitalmars-d-learn
Say I have a struct `S`: struct S { /*const*/ char* pointer; ... other members ... this(/*const*/ char* p, ... others ...) { pointer = p; ... } } What I want, is to be able to use `S` in other data structures with the following

Re: mir.ndslice: assign a vector to a matrix row

2018-12-28 Thread David via Digitalmars-d-learn
On Friday, 28 December 2018 at 08:11:37 UTC, 9il wrote: On Friday, 28 December 2018 at 08:09:09 UTC, 9il wrote: On Thursday, 27 December 2018 at 21:17:48 UTC, David wrote: On Wednesday, 26 December 2018 at 18:59:25 UTC, 9il wrote: [...] great many thanks!! Is there any logic why getting

Re: mir.ndslice: assign a vector to a matrix row

2018-12-27 Thread David via Digitalmars-d-learn
On Wednesday, 26 December 2018 at 18:59:25 UTC, 9il wrote: On Saturday, 15 December 2018 at 19:04:37 UTC, David wrote: Hi I am wondering if it is possible to assign a vector to a row of a matrix? main.d == import mir.ndslice; void main() { auto matrix = slice!double

Re: dscanner --ctags: local variables, functions, ... are now shown in vim/neovim Tagbar

2018-12-17 Thread David via Digitalmars-d-learn
On Monday, 17 December 2018 at 08:56:07 UTC, Laurent Tréguier wrote: I think that's not possible right now, D-Scanner skips over body functions and unittest blocks to not clutter the tags with potentially lots of local names. A pity; nevertheless many thanks for coming back on it!

dscanner --ctags: local variables, functions, ... are now shown in vim/neovim Tagbar

2018-12-16 Thread David via Digitalmars-d-learn
I am wondering how I could display (nested) local variables and functions in vim's tagbar (majutsushi/tagbar) using dscanner? So far I only see gloable variables, functions, ... === script.d == import std.stdio; enum globalEnum1 { A = 1, B = 2 } enum globalEnum2 { C, D }

mir.ndslice: assign a vector to a matrix row

2018-12-15 Thread David via Digitalmars-d-learn
Hi I am wondering if it is possible to assign a vector to a row of a matrix? main.d == import mir.ndslice; void main() { auto matrix = slice!double(3, 4); matrix[] = 0; matrix.diagonal[] = 1; auto row = matrix[0]; row[3] = 4; assert(matrix[0, 3] == 4);

Re: Class qualifier vs struct qualifier

2018-06-15 Thread David Bennett via Digitalmars-d-learn
On Wednesday, 13 June 2018 at 07:35:25 UTC, RazvanN wrote: Hello, I'm having a hard time understanding whether this inconsistency is a bug or intended behavior: immutable class Foo {} immutable struct Bar {} void main() { import std.stdio : writeln; Foo a; Bar b;

Re: Confusion/trying to understand CTFE keywords

2018-06-07 Thread David Bennett via Digitalmars-d-learn
On Thursday, 7 June 2018 at 04:58:40 UTC, Jonathan M Davis wrote: It would be trivial enough to create a wrapper template so that you can do something like immutable n = ctfe!(foo()); e.g. template ctfe(alias value) { enum ctfe = value; } Would this be equivalent to using static

Re: Manipulate slice or specific element of range and return range

2018-03-22 Thread David Bennett via Digitalmars-d-learn
On Thursday, 22 March 2018 at 04:49:39 UTC, Seb wrote: No need for regular expressions. D is powerful enough without them: ``` alias lowercased = (m, n) => m.take(n).asLowerCase.chain(m.drop(n)); ``` https://run.dlang.io/is/cSL0si And with the filter, so it passes the assert: ```

Re: How to build static linked executable

2018-03-20 Thread David Nadlinger via Digitalmars-d-learn
it for? — David

Re: Slow start up time of runtime

2018-03-20 Thread David Nadlinger via Digitalmars-d-learn
On Tuesday, 20 March 2018 at 09:44:41 UTC, Dennis wrote: Are there ways to reduce this to below 0.1s, or should I just leave idiomatic D and make a betterC program? The best solution would be to profile the startup process and file a bug accordingly. ;) — David

Re: Does the compiler inline the predicate functions to std.algorithm.sort?

2018-03-18 Thread David Nadlinger via Digitalmars-d-learn
he LLVM IR obtained with -output-ll might be easier to read than assembly.) — David

Re: Convert output range to input range

2018-03-17 Thread David Nadlinger via Digitalmars-d-learn
– process the results further? — David

Re: Getting a reference to an immutable string

2018-02-10 Thread David Zhang via Digitalmars-d-learn
On Saturday, 10 February 2018 at 22:59:18 UTC, ag0aep6g wrote: But there is a recent regression on Windows that might be related. Do you also have a static constructor (`static this`) that uses `wndclassName`? If so, you might be hitting issue 18412.

Re: Getting a reference to an immutable string

2018-02-10 Thread David Zhang via Digitalmars-d-learn
Building with Visual Studio seems to be fine. This isn't an OptLink issue, is it?

Re: Getting a reference to an immutable string

2018-02-10 Thread David Zhang via Digitalmars-d-learn
On Saturday, 10 February 2018 at 22:36:41 UTC, ag0aep6g wrote: On 02/10/2018 11:26 PM, David Zhang wrote: I've got an immutable string declared in module scope, and I attempted to get a pointer to its characters through both [0] and str.ptr. However, it appears to me that the string

Getting a reference to an immutable string

2018-02-10 Thread David Zhang via Digitalmars-d-learn
that it has a location in memory and thus has a pointer. So, my question is thus: Is this a bug in DMD, or is this just something I missed? Thanks David

Re: Terminating multiple processes

2018-02-01 Thread David Nadlinger via Digitalmars-d-learn
/...), But couldn't you in theory just send a custom signal to the thread (which you ignore), and then check for the exit flag after the syscall returned EINTR? The DInotify wrapper might of course have the retry loop hardcoded; I didn't check. —David

Re: Get aliased type

2018-01-02 Thread David Nadlinger via Digitalmars-d-learn
.) There is indeed no way to do this; as you say, aliases are just names for a particular reference to a symbol. Perhaps you don't actually need the names in your use case, though? — David

Re: partial application for templates

2017-12-25 Thread David Nadlinger via Digitalmars-d-learn
On Monday, 25 December 2017 at 20:39:52 UTC, Mengu wrote: is partially applying templates possible? Check out std.meta.Apply{Left, Right}. — David

Re: Does LDC support profiling at all?

2017-12-23 Thread David Nadlinger via Digitalmars-d-learn
. — David

Re: Parsing string to octal(for umask) at runtime?

2017-12-22 Thread Ryan David Sheasby via Digitalmars-d-learn
On Friday, 22 December 2017 at 21:36:20 UTC, Ryan David Sheasby wrote: Hi. Struggling to figure this out. At the bottom of this page: https://dlang.org/library/std/conv/octal.html is a vague reference to using parse. However, when I use what I would assume to be correct based on this: https

Parsing string to octal(for umask) at runtime?

2017-12-22 Thread Ryan David Sheasby via Digitalmars-d-learn
Hi. Struggling to figure this out. At the bottom of this page: https://dlang.org/library/std/conv/octal.html is a vague reference to using parse. However, when I use what I would assume to be correct based on this: https://dlang.org/phobos/std_conv.html#.parse.3 and the fact that in the octal

Re: Where is sleep()?

2017-12-17 Thread Ryan David Sheasby via Digitalmars-d-learn
On Sunday, 17 December 2017 at 08:40:53 UTC, rikki cattermole wrote: On 17/12/2017 8:32 AM, Ryan David Sheasby wrote: Hey guys. First time poster here. I've searched high and low but can't seem to find a simple sleep/delay/wait/pause function in the core or in phobos. The most recent

Where is sleep()?

2017-12-17 Thread Ryan David Sheasby via Digitalmars-d-learn
Hey guys. First time poster here. I've searched high and low but can't seem to find a simple sleep/delay/wait/pause function in the core or in phobos. The most recent information I can find about it is this forum post from 12 years ago:

Re: Is there anyway to access LLVM's 128 bit int type for C from LDC?

2017-12-14 Thread David Nadlinger via Digitalmars-d-learn
On Thursday, 14 December 2017 at 19:47:53 UTC, Jack Stouffer wrote: Clang has __int128. Is there anyway to use this with D with LDC? There has been some work on this a while ago, by Kai, but it hasn't been merged yet: https://github.com/ldc-developers/ldc/pull/1355 — David

Re: Get pointer or reference of an element in Array(struct)

2017-12-09 Thread David Nadlinger via Digitalmars-d-learn
lain" iteration the compiler AST internally has special ref variables, but they are not visible to the language.) -David

Re: Changing the class data underneath some reference

2017-11-29 Thread David Colson via Digitalmars-d-learn
On Thursday, 30 November 2017 at 00:40:51 UTC, David Colson wrote: Hello all! I'm getting settled into D and I came into a problem. A code sample shows it best: class SomeType { string text; this(string input) {text = input;} } void main() { SomeType foo = new SomeType("

Changing the class data underneath some reference

2017-11-29 Thread David Colson via Digitalmars-d-learn
Hello all! I'm getting settled into D and I came into a problem. A code sample shows it best: class SomeType { string text; this(string input) {text = input;} } void main() { SomeType foo = new SomeType("Hello"); SomeType bar = foo; foo = new SomeType("World");

Re: String copying fails when output from assert

2017-11-21 Thread David Zhang via Digitalmars-d-learn
On Tuesday, 21 November 2017 at 19:05:21 UTC, Jonathan M Davis wrote: Well, the assertion is going to throw an AssertError, which takes a string for its message. It doesn't copy the contents of the string. It's just taking a slice just like whenever you pass a string to any other function. So,

Re: String copying fails when output from assert

2017-11-21 Thread David Zhang via Digitalmars-d-learn
On Tuesday, 21 November 2017 at 18:56:03 UTC, Adam D. Ruppe wrote: On Tuesday, 21 November 2017 at 18:49:40 UTC, David Zhang wrote: assert(false, chars[0..str.length]); } What am I missing here? You're escaping a reference to a local variable there. chars[] is a pointer

String copying fails when output from assert

2017-11-21 Thread David Zhang via Digitalmars-d-learn
Hi, I've been trying to copy a string, then output it from an `assert(false)` statement, but the copy seems to be corrupted somehow. void main() { string str = "some string"; //initializing `chars` with any value doesn't do anything char[64] chars; //char[64]

Re: @nogc deduction for templated functions

2017-11-18 Thread David Zhang via Digitalmars-d-learn
Huh, I think I did something weird. It compiles now, and I don't know why. Thanks for your answers.

@nogc deduction for templated functions

2017-11-18 Thread David Zhang via Digitalmars-d-learn
Hi, Is there a way for a templated function to deduce or apply the @safe/@nogc attributes automaticaly? I feel like I remember dmd doing so at one point, but it doesn't appear to work anymore. In particular, I need to call a function belonging to a templated type, but do not know what

Re: D on AArch64 CPU

2017-10-20 Thread David J Kordsmeier via Digitalmars-d-learn
On Thursday, 10 August 2017 at 07:00:55 UTC, David J Kordsmeier wrote: On Wednesday, 9 August 2017 at 08:37:53 UTC, Johannes Pfau wrote: Iain recently updated GDC & phobos up to 2.074 and we have a pull request for 2.075. So don't worry about fixing old GDC phobos/druntime versions, re

Re: How to check if string is available at compile time

2017-09-21 Thread David Bennett via Digitalmars-d-learn
On Thursday, 21 September 2017 at 13:52:25 UTC, Meta wrote: On Thursday, 21 September 2017 at 12:30:15 UTC, David Bennett wrote: On Thursday, 21 September 2017 at 11:42:36 UTC, David Bennett wrote: enum isCTstring(alias arg) = (!isAssignable!(typeof(arg)) || __traits(compiles, mixin(` &quo

Re: Getting the size of a type tuple

2017-09-21 Thread David Zhang via Digitalmars-d-learn
On Thursday, 21 September 2017 at 19:49:14 UTC, ag0aep6g wrote: I don't have a one-liner, but here are some other solutions that might be interesting. None of them is particularly pretty, though. 1) Recursive template: 2) Using the std library: 3) Declaring a packed struct in a function

Getting the size of a type tuple

2017-09-21 Thread David Zhang via Digitalmars-d-learn
Given the function F, where: F(Args...)(Args args) { ... } How can I statically determine the size of the argument list in bytes? Preferably, I would like a one-liner. However, std.algorithm doesn't seem to support tuples, or `Args.each!(T => T.sizeof).sum` would work. For the moment,

Re: How to check if string is available at compile time

2017-09-21 Thread David Bennett via Digitalmars-d-learn
On Thursday, 21 September 2017 at 11:42:36 UTC, David Bennett wrote: [snip] ``` string[] escapeCTFE(Args...)(){ static foreach (arg; Args){ static if(__traits(compiles, ###WHATDOIPUTHERE###)){ [snip] So far the best I've come up with is : ``` enum isCTstring(alias arg

How to check if string is available at compile time

2017-09-21 Thread David Bennett via Digitalmars-d-learn
t;c"; immutable string d = "d"; const string e = "e"; enum escape_as_much_as_possible = escapeCTFE!(a,b,c,d,e,"f"); } ``` I know for ints I can use __traits(compiles, int[arg]) but I'm not sure about strings. I believe only a and b should be hidden from pragma right? Thanks, David.

Re: Propagating constness through function results

2017-09-17 Thread David Zhang via Digitalmars-d-learn
Nevermind! I rediscovered the `inout`attribute. Though if I may say so, I have no idea how `inout` is supposed to indicate "whatever the constness of a".

Re: Propagating constness through function results

2017-09-17 Thread David Zhang via Digitalmars-d-learn
On Sunday, 17 September 2017 at 21:18:08 UTC, David Zhang wrote: Hi, I have a class `Image`, and I have a function called `getSubImage(Rect bounds)`. What I can't figure out is how to get the result of `getSubImage()` to take on the constness of the backing image. ie. //The Image

Propagating constness through function results

2017-09-17 Thread David Zhang via Digitalmars-d-learn
Hi, I have a class `Image`, and I have a function called `getSubImage(Rect bounds)`. What I can't figure out is how to get the result of `getSubImage()` to take on the constness of the backing image. ie. //The Image class is really just a view over a buffer that's managed elsewhere

Re: Internal error mixing templates and CTFE

2017-09-17 Thread David Bennett via Digitalmars-d-learn
On Friday, 15 September 2017 at 15:48:10 UTC, Stefan Koch wrote: are you using ucent ? Not that I know of, the code above is the full code (not sure what's used internally for string literals). I was using dmd 2.076 from the apt repo but the error also happens in LDC 1.3[1]. Is there an

Re: Internal error mixing templates and CTFE

2017-09-15 Thread David Bennett via Digitalmars-d-learn
On Friday, 15 September 2017 at 07:12:36 UTC, Andrea Fontana wrote: Internal error is always a bug, so it should be reported! I have opened a issue: https://issues.dlang.org/show_bug.cgi?id=17828

Internal error mixing templates and CTFE

2017-09-15 Thread David Bennett via Digitalmars-d-learn
Hi Guys, I've been playing around with CTFE today to see how far I would push it but I'm having an issue appending to an array on a struct in CTFE from a template: ``` struct Content{ string[] parts; } void add_part_to_content(Content content, string s)(){ content.parts ~= "Part:

Re: DLL loading behaviors and pragma(lib)

2017-08-11 Thread David Zhang via Digitalmars-d-learn
On Friday, 11 August 2017 at 04:50:48 UTC, rikki cattermole wrote: On 11/08/2017 12:18 AM, David Zhang wrote: I've been working on getting OpenGL to load on windows without a library, and encountered something curious; Context creation fails when I try to use the function pointer retrieved

DLL loading behaviors and pragma(lib)

2017-08-10 Thread David Zhang via Digitalmars-d-learn
I've been working on getting OpenGL to load on windows without a library, and encountered something curious; Context creation fails when I try to use the function pointer retrieved through GetProcAddress, but works just fine with the statically linked version provided through

Re: D on AArch64 CPU

2017-08-10 Thread David J Kordsmeier via Digitalmars-d-learn
On Wednesday, 9 August 2017 at 08:37:53 UTC, Johannes Pfau wrote: Iain recently updated GDC & phobos up to 2.074 and we have a pull request for 2.075. So don't worry about fixing old GDC phobos/druntime versions, recent gdc git branches should already have AArch64 phobos changes. We have a

Re: D on AArch64 CPU

2017-08-06 Thread David J Kordsmeier via Digitalmars-d-learn
On Sunday, 14 May 2017 at 15:05:08 UTC, Richard Delorme wrote: I recently bought the infamous Raspberry pi 3, which has got a cortex-a53 4 cores 1.2 Ghz CPU (Broadcom). After installing on it a 64 bit OS (a non official fedora 25), I was wondering if it was possible to install a D compiler on

Re: GDC generate wrong .exe ("not a valid win32 application")

2017-06-21 Thread David Nadlinger via Digitalmars-d-learn
in fact generate Linux binaries. — David

Re: libc dependency

2017-06-21 Thread David Nadlinger via Digitalmars-d-learn
Windows x64/MSVCRT executable from Linux today if you copy over the necessary libraries. The question is just how we can make this as easy as possible for users. — David

Re: libc dependency

2017-06-20 Thread David Nadlinger via Digitalmars-d-learn
: https://github.com/ldc-developers/ldc/pull/2142 For Windows, we use the MS C runtime, though, and the legal situation around redistribution seems a bit unclear. — David

Re: Mutiple AliasSeq as input to template

2017-06-07 Thread David Sanders via Digitalmars-d-learn
On Thursday, 25 May 2017 at 17:56:12 UTC, jmh530 wrote: On Thursday, 25 May 2017 at 16:36:45 UTC, jmh530 wrote: [snip] I haven't played around with it fully, but it seems like the following resolves my issue in a sort of manual way: template Process1(A, B) { static if (!isIndex!B)

Re: std.path.buildPath

2017-06-03 Thread David Nadlinger via Digitalmars-d-learn
path if necessary. (Whether this is useful or just unnecessarily error-prone is another question, of course.) — David

Re: C macros vs D can't do the right thing

2017-06-03 Thread David Nadlinger via Digitalmars-d-learn
that this is a bug that needs fixing. ;) — David

Re: C macros vs D can't do the right thing

2017-06-03 Thread David Nadlinger via Digitalmars-d-learn
to make the code work as-is, I suppose you could create some aliases like `enum u32 = __u32.init;` and pass these instead of the types – using runtime values just to convey their type. — David

Re: Implicit conversion from 'Ok' to 'Result' type when returning functions

2017-05-22 Thread David Zhang via Digitalmars-d-learn
On Sunday, 21 May 2017 at 10:03:58 UTC, Nicholas Wilson wrote: As in the function signature of the function you call `ok` or `error` in. Result!(int, SomeEnum) myfunc(bool foo) { if(!foo) return ok(42); else return error(SomeEnum.fooHappened); } should work. This is

Re: Implicit conversion from 'Ok' to 'Result' type when returning functions

2017-05-21 Thread David Zhang via Digitalmars-d-learn
On Sunday, 21 May 2017 at 09:37:46 UTC, Nicholas Wilson wrote: On Sunday, 21 May 2017 at 09:29:40 UTC, David Zhang wrote: Well then it becomes Result!(T, E) ok(T,E) (T t) { return Result(t); } Result!(T, E) error(T,E)(E e) { return Result(e); } and then provided it can be inferred (e.g

Re: Implicit conversion from 'Ok' to 'Result' type when returning functions

2017-05-21 Thread David Zhang via Digitalmars-d-learn
On Sunday, 21 May 2017 at 09:15:56 UTC, Nicholas Wilson wrote: have free functions Result!(T, ErrorEnum) ok(T)(T t) { return Result(t); } Result!(T, ErrorEnum) error(T)(ErrorEnum e) { return Result(e); } then go if (!foo) return ok(42); else return error(Error.fooHappened); Ah,

Implicit conversion from 'Ok' to 'Result' type when returning functions

2017-05-21 Thread David Zhang via Digitalmars-d-learn
Hi, I was reading a bit about this in Rust, and their enum type. I was wondering if this is replicate-able in D. What I've got right now is rather clunky, and involves using `typeof(return).ok` and `typeof(return).error)`. While that's not too bad, it does involve a lot more typing,

  1   2   3   4   5   6   7   >