Re: Get function argument name?

2018-03-04 Thread Timothee Cour via Digitalmars-d-learn
`printName(alias var)()` is not a great solution, eg: doesn't work with expressions, doesn't work with variadics, introduces template bloat. https://github.com/dlang/dmd/pull/7821 introduces __traits(getCallerSource, symbol) which will allow what you want. On Sun, Mar 4, 2018 at 1:53 PM, bauss

Re: Tuts/Aritcles: Incrementasl C++-to-D conversion?

2018-02-22 Thread Timothee Cour via Digitalmars-d-learn
also related: https://github.com/Syniurge/Calypso/issues/85 (feasibility of extending calypso to do source to source translation (eg C++ => D or C=>D) ) On Thu, Feb 22, 2018 at 12:43 AM, ketmar via Digitalmars-d-learn wrote: > Nick Sabalausky (Abscissa) wrote:

Re: what's the point of function template declarations if they can't be defined?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
wrote: > On Thursday, 8 February 2018 at 09:42:08 UTC, Timothee Cour wrote: >> >> I guess you mean `version(StdDdoc)` ? >> >> On that note, I see things like this, which are not DRY: > > > This is actually one of the reasons why I abandoned dmd for my dpldocs.info >

Re: are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
puremagic.com> wrote: > On Thursday, 8 February 2018 at 10:09:12 UTC, Timothee Cour wrote: >> >> I'm curious whether scope guards add any cost over the naive way, eg: >> >> ``` >> void fun(){ >> ... >> scope(success) {bar;} >> ... &

Re: are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
at 2:09 AM, Timothee Cour <thelastmamm...@gmail.com> wrote: > I'm curious whether scope guards add any cost over the naive way, eg: > > ``` > void fun(){ > ... > scope(success) {bar;} > ... > } > ``` > > vs: > > ``` > void fun(){ > ..

are scope guards (scope(exit, success, failure)) zero-cost abstractions?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
I'm curious whether scope guards add any cost over the naive way, eg: ``` void fun(){ ... scope(success) {bar;} ... } ``` vs: ``` void fun(){ ... if(foo1){ bar; // add this before each return return; } ... bar; return; } ``` For scope(success) and scope(failure), the

Re: what's the point of function template declarations if they can't be defined?

2018-02-08 Thread Timothee Cour via Digitalmars-d-learn
PM, Jonathan M Davis via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote: > On Wednesday, February 07, 2018 13:39:55 Timothee Cour via Digitalmars-d- > learn wrote: >> ``` >> void fun_bad3(T)(T a); // declaration [1] >> void fun_bad3(T)(T a){}; // d

what's the point of function template declarations if they can't be defined?

2018-02-07 Thread Timothee Cour via Digitalmars-d-learn
``` void fun_bad3(T)(T a); // declaration [1] void fun_bad3(T)(T a){}; // definition [2] void test(){ fun_bad3(1); } ``` Error: test_all.fun_bad3 called with argument types (int) matches both: main.d(11): test_all.fun_bad3!int.fun_bad3(int a) and: main.d(12):

Re: dirEntries returns relative, not absolute paths

2018-02-06 Thread Timothee Cour via Digitalmars-d-learn
https://github.com/dlang/phobos/pull/6133 On Tue, Feb 6, 2018 at 1:40 PM, Jonathan M Davis via Digitalmars-d-learn wrote: > On Tuesday, February 06, 2018 18:58:43 number via Digitalmars-d-learn wrote: >> https://dlang.org/phobos/std_file.html#dirEntries >> >>

Re: Interfacing with C++

2018-02-05 Thread Timothee Cour via Digitalmars-d-learn
https://github.com/opencv/opencv/issues/6585#issuecomment-221842441 snip: > "C-API" is not supported and should be removed totally (but we have a lack of > resources to port this legacy C code to C++, so some of this code still > exists right now). Also huge part of fresh OpenCV functionality

Re: Interfacing with C++

2018-02-04 Thread Timothee Cour via Digitalmars-d-learn
Calypso (https://github.com/Syniurge/Calypso/) is the most promising way to interface with C++, it requires 0 bindings and understands all of C++ (templates etc); there are some caveats/kinks that are being ironed out (and any help is welcome). On Sun, Feb 4, 2018 at 4:37 AM, rjframe via

Re: C++ Interop

2018-01-05 Thread Timothee Cour via Digitalmars-d-learn
see also https://github.com/Syniurge/Calypso/ although I'm having lots of issues using it on OSX On Fri, Jan 5, 2018 at 9:02 AM, qznc via Digitalmars-d-learn wrote: > I'm exploring [0] C++ interop after watching Walter's presentation [1]. > > I hit a block with

why does unittest mangled name now contains full file path instead of fully qualified module name?

2018-01-05 Thread Timothee Cour via Digitalmars-d-learn
why does unittest mangled name now contains full file path instead of fully qualified module name? seems like a regression, previous behavior seemed better and not dependent on installation path.

Re: Application settings

2017-07-08 Thread Timothee Cour via Digitalmars-d-learn
I use protocol buffers (using dproto) for this, storing my settings in either text or wire format. Advantages: type-safety with fwd/backward compatibility (unlike json which requires dynamic field access, eg with dproto you get errors at compile time instead of runtime), supports comments

Re: D equivalent of C++11's function local static initialization?

2017-05-16 Thread Timothee Cour via Digitalmars-d-learn
NOTE: curious about both cases: * thread local * shared On Tue, May 16, 2017 at 8:04 PM, Timothee Cour <thelastmamm...@gmail.com> wrote: > what's the best D equivalent of C++11's function local static initialization? > ``` > void fun(){ > static auto a=[](){ > //

D equivalent of C++11's function local static initialization?

2017-05-16 Thread Timothee Cour via Digitalmars-d-learn
what's the best D equivalent of C++11's function local static initialization? ``` void fun(){ static auto a=[](){ //some code return some_var; } } ``` (C++11 guarantees thread safety)

Error: unrecognized switch '--DRT-oncycle=print' => where is switch defined?

2017-05-15 Thread Timothee Cour via Digitalmars-d-learn
Getting this: ``` Deprecation 16211 warning: A cycle has been detected in your program that was undetected prior to DMD 2.072. This program will continue, but will not operate when using DMD 2.073 to compile. Use runtime option --DRT-oncycle=print to see the cycle details. ``` Where is `

Re: pointer not aligned

2017-04-02 Thread Timothee Cour via Digitalmars-d-learn
indeed. NOTE: ldmd2/ldc2 doens't have this issue to reproduce: ``` rdmd --force --eval='writeln(`hello`)' ``` ld: warning: pointer not aligned at address 0x1000BE0B9 (_D53TypeInfo_S3std5array17__T8AppenderTAyaZ8Appender4Data6__initZ + 24 from .rdmd-501/rdmd-eval.o) with `--compiler=ldmd2`

Re: Strange Bug

2017-01-20 Thread Timothee Cour via Digitalmars-d-learn
This and some other recent posts (`Is this a bug?`, `Hopefully a simple question...`). If you want help (and help other ppl who search for similar issues), could you please make the subject more descriptive? On Fri, Jan 20, 2017 at 12:19 AM, Chris M. via Digitalmars-d-learn <

DRY version of `static if(__traits(compiles, expr)) fun(expr)`

2016-12-13 Thread Timothee Cour via Digitalmars-d-learn
what's the best (and DRY) way to achieve: ``` static if(__traits(compiles, expr)) fun(expr); ``` ie, without repeating the expression inside expr? eg: ``` static if(__traits(compiles, foo.bar[2])){ counter++; writeln(" expr = ", foo.bar[2]); } ```

Re: [Semi-OT] I don't want to leave this language!

2016-12-06 Thread Timothee Cour via Digitalmars-d-learn
My 2 cents: for most applications, hotspots tend to be in a tiny percentage of the code (ie 90/10 rule where 10% of code accounts for 90% execution time, although my experience in large projects is even more unbalanced) ; throwing away druntime or GC for the whole codebase based on performance

extern(C++) with template produces wrong mangleof

2016-12-02 Thread Timothee Cour via Digitalmars-d-learn
What's the difference bw _Z21test_D20161202T141925IiET_S0_ and _Z21test_D20161202T141925IiEii? mangleof produces the one that's not in the library produced: test.cpp: ``` template T test_D20161202T141925(T a); template int test_D20161202T141925(int); ``` clang++ -shared -o libtest.so test.cpp

The module 'foo' is already defined in 'libmylib.so'

2016-12-01 Thread Timothee Cour via Digitalmars-d-learn
I want to update a library with new symbols (ie partial recompilation): libmylib.so : compiled from bar.d and foo.d now update the file foo.d dmd -c -fPIC foo.d -offoo.o clang++ -o libmylib_update.so foo.o -shared -Wl,-lmylib When trying to dlopen libmylib_update.so from C++ it fails with:

how to catch D Throwables (or exceptions) from C++?

2016-11-30 Thread Timothee Cour via Digitalmars-d-learn
eg: ``` dlib.d: extern(C) void dfun(){assert(0, "some_msg");} clib.cpp: extern "C" void dfun(); void fun(){ try{ dfun(); } catch(...){ // works but how do i get "some_msg" thrown from D? } } ```

Re: how to debug exceptions/asserts thrown in module constructors?

2016-11-27 Thread Timothee Cour via Digitalmars-d-learn
65ad libdyld.dylib start + 1 Ideally there should be a way (via a runtime or compile time option) to wrap the exception throwing (during rt_moduleCtor) inside a extern(C) function that we can put a breakpoint on (and possibly even call backtrace_symbols on) On Sun, Nov 27, 2016 at 2:19 PM, Timothee

how to debug exceptions/asserts thrown in module constructors?

2016-11-27 Thread Timothee Cour via Digitalmars-d-learn
in the process of trying to debug https://github.com/BlackEdder/ggplotd/issues/32 I would like to get a stracktrace and/or put a breakpoint before exception is thrown: ``` lldb $binary r (lldb) Process 34168 resuming

mangle!(void function())("foo").demangle = "void function()* foo"

2016-11-02 Thread Timothee Cour via Digitalmars-d-learn
mangle!(void function())("foo").demangle returns "void function()* foo" how would i get instead: `void foo ()` ? my current workaround: alias FunctionTypeOf(Fun)=typeof(*Fun.init); mangle!(FunctionTypeOf!(void function()))("foo")

zip: why isn't requireSameLength the default?

2016-09-13 Thread Timothee Cour via Digitalmars-d-learn
in zip: why isn't requireSameLength the default? This is the most common case and would fit with the goal of being safe by default.

Re: Checking if a port is listening

2016-03-19 Thread Timothee Cour via Digitalmars-d-learn
see also: https://github.com/rejectedsoftware/vibe.d/issues/1431 api to find an available port On Fri, Mar 18, 2016 at 2:50 AM, Marc Schütz via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Looking at an strace of nmap, it seems it opens a bunch of sockets, puts > them

Re: How to list all version identifiers?

2016-03-15 Thread Timothee Cour via Digitalmars-d-learn
would be easy with compiler as a library... also i thought 'dmd -v -version=foo -c -o- bar.d' would show -version identifiers used on the command line but doesn't seem to On Tue, Mar 15, 2016 at 8:51 AM, Iakh via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Sunday, 13

get stacktrace across all threads

2016-02-22 Thread Timothee Cour via Digitalmars-d-learn
It would be nice to have an api to get stacktrace across threads; it would be particularly useful for server applications (eg vibe.d). Has anyone implemented something similar? I guess one would need to use signal handlers to interrupt each thread?

Re: Scale-Hierarchy on ndslice

2016-01-13 Thread Timothee Cour via Digitalmars-d-learn
On Wed, Jan 13, 2016 at 10:13 AM, jmh530 via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Tuesday, 12 January 2016 at 21:48:39 UTC, Per Nordlöw wrote: > >> Have anybody been thinking about adding a scale-hierarchy structure on >> top of ndslice? >> > > What is a

Re: to!string(double) at compile time

2016-01-01 Thread timothee cour via Digitalmars-d-learn
On Thursday, 23 August 2012 at 13:56:05 UTC, Philippe Sigaud wrote: On Tue, Aug 21, 2012 at 6:43 AM, Bobby Bingham wrote: [...] [...] A possibility is to use a function template, passing the double as a template argument: string test(double d)() // d is a template

Re: DMD Compiler 'switches'

2015-10-12 Thread Timothee Cour via Digitalmars-d-learn
On Mon, Oct 12, 2015 at 11:33 AM, ric maicle via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > On Tuesday, 13 October, 2015 01:46 AM, anonymous wrote: > >> On Monday 12 October 2015 17:38, ric maicle wrote: >> >> I'm wondering if this small irregularity should be made

IFTI with template alias fails in D, works in C++

2015-08-12 Thread Timothee Cour via Digitalmars-d-learn
main.d: -- struct A(T, int D) { this(string ignore){} } alias B(T)=A!(T, 1); void fun1(T)(A!(T,1) a) { } void fun2(T)(B!T a) { } unittest{ auto a=A!(double,1)(a); assert(is(typeof(a) == B!double)); fun1(a);//ok fun2!double(a);//ok // no IFTI here: //fun2(a);//not ok:

Re: exclude current directory from search path in dmd ?

2015-07-20 Thread Timothee Cour via Digitalmars-d-learn
https://github.com/D-Programming-Language/dmd/pull/4823 On Sun, Jul 19, 2015 at 10:42 PM, ZombineDev via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 20 July 2015 at 03:33:08 UTC, Timothee Cour wrote: I've attached a reduced use case showing that the solutions

Re: exclude current directory from search path in dmd ?

2015-07-19 Thread Timothee Cour via Digitalmars-d-learn
https://issues.dlang.org/show_bug.cgi?id=14811 On Wed, Jun 17, 2015 at 3:22 AM, Liran Zvibel via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, 8 June 2015 at 04:08:55 UTC, Adam D. Ruppe wrote: The easiest way is to not use search paths, and instead pass all the

Re: exclude current directory from search path in dmd ?

2015-07-19 Thread Timothee Cour via Digitalmars-d-learn
I've attached a reduced use case showing that the solutions proposed in this thread do not work, and wrote a local modification to dmd to allow a flag -exclude_cwd_from_imports that does work. Would that be acceptable to have this in official dmd? On Sun, Jul 19, 2015 at 8:07 PM, Timothee Cour

generic cast(unshared) ?

2015-06-30 Thread Timothee Cour via Digitalmars-d-learn
How would I cast away shared for a given expression? I can write it for a specific type but I'd like to have a generic way to do so. Also, Unqual doesn't help here.

Re: generic cast(unshared) ?

2015-06-30 Thread Timothee Cour via Digitalmars-d-learn
Note: should work with any types, eg: shared(T[])* = T[]* etc... On Sun, Jun 28, 2015 at 4:42 PM, Timothee Cour thelastmamm...@gmail.com wrote: How would I cast away shared for a given expression? I can write it for a specific type but I'd like to have a generic way to do so. Also, Unqual

Re: string to time conversion (when string contains time but no date)

2015-06-27 Thread Timothee Cour via Digitalmars-d-learn
thanks, missed that! On Sat, Jun 27, 2015 at 2:59 AM, via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Saturday, 27 June 2015 at 03:17:49 UTC, Timothee Cour wrote: is there a way to convert a string representing a time (without date) to a time, eg: auto t = 19:03

string to time conversion (when string contains time but no date)

2015-06-26 Thread Timothee Cour via Digitalmars-d-learn
is there a way to convert a string representing a time (without date) to a time, eg: auto t = 19:03:40.143656; auto a=SysTime.fromTimeString(t); // doesn't exist My current workaround is to append a dummy date before and then calling SysTime.fromSimpleString. Is there a better way? seems

type of a variable as a mixin-able string?

2015-06-21 Thread Timothee Cour via Digitalmars-d-learn
Suppose I have: import std.range; auto a=iota(complex_expr_returning_3()); I'd like to have a function/trait/template/compiler magic that takes variable a and generates a string that can be mixed in to represent the type of a. The difficulty is that typeid(a).to!string doesn't work for

how come is this legal? 'void fun(int){ }' ?

2015-06-13 Thread Timothee Cour via Digitalmars-d-learn
I understand this is legal for declaration wo definition (void fun(int);) but why allow this: void test(int){} ?

Re: exclude current directory from search path in dmd ?

2015-06-08 Thread Timothee Cour via Digitalmars-d-learn
On Mon, Jun 8, 2015 at 12:08 AM, Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: The easiest way is to not use search paths, and instead pass all the modules you want compiled to the compiler directly. Then it will look for the module name declaration instead of

Re: Why is there no named parameter support?

2015-06-08 Thread Timothee Cour via Digitalmars-d-learn
On Mon, Jun 8, 2015 at 11:32 PM, Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Monday, June 08, 2015 23:18:50 Timothee Cour via Digitalmars-d-learn wrote: nim has both overloading and named arguments (with reordering and defaults allowed): http://nim

Re: Why is there no named parameter support?

2015-06-08 Thread Timothee Cour via Digitalmars-d-learn
nim has both overloading and named arguments (with reordering and defaults allowed): http://nim-lang.org/docs/tut1.html#procedures-named-arguments and it doesn't seem to cause issues. Is there a document / thread that explains the argument against named arguments in more details than 'do not play

deserialization: creating a class instance without calling constructor

2015-05-21 Thread Timothee Cour via Digitalmars-d-learn
Can I create an instance of A without calling a constructor? (see below) Use case: for generic deserialiaztion, when the deserialization library encounters a class without default constructor for example (it knows what the fields should be set to, but doesn't know how to construct the object).

why does phobos use [0, 5, 8, 9][] instead of [0, 5, 8, 9] in examples?

2015-04-07 Thread Timothee Cour via Digitalmars-d-learn
Eg, code like this in std.algorithm: assert(equal(setSymmetricDifference(a, b), [0, 5, 8, 9][])); why not just: assert(equal(setSymmetricDifference(a, b), [0, 5, 8, 9])); ?

exclude current directory from search path in dmd ?

2015-03-15 Thread Timothee Cour via Digitalmars-d-learn
Is there a way to exclude current directory from search path in dmd, so that the search path is only given by '-I' arguments (+ones from dmd.conf)? use case: files: /base/foo.d /base/bar/foo.d /base/bar/main.d #contains: import foo.d cd /base/bar dmd -I/base main.d = I want 'import foo.d' to

mixin template can't contain statements: workaround?

2015-03-14 Thread Timothee Cour via Digitalmars-d-learn
Why can't we allow mixin templates to contain statements, as is the case for regular mixins? Is there a workaround? here's a dummy example: template mixin Foo{ //some statement, eg: 'return;' } void fun(){ mixin Foo; } Note that I can do this with a regular mixin, but template mixins are

boilerplate for constructor

2015-03-11 Thread Timothee Cour via Digitalmars-d-learn
I'm trying to define a boilerplate mixin for class constructor to generate code such as: this(T1 a1, T2 a2){this.a1=a1; this.a2=a2;} The following works, but fails if one field is from a superclass, with an error such as: template instance GenThis!(b, a) GenThis!(b, a) is nested in both B and A.

Re: is struct delete deterministic? (cf used in Unique)

2015-03-08 Thread Timothee Cour via Digitalmars-d-learn
On Sun, Mar 8, 2015 at 4:36 AM, Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Sunday, March 08, 2015 04:13:28 Jonathan M Davis via Digitalmars-d-learn wrote: On Saturday, March 07, 2015 17:20:49 Timothee Cour via Digitalmars-d-learn wrote

is struct delete deterministic? (cf used in Unique)

2015-03-07 Thread Timothee Cour via Digitalmars-d-learn
I'm a little confused about the following: clear,delete,destroy. My understanding is that clear is deprecated and delete is planned to be deprecated, so we should only ever use destroy (which deterministic calls the destructor but doesn't release memory). Unique uses delete however in the

Re: is struct delete deterministic? (cf used in Unique)

2015-03-07 Thread Timothee Cour via Digitalmars-d-learn
wrote: On Saturday, 7 March 2015 at 23:48:39 UTC, Timothee Cour wrote: I'm a little confused about the following: clear,delete,destroy. My understanding is that clear is deprecated and delete is planned to be deprecated, so we should only ever use destroy (which deterministic calls

mixin template scope inconsistency?

2015-03-03 Thread Timothee Cour via Digitalmars-d-learn
Template mixin scope seems to have a weird behavior: I don't understand 'WEIRD(1)' and 'WEIRD(2)' below. import std.stdio; struct A{ int b; this(int b){ this.b=b; writeln(A.begin); } ~this(){ writeln(A.end); } } mixin template Entry(){ auto a=A(12); } void test1(){

Re: mixin template scope inconsistency?

2015-03-03 Thread Timothee Cour via Digitalmars-d-learn
posted as bugzilla/14243. Am I misunderstanding something here? On Tue, Mar 3, 2015 at 10:20 PM, Timothee Cour thelastmamm...@gmail.com wrote: Template mixin scope seems to have a weird behavior: I don't understand 'WEIRD(1)' and 'WEIRD(2)' below. import std.stdio; struct A{ int b

shallowCopyFrom: how to shallow copy objects / swap contents ?

2015-02-13 Thread Timothee Cour via Digitalmars-d-learn
Is there a standard way to shallow copy objects? eg: class A{ int* a; string b; } unittest{ auto a=new A; a.a=new int(1); a.b=asdf; auto b=new A; b.shallowCopyFrom(a); assert(b.a==a.a); assert(b.b==a.b); } How about: option A1: void shallowCopyFrom(T)(T a, T b)

parse string as char

2015-02-08 Thread Timothee Cour via Digitalmars-d-learn
Is there a simple way to parse a string as a char? eg: unittest{ assert(parseChar(`a`)=='a'); assert(parseChar(`\n`)=='\n'); //NOTE: I'm looking at `\n` not \n // should also work with other forms of characters, see http://dlang.org/lex.html } Note, std.conv.to doesn't work (`\n`.to!char

eraseInPlace (eg using memmove)?

2014-12-16 Thread Timothee Cour via Digitalmars-d-learn
Is there a phobos way to do eraseInPlace (eg with optimization using memmove where appropriate) ? (akin to insertInPlace)

Re: eraseInPlace (eg using memmove)?

2014-12-16 Thread Timothee Cour via Digitalmars-d-learn
]; a.eraseInPlace(1,2); import std.conv:text; assert(a==[0,3,4,5,6], text(a)); } (obviously it assumes no aliasing) On Tue, Dec 16, 2014 at 6:59 PM, Timothee Cour thelastmamm...@gmail.com wrote: Is there a phobos way to do eraseInPlace (eg with optimization using memmove where appropriate) ? (akin

Re: how to redirect stderr to stdout io in spawnProcess (eg stderr to stdout)?

2014-09-14 Thread Timothee Cour via Digitalmars-d-learn
ping? On Tue, Sep 9, 2014 at 6:48 PM, Timothee Cour thelastmamm...@gmail.com wrote: How to redirect io in spawnProcess (eg stderr to stdout)? is it safe to use it with a same File object for stderr and stdout as follows? Couldn't find this in the docs. auto logFile =File(...); auto pid

spawnShell: how to specify buffering mode (unbuffered, line-buffered, block-buffered)?

2014-09-09 Thread Timothee Cour via Digitalmars-d-learn
Is there a way to specify buffering mode (unbuffered,line-buffered,block-buffered) in spawnShell + friends? This is very useful to have in many applications, eg for logging where one wants to view in progress log results without waiting for entire process to complete or for a 40960-sized block to

how to redirect stderr to stdout io in spawnProcess (eg stderr to stdout)?

2014-09-09 Thread Timothee Cour via Digitalmars-d-learn
How to redirect io in spawnProcess (eg stderr to stdout)? is it safe to use it with a same File object for stderr and stdout as follows? Couldn't find this in the docs. auto logFile =File(...); auto pid = spawnShell(command, std.stdio.stdin,

extern(C) function declaration inside a function without altering mangling

2014-09-06 Thread Timothee Cour via Digitalmars-d-learn
Is there way to declare a extern(C) function inside a function without altering the mangled name? Should I write a mixin for that based on pragma(mangleof) (used as extern_C_global_scope in example below) ? Or did someone already implement that? extern(C) void foo1(); void fun(){ extern(C) void

RAII limitations in D?

2014-08-21 Thread Timothee Cour via Digitalmars-d-learn
What would be a good answer to this article? http://swiftcoder.wordpress.com/2009/02/18/raii-why-is-it-unique-to-c/ Especially the part mentioning D:{ D’s scope keyword, Python’s with statement and C#’s using declaration all provide limited RAII, by allowing resources to have a scoped lifetime,

Re: RAII limitations in D?

2014-08-21 Thread Timothee Cour via Digitalmars-d-learn
On Thu, Aug 21, 2014 at 7:26 PM, Dicebot via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: http://dlang.org/phobos/std_typecons.html#.RefCounted That doesn't work with classes though; is there any way to get a ref counted class? (and btw RefCounted should definitely appear in

Deprecation: Read-modify-write operations are not allowed for shared variables

2014-08-12 Thread Timothee Cour via Digitalmars-d-learn
dmd 2.066(rc) generates warning: 'Deprecation: Read-modify-write operations are not allowed for shared variables. Use core.atomic.atomicOp!-=(a, 1) instead.' for following code: synchronized { ++a; } Is that correct given that it's inside synchronized?

alias to fully qualified enum in scope where enum is expected

2014-08-06 Thread Timothee Cour via Digitalmars-d-learn
Is there a simple way to to do this? enum A{ a1, a2 } void fun(A a){...} void test(){ fun(A.a1); //works fun(a1); //I'd like a1 to work, but just where an A is expected to avoid polluting namespace. }

Re: alias to fully qualified enum in scope where enum is expected

2014-08-06 Thread Timothee Cour via Digitalmars-d-learn
Thanks, I know with statement could be used but I was hoping for a solution not involving adding syntax to call site. void fun(with(A){A a}, int b){...} //conceptually like this void test(){ int a1=1; fun(A.a1, a1); // would work fun(a1, a1);// would work } On Wed, Aug 6, 2014 at 8:22

'with(Foo):' not allowed, why?

2014-08-06 Thread Timothee Cour via Digitalmars-d-learn
Is there a reason why 'with(Foo):' is not allowed, and we have to use with(Foo){...} ? It would be more in line with how other scope definitions work (extern(C) etc)

Re: alias to fully qualified enum in scope where enum is expected

2014-08-06 Thread Timothee Cour via Digitalmars-d-learn
On Wed, Aug 6, 2014 at 12:04 PM, via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Wednesday, 6 August 2014 at 16:48:57 UTC, Timothee Cour via Digitalmars-d-learn wrote: Thanks, I know with statement could be used but I was hoping for a solution not involving adding

Re: myrange.at(i) for myrange.dropExactly(i).front

2014-07-29 Thread Timothee Cour via Digitalmars-d-learn
On Sun, Jul 27, 2014 at 9:20 PM, H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Sun, Jul 27, 2014 at 07:42:17PM -0700, Timothee Cour via Digitalmars-d-learn wrote: Just for clarification, I wanted 'myrange.at(i)' to be the same as `myrange.dropExactly(i

Re: myrange.at(i) for myrange.dropExactly(i).front

2014-07-27 Thread Timothee Cour via Digitalmars-d-learn
Just for clarification, I wanted 'myrange.at(i)' to be the same as `myrange.dropExactly(i).front` (so I don't assume it's a random access range). myrange.dropExactly(i).front makes it much more obvious what you're doing and that it's inefficient. It might be necessary in some cases, but we don't

myrange.at(i) for myrange.dropExactly(i).front

2014-07-25 Thread Timothee Cour via Digitalmars-d-learn
Is there a function for doing this? myrange.at(i) (with meaning of myrange.dropExactly(i).front) it's a common enough operation (analog to myrange[i]; the naming is from C++'s std::vectorT::at)

__traits(position,symbol) to get the file:line:column:index of a symbol (module,unittest etc)

2014-06-12 Thread Timothee Cour via Digitalmars-d-learn
Wouldn't that be nice? it's all known at CT so why not expose it among other things it'd allow proper association of modules to files in stacktraces (sometimes this is impossible / ambiguous), custom user defined error messages involving lambdas, printing unittest lines etc.

escape string into a C style string litteral (pasteable in C code)

2014-06-11 Thread Timothee Cour via Digitalmars-d-learn
Is there an existing way to do it or do I have to roll my own? unittest{ assert(escapeC(`abc\ndef`~\n) == `a\bc\\ndef\n`); } Likewise with escapeD (pastable in D code), which would return something like: `r...` for more readability

findBack: find a needle in a haystack from the back

2014-06-09 Thread Timothee Cour via Digitalmars-d-learn
Is there a more idiomatic/elegant way to achieve the following, while remaining as efficient as possible? Same question in the simpler case n==0? using retro seems inefficient because of all the decodings // returns the largest suffix of a that contains no more than n times c string

alias with lambda syntax: alias fun2=a=fun(a);

2014-06-05 Thread Timothee Cour via Digitalmars-d-learn
Is there a way to do this? import std.algorithm; auto fun(T)(T a){return a;} template fun2(T){auto fun2(T a){return fun(a);}}//OK but heavy syntax and cannot be nested inside test() void main(){ //alias fun2=fun!int; //OK but needs to specify template params //none of those work: //alias

Re: alias with lambda syntax: alias fun2=a=fun(a);

2014-06-05 Thread Timothee Cour via Digitalmars-d-learn
ok I remembered we can use std.typetuple.Alias for that. On Wed, Jun 4, 2014 at 11:58 PM, Timothee Cour thelastmamm...@gmail.com wrote: Is there a way to do this? import std.algorithm; auto fun(T)(T a){return a;} template fun2(T){auto fun2(T a){return fun(a);}}//OK but heavy syntax

Re: string - string literal

2014-04-21 Thread Timothee Cour via Digitalmars-d-learn
does that work? string escapeD(string a){ import std.array:replace; return `r`~a.replace(``,` \ r`)~``; } On Sun, Apr 20, 2014 at 11:14 AM, monarch_dodra via Digitalmars-d-learn digitalmars-d-learn@puremagic.com wrote: On Sunday, 20 April 2014 at 17:55:25 UTC, Ellery Newcomer wrote: is

Re: Best way to check for an element in an array?

2014-04-21 Thread Timothee Cour via Digitalmars-d-learn
you can use stuff.canFind(2) but sometimes it'd be more convenient to have the other way around (UFCS chains etc); how about: bool isIn(T,T2...)(T needle, T2 haystack) if(__traits(compiles,T.init==T2[0].init)){ foreach(e;haystack){ if(needle==e) return true; } return false; }

Re: Test

2014-03-14 Thread Timothee Cour
On 3/22/05, 3:00 PM, AEon wrote: Jan Knepper wrote: Testing Modzilla Thunderbird... AEon test

Re: writeln if not empty

2014-03-11 Thread Timothee Cour
Thanks! your solution is more robust (minus some caveats i mentioned) and also trivially extends to variadics. On Tue, Mar 11, 2014 at 2:07 PM, monarch_dodra monarchdo...@gmail.comwrote: On Tuesday, 11 March 2014 at 05:37:25 UTC, Timothee Cour wrote: void writelnIfNotEmpty(T)(T a){ auto

writeln if not empty

2014-03-10 Thread Timothee Cour
Is there a way to do the following lazily: writelnIfNotEmpty(T)(T a){ auto b=text(a); if(b.length) writeln(b); } ie, without using std.conv.text (which needlessly computes an intermediate string, which could be quite large) or launching a separate process ? writelnIfNotEmpty(); //doesn't

Re: writeln if not empty

2014-03-10 Thread Timothee Cour
On Mon, Mar 10, 2014 at 9:14 PM, Jonathan M Davis jmdavisp...@gmx.comwrote: On Monday, March 10, 2014 21:50:25 Nick Sabalausky wrote: On 3/10/2014 9:24 PM, Timothee Cour wrote: Is there a way to do the following lazily: writelnIfNotEmpty(T)(T a){ auto b=text(a); if(b.length

Re: getTid wrapper

2014-03-04 Thread Timothee Cour
On Tue, Mar 4, 2014 at 10:09 AM, Timothee Cour thelastmamm...@gmail.comwrote: Thanks, that works does it make sense to add a function to do that? as it stands there are 2 separate ways, cast(void*)Thread.getThis and cast(void*)getTid, so having a function would make it the preferred way

Re: runtime loading D shared library as a standalone (with it's own GC etc)

2014-03-03 Thread Timothee Cour
On Fri, Feb 28, 2014 at 10:27 AM, Martin Nowak c...@dawg.eu wrote: On 02/26/2014 10:16 PM, Timothee Cour wrote: Currently (on OSX) I can runtime load a D dll from a C program, but not from a D program, which seems silly. Is it possible to runtime load a D shared library as a standalone (ie

runtime loading D shared library as a standalone (with it's own GC etc)

2014-02-26 Thread Timothee Cour
Currently (on OSX) I can runtime load a D dll from a C program, but not from a D program, which seems silly. Is it possible to runtime load a D shared library as a standalone (ie without sharing GC, runtime or any other data), treating it as if we were loading from a C program (making no attempt

Re: runtime loading D shared library as a standalone (with it's own GC etc)

2014-02-26 Thread Timothee Cour
On Wed, Feb 26, 2014 at 1:20 PM, Adam D. Ruppe destructiona...@gmail.comwrote: Try compiling your library with -defaultlib= (leaving it blank after the equal sign). Then it might work by not loading the symbols for phobos etc twice - they will only be linked into the main program. Thanks,

inverse of escapeShellCommand?

2014-02-14 Thread Timothee Cour
is there a function to get the inverse of escapeShellCommand? ie: assert(escapeShellCommandInverse(` foo 'hello world' `)==[`foo`, `hello world`]);

Re: how to round durations to most significant unit ? (5 secs, 889 ms, and 811 μs = 5 secs)

2014-02-14 Thread Timothee Cour
thanks! On Fri, Feb 14, 2014 at 2:14 PM, Jonathan M Davis jmdavisp...@gmx.comwrote: On Thursday, February 13, 2014 23:37:13 Timothee Cour wrote: Is there a function to do this? If not and I/someone writes it, is there interest to add it to std.datetime? Duration t = ...; t.to!string

how to iterate over an AA by key-value pair (tuple)?

2014-02-13 Thread Timothee Cour
how to iterate over an AA by key-value pair (tuple)? use case: avoid interrupting UFCS chains, eg: foo.generate_aa.byKeyValue.filter!(a=a[0].isLower).map!(a=a[1]) ... of course I could roll my own function but I was wondering if there's already a way.

Re: how to iterate over an AA by key-value pair (tuple)?

2014-02-13 Thread Timothee Cour
is there anything more efficient than this? auto byKeyValue(T)(T a)if(isAssociativeArray!T){ return a.byKey.map!(b=tuple(b, a[b])); } On Thu, Feb 13, 2014 at 3:56 PM, Timothee Cour thelastmamm...@gmail.comwrote: how to iterate over an AA by key-value pair (tuple)? use case: avoid

Re: how to iterate over an AA by key-value pair (tuple)?

2014-02-13 Thread Timothee Cour
On Thu, Feb 13, 2014 at 5:50 PM, Steven Schveighoffer schvei...@yahoo.comwrote: On Thu, 13 Feb 2014 19:06:45 -0500, timotheecour timothee.co...@gmail.com wrote: On Thursday, 13 February 2014 at 23:56:35 UTC, Timothee Cour wrote: how to iterate over an AA by key-value pair (tuple)? use

how to round durations to most significant unit ? (5 secs, 889 ms, and 811 μs = 5 secs)

2014-02-13 Thread Timothee Cour
Is there a function to do this? If not and I/someone writes it, is there interest to add it to std.datetime? Duration t = ...; t.to!string = 5 secs, 889 ms, and 811 μs t.round.to!string= 5 secs t=...; t.to!string = 889 ms, and 811 μs t.round.to!string= 889 secs Use case: shorter logs.

Re: dirEntries throws exception on broken symlinks

2014-01-07 Thread Timothee Cour
I reported this here some time ago: http://d.puremagic.com/issues/show_bug.cgi?id=11501 (dup of http://d.puremagic.com/issues/show_bug.cgi?id=8298) and there's a pull request ready, not sure why it isn't being merged On Sun, Jan 5, 2014 at 10:20 PM, dennis denn...@visi.com wrote: On Sunday, 5

Re: std.file.dirEntries unsorted

2013-12-11 Thread Timothee Cour
yes, I agree sorting should be explicit as there's no natural order. However sorting after calling dirEntries is not great as typically one wants to sort within a given directory level and it's too late to sort once all the directory levels are flattened. so how about having an extra argument that

Re: Type inference and overloaded functions

2013-12-11 Thread Timothee Cour
On Wed, Dec 11, 2013 at 5:17 PM, bearophile bearophileh...@lycos.comwrote: Namespace: Your gig: https://github.com/D-Programming-Language/dmd/pull/ 2952#discussion_r8288045 My enhancement request was for the array[$] syntax. The idea of []s was invented by someone else (Timothee Cour

std.file.dirEntries unsorted

2013-12-10 Thread Timothee Cour
dirEntries depends on readdir, which has undefined order (eg: http://stackoverflow.com/questions/8977441/does-readdir-guarantee-an-order, and I've experienced as well dirEntries in non-alphabetical order) shouldn't we make dirEntries return in alphabetical order by default, with an option to

  1   2   3   >