When is copy assignment @safe to use when the left-hand-side is an undefined l-value?

2018-03-16 Thread Nordlöw via Digitalmars-d-learn
Given an uninitialized (undefined content from, for instance, 
malloc) value `x` of type `T`, when is it @safe to initalize `x` 
with a simple assignment such as


x = y

in contrast to

emplace(&x, y);

?

My current guess is when

hasElaborateCopyConstructor!T

is `false`. Is this always correct?

I'm asking because I want the following function to work 
correctly for all types including default-uncopyable container 
types (that require explicit call to .dup)


private static void duplicateEmplace(T)(const scope ref T src,
scope ref T dst) @system
{
import std.conv : emplace;
import std.traits : hasElaborateCopyConstructor, isCopyable, 
isBasicType;

static if (!hasElaborateCopyConstructor!T)
{
import std.traits : isInstanceOf;
static if (is(T == class) ||
   is(T == string))
{
dst = cast(T)src;
}
else static if (isBasicType!T ||
isInstanceOf!(Nullable, T)) // `Nullable` 
types cannot be emplaced

{
dst = src;
}
else
{
emplace(&dst, cast(Unqual!T)src);
}
}
else static if (__traits(hasMember, T, "dup"))
{
// TODO fix when emplace can handle uncopyable types
emplace(&dst);
dst = src.dup;
}
else
{
static assert(0, T.stringof ~ " is neither copyable or 
dupable");

}
}



Re: CTFE and -betterC

2018-03-16 Thread Xavier Bigand via Digitalmars-d-learn

Le 16/03/2018 à 22:58, Xavier Bigand a écrit :

Le 15/03/2018 à 01:09, Flamaros a écrit :

On Wednesday, 14 March 2018 at 01:17:54 UTC, rikki cattermole wrote:

You will still need DllMain, that is a platform requirement.


I am not sure about that because when DllAnalyser don't see it in the 
opengl32.dll from the system32 directory. And the documentation indicate that 
it is optional.

I finally choose to put the entry points generation in a sub-project that put 
them in a d file, like that it is easier to make the CTFE working and will be 
much better for the debugging and compilation time.

So I have also some few other questions :
 - Is it a bug that ctRegex doesn't with the return of allMembers?
 - What is the status of the new CTFE engine?
 - Will CTFE be able to write files or expose a way to see to resulting 
generated code for a debug purpose?
 - Is there a reason why CTFE is impacted by the -betterC option?




I actually found token strings, but I can't figure out how to cascade them, it 
is even possible?
I tried things like that :

enum loadSystemSymbolsCode = q{
version (Windows)
{
extern (Windows)
void loadSytemSymbols()
{
import core.sys.windows.windows;

immutable string dllFilePath = "C:/Windows/System32/opengl32.dll";

auto hModule = LoadLibraryEx(dllFilePath, null, 0);
if (hModule == null)
{
return;
}
writeln(dllFilePath ~ " loaded.");

"%SYSTEM_BINDINGS%"
}
}
};

enum moduleCode = q{
module api_entry;

import std.stdio : writeln;
import derelict.util.wintypes;

export extern (C)
{
mixin(loadSystemSymbolsCode);
}
};

string getLoadSystemSymbolsCode(string bindinsCode)()
{
return loadSystemSymbolsCode.replace("%SYSTEM_BINDINGS%", bindinsCode);
}

string getModuleCode(string loadSystemSymbolsCode)()
{
return moduleCode.replace("%LOAD_SYSTEM_SYMBOLS%", loadSystemSymbolsCode);
}

voidmain()
{
import std.stdio : File;

auto file = File("../opengl32/src/api_entry.d", "w");

file.writeln(
getModuleCode!(
getLoadSystemSymbolsCode!("test;")())
);
}

Is there some materials for learning to do this kind of things with CTFE?


I feel my self little stupid, I don't need the " in the token string with the 
%WordToReplace%. So I think that the magic will happen.



Re: Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread visitor via Digitalmars-d-learn

On Friday, 16 March 2018 at 20:19:59 UTC, aberba wrote:

On Friday, 16 March 2018 at 17:11:17 UTC, visitor wrote:

On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote:
I creating one simple desktop application using dlang. I need 
to display some html file in my desktop application. How can 
make it works ?


There's also gtkd sourceview :
https://github.com/gtkd-developers/GtkD/tree/master/generated/sourceview


I think you mean Gtk web view. It comes from WebKit.


oh yes, my bad, misreading, i thought OP wanted syntax 
highlighting and stuff...


Re: CTFE and -betterC

2018-03-16 Thread Xavier Bigand via Digitalmars-d-learn

Le 15/03/2018 à 01:09, Flamaros a écrit :

On Wednesday, 14 March 2018 at 01:17:54 UTC, rikki cattermole wrote:

You will still need DllMain, that is a platform requirement.


I am not sure about that because when DllAnalyser don't see it in the 
opengl32.dll from the system32 directory. And the documentation indicate that 
it is optional.

I finally choose to put the entry points generation in a sub-project that put 
them in a d file, like that it is easier to make the CTFE working and will be 
much better for the debugging and compilation time.

So I have also some few other questions :
 - Is it a bug that ctRegex doesn't with the return of allMembers?
 - What is the status of the new CTFE engine?
 - Will CTFE be able to write files or expose a way to see to resulting 
generated code for a debug purpose?
 - Is there a reason why CTFE is impacted by the -betterC option?




I actually found token strings, but I can't figure out how to cascade them, it 
is even possible?
I tried things like that :

enum loadSystemSymbolsCode = q{
version (Windows)
{
extern (Windows)
void loadSytemSymbols()
{
import core.sys.windows.windows;

immutable string dllFilePath = "C:/Windows/System32/opengl32.dll";

auto hModule = LoadLibraryEx(dllFilePath, null, 0);
if (hModule == null)
{
return;
}
writeln(dllFilePath ~ " loaded.");

"%SYSTEM_BINDINGS%"
}
}
};

enum moduleCode = q{
module api_entry;

import std.stdio : writeln;
import derelict.util.wintypes;

export extern (C)
{
mixin(loadSystemSymbolsCode);
}
};

string getLoadSystemSymbolsCode(string bindinsCode)()
{
return loadSystemSymbolsCode.replace("%SYSTEM_BINDINGS%", bindinsCode);
}

string getModuleCode(string loadSystemSymbolsCode)()
{
return moduleCode.replace("%LOAD_SYSTEM_SYMBOLS%", loadSystemSymbolsCode);
}

voidmain()
{
import std.stdio : File;

auto file = File("../opengl32/src/api_entry.d", "w");

file.writeln(
getModuleCode!(
getLoadSystemSymbolsCode!("test;")())
);
}

Is there some materials for learning to do this kind of things with CTFE?


Re: Forwarding arguments through a std.algorithm.map

2018-03-16 Thread Nordlöw via Digitalmars-d-learn
On Friday, 16 March 2018 at 20:39:33 UTC, Andrei Alexandrescu 
wrote:
My knee-jerk reaction is that's a rather peculiar primitive to 
add to the standard library. -- Andrei


I'm needing it for variadic equal...I'll put it as a private 
member in `equal`s template declaration for now.


Re: Testing D database calls code for regression

2018-03-16 Thread nani via Digitalmars-d-learn

On Friday, 16 March 2018 at 20:17:49 UTC, aberba wrote:
How will you test D code which makes calls to database to 
detect bugs and regression. Unlike where you can inject data 
like assert (2+1 == 3), database interfacing code will be 
crazy... Or there's some mocking available for such cases. 
Especially when more features are developed on top.


would type providers 
(https://docs.microsoft.com/en-us/dotnet/fsharp/tutorials/type-providers/) be posible with ctfe?
that would be one way to test at compile time functions that use 
the db.


Re: Testing D database calls code for regression

2018-03-16 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Mar 16, 2018 at 08:17:49PM +, aberba via Digitalmars-d-learn wrote:
> How will you test D code which makes calls to database to detect bugs
> and regression. Unlike where you can inject data like assert (2+1 ==
> 3), database interfacing code will be crazy... Or there's some mocking
> available for such cases. Especially when more features are developed
> on top.

The usual way I do this is to decouple the code from the real database
backend by templatizing the database driver.  Then in my unittest I can
instantiate the template with a mock database driver that only
implements the bare minimum to run the test.

For example, instead of:

import database : Database;
auto myQueryFunc(Args...)(Database db, Args args) {
return db.query(...);
}

Do this:

import database : Database;
auto myQueryFunc(Db = database.Database, Args...)(Db db, Args args) {
return db.query(...);
}

Then regular calls to myQueryFunc will call the real database backend,
as usual. But in the unittest:

unittest {
struct FakeDb {
auto query(...) {
// mock implementation here
}
}
FakeDb db;

// test away
assert(myQueryFunc(db, ...) == ... ); // uses FakeDb
}

This applies not only to database backends, but just about anything you
need to insert mockups for.  For example, for testing complicated file
I/O, I've found it useful to do this:

auto myFunc(File = std.stdio.File, Args...)(Args args) {
auto f = File(...);
// do stuff with f
}

unittest
{
struct FakeFile {
this(...) { ... }
// mockup here
}
assert(myFunc!FakeFile(...) == ... );
}

Using this method, you can even create tests for error-handling, like a
simulated filesystem that returns random (simulated) I/O errors, or
exhibits various disk-full conditions (without actually filling up your
real disk!), etc..  I've created tests for code that searches
directories for files, by substituting a fake filesystem that contains
pre-determined sets of files with content that only exist inside the
unittest.  This way, I can run these tests without actually modifying my
real filesystem in any way.

If you push this idea far enough, you might be able to write unittests
for simulated syscalls, too. :-D  (Maybe that's something we could do in
druntime... :-P)


T

-- 
May you live all the days of your life. -- Jonathan Swift


Re: Forwarding arguments through a std.algorithm.map

2018-03-16 Thread Andrei Alexandrescu via Digitalmars-d-learn

On 03/16/2018 03:52 PM, Nordlöw wrote:

On Saturday, 10 March 2018 at 21:31:41 UTC, ag0aep6g wrote:

auto forwardMap(alias fun, Ts ...)(Ts things)
{
    import std.meta: aliasSeqOf, staticMap;
    import std.range: iota;
    import std.typecons: Tuple;
    alias NewType(size_t i) = typeof(fun(things[i]));
    alias NewTypes = staticMap!(NewType,
    aliasSeqOf!(iota(things.length)));
    Tuple!NewTypes results;
    static foreach (i, thing; things) results[i] = fun(thing);
    return results;
}


Found a slightly compacter way without `iota` and `aliasSeqOf` and with 
(deprecated) string-lambda support and single-pass initialization using 
`= void` and `emplace`:


/** Returns: `xs` forwarded through calls to `fun`.
  *
  * See also: 
https://forum.dlang.org/post/zjxmreegqkxgdzvih...@forum.dlang.org

  */
auto forwardMap(alias fun, Ts...)(Ts xs)
{
     import std.meta : staticMap;
     alias MappedTypeOf(T) = typeof(fun(T.init));
     alias NewTypes = staticMap!(MappedTypeOf, Ts);

     import std.typecons : Tuple;
     Tuple!NewTypes ys = void;
     import std.conv : emplace;

     import std.functional : unaryFun;
     alias fun_ = unaryFun!(fun);

     static foreach (immutable i, x; xs)
     {
     emplace(&ys[i], fun_(x));
     }
     return ys;
}

I believe this should go into Phobos somewhere. Into std.typecons, 
std.meta or std.algorithm?


My knee-jerk reaction is that's a rather peculiar primitive to add to 
the standard library. -- Andrei


Testing D database calls code for regression

2018-03-16 Thread aberba via Digitalmars-d-learn
How will you test D code which makes calls to database to detect 
bugs and regression. Unlike where you can inject data like assert 
(2+1 == 3), database interfacing code will be crazy... Or there's 
some mocking available for such cases. Especially when more 
features are developed on top.


Re: Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread aberba via Digitalmars-d-learn

On Friday, 16 March 2018 at 17:11:17 UTC, visitor wrote:

On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote:
I creating one simple desktop application using dlang. I need 
to display some html file in my desktop application. How can 
make it works ?


There's also gtkd sourceview :
https://github.com/gtkd-developers/GtkD/tree/master/generated/sourceview


I think you mean Gtk web view. It comes from WebKit.


Re: Forwarding arguments through a std.algorithm.map

2018-03-16 Thread Nordlöw via Digitalmars-d-learn

On Saturday, 10 March 2018 at 21:31:41 UTC, ag0aep6g wrote:

auto forwardMap(alias fun, Ts ...)(Ts things)
{
import std.meta: aliasSeqOf, staticMap;
import std.range: iota;
import std.typecons: Tuple;
alias NewType(size_t i) = typeof(fun(things[i]));
alias NewTypes = staticMap!(NewType,
aliasSeqOf!(iota(things.length)));
Tuple!NewTypes results;
static foreach (i, thing; things) results[i] = fun(thing);
return results;
}


Found a slightly compacter way without `iota` and `aliasSeqOf` 
and with (deprecated) string-lambda support and single-pass 
initialization using `= void` and `emplace`:


/** Returns: `xs` forwarded through calls to `fun`.
 *
 * See also: 
https://forum.dlang.org/post/zjxmreegqkxgdzvih...@forum.dlang.org

 */
auto forwardMap(alias fun, Ts...)(Ts xs)
{
import std.meta : staticMap;
alias MappedTypeOf(T) = typeof(fun(T.init));
alias NewTypes = staticMap!(MappedTypeOf, Ts);

import std.typecons : Tuple;
Tuple!NewTypes ys = void;
import std.conv : emplace;

import std.functional : unaryFun;
alias fun_ = unaryFun!(fun);

static foreach (immutable i, x; xs)
{
emplace(&ys[i], fun_(x));
}
return ys;
}

I believe this should go into Phobos somewhere. Into 
std.typecons, std.meta or std.algorithm?


Re: Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread visitor via Digitalmars-d-learn

On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote:
I creating one simple desktop application using dlang. I need 
to display some html file in my desktop application. How can 
make it works ?


There's also gtkd sourceview :
https://github.com/gtkd-developers/GtkD/tree/master/generated/sourceview


Re: Forwarding arguments through a std.algorithm.map

2018-03-16 Thread Nordlöw via Digitalmars-d-learn

On Saturday, 10 March 2018 at 21:31:41 UTC, ag0aep6g wrote:

Not tested beyond `f(1, 2.3, "foo")`:

auto forwardMap(alias fun, Ts ...)(Ts things)
{
import std.meta: aliasSeqOf, staticMap;
import std.range: iota;
import std.typecons: Tuple;
alias NewType(size_t i) = typeof(fun(things[i]));
alias NewTypes = staticMap!(NewType,
aliasSeqOf!(iota(things.length)));
Tuple!NewTypes results;
static foreach (i, thing; things) results[i] = fun(thing);
return results;
}


Thanks! I'll try to put together something...


Re: How to simplify nested ifs

2018-03-16 Thread Tony via Digitalmars-d-learn

On Tuesday, 13 March 2018 at 12:23:06 UTC, Ozan Süel wrote:


if (source?pool?repository?directory?users) // do something



That type of chain is sometimes referred to as a "train wreck" 
(see Law of Demeter).


If this is a common lookup it could be:

if (source && source.GotSomeUsers() )




Re: List of language deprecations

2018-03-16 Thread Nordlöw via Digitalmars-d-learn
On Friday, 16 March 2018 at 16:01:18 UTC, Steven Schveighoffer 
wrote:

https://dlang.org/deprecate.html


Thanks!


Re: List of language deprecations

2018-03-16 Thread Steven Schveighoffer via Digitalmars-d-learn

On 3/16/18 11:58 AM, Nordlöw wrote:

Is there a list of language deprecations?

I want to show my codings fellows how strong and modern D's view on 
deprecations are.


https://dlang.org/deprecate.html

-Steve


List of language deprecations

2018-03-16 Thread Nordlöw via Digitalmars-d-learn

Is there a list of language deprecations?

I want to show my codings fellows how strong and modern D's view 
on deprecations are.


Re: Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread Jesse Phillips via Digitalmars-d-learn

On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote:
I creating one simple desktop application using dlang. I need 
to display some html file in my desktop application. How can 
make it works ?


I believe on is available in dtw.
http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fswt%2Fbrowser%2FBrowser.html


Re: Allocator Part of Type

2018-03-16 Thread jmh530 via Digitalmars-d-learn

On Friday, 16 March 2018 at 06:20:42 UTC, Eugene Wissner wrote:


[snip]


That's interesting thanks.


Re: Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread bauss via Digitalmars-d-learn

On Friday, 16 March 2018 at 11:04:31 UTC, Jayam wrote:

On Friday, 16 March 2018 at 10:53:39 UTC, bauss wrote:

On Friday, 16 March 2018 at 10:52:14 UTC, Alex wrote:

On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote:
I creating one simple desktop application using dlang. I 
need to display some html file in my desktop application. 
How can make it works ?


Do you mean something like this?
http://vibed.org/api/diet.dom/


I think he means something like an embedded web browser 
component.


Yes, I need component like Web Browser of windows form.


I don't think there is any written in D, but you could probably 
bind against webkit or gecko.


Re: Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread Jayam via Digitalmars-d-learn

On Friday, 16 March 2018 at 10:53:39 UTC, bauss wrote:

On Friday, 16 March 2018 at 10:52:14 UTC, Alex wrote:

On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote:
I creating one simple desktop application using dlang. I need 
to display some html file in my desktop application. How can 
make it works ?


Do you mean something like this?
http://vibed.org/api/diet.dom/


I think he means something like an embedded web browser 
component.


Yes, I need component like Web Browser of windows form.


Re: Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread Alex via Digitalmars-d-learn

On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote:
I creating one simple desktop application using dlang. I need 
to display some html file in my desktop application. How can 
make it works ?


Do you mean something like this?
http://vibed.org/api/diet.dom/



Re: Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread bauss via Digitalmars-d-learn

On Friday, 16 March 2018 at 10:52:14 UTC, Alex wrote:

On Friday, 16 March 2018 at 10:31:51 UTC, Jayam wrote:
I creating one simple desktop application using dlang. I need 
to display some html file in my desktop application. How can 
make it works ?


Do you mean something like this?
http://vibed.org/api/diet.dom/


I think he means something like an embedded web browser component.


Re: How to simplify nested ifs

2018-03-16 Thread bauss via Digitalmars-d-learn

On Tuesday, 13 March 2018 at 12:23:06 UTC, Ozan Süel wrote:

Hi

I have a construction like the following

if (source) {
  if (source.pool) {
if (source.pool.repository) {
  if (source.pool.repository.directory) {
if (source.pool.repository.directory.users) {
  // do something

Any chance to simplify this nested ifs?
I know some languages has a way like.

if (source?pool?repository?directory?users) // do something


Similar ways in D?

Thanks and Regards, Ozan


Kind of an ugly hack, but:

string createCondition(string[] entries)
{
string result = "";
string lastEntry = "";

foreach (entry; entries)
{
if (lastEntry && lastEntry.length) lastEntry ~= "." ~ 
entry;

else lastEntry = entry;

result ~= lastEntry ~ " !is null &&";
}

result.length -= 2;

return result;
}

bool isDefined(alias symbol,T)(T arg)
{
import std.array : split;

enum symbolEntries = symbol.split(".");

enum entriesCondition = createCondition(["arg"] ~ 
symbolEntries[1..$]);


mixin("return " ~ entriesCondition ~ ";");
}

...

Usage:

Let's say we have these:

class A {}

class B { A a; }

class C { B b; }

class D { C c; }

class E { D d; }

Then instead of:

auto e = new E;

if (e !is null && e.d !is null && e.d.c !is null && e.d.c.b !is 
null && e.d.c.b.a !is null)

{
// ...
}

Then we can just do:

if (isDefined!((e.d.c.b.a).stringof)(e))
{
   // ...
}

...

The ugly part tbh.

is that we need to stringof when passing the symbol and we also 
have to pass the object itself to the function.


A preferred version would have been:

if (isDefined!(e.d.c.b.a))
{
   // ...
}

Unfortunately that's not possible.

You can see it live here: https://run.dlang.io/is/e2ACNc


Is there any web browser control in D Lang to display html file ?

2018-03-16 Thread Jayam via Digitalmars-d-learn
I creating one simple desktop application using dlang. I need to 
display some html file in my desktop application. How can make it 
works ?




Re: How to simplify nested ifs

2018-03-16 Thread bauss via Digitalmars-d-learn

On Friday, 16 March 2018 at 09:34:38 UTC, Satoshi wrote:
null conditional operators are not implemented in D because, as 
a (I think Walter) said, D is not language designed to work 
with classes or advanced OOP stuff. Nobody uses it, so please, 
if you are using it, stop and use structs and meta programming 
instead.


Tbh. the real reason is because there is no real backing and 
there has never been proposed a DIP on it.


Re: How to simplify nested ifs

2018-03-16 Thread drug via Digitalmars-d-learn

On 16.03.2018 09:34, Satoshi wrote:

On Tuesday, 13 March 2018 at 12:23:06 UTC, Ozan Süel wrote:

Hi

I have a construction like the following

if (source) {
  if (source.pool) {
if (source.pool.repository) {
  if (source.pool.repository.directory) {
if (source.pool.repository.directory.users) {
  // do something

Any chance to simplify this nested ifs?
I know some languages has a way like.

if (source?pool?repository?directory?users) // do something


Similar ways in D?

Thanks and Regards, Ozan


null conditional operators are not implemented in D because, as a (I
think Walter) said, D is not language designed to work with classes or
advanced OOP stuff. Nobody uses it, so please, if you are using it, stop
and use structs and meta programming instead.


I think that null conditional operator is intended for OOP only. It's 
really useful if your data field may be nullable. May be start review 
about this?


Re: How to simplify nested ifs

2018-03-16 Thread drug via Digitalmars-d-learn

On 16.03.2018 09:51, drug wrote:


I think that null conditional operator is intended for OOP only. It's
really useful if your data field may be nullable. May be start review
about this?

Oops. I mean *isn't intended for OOP only*


Re: How to simplify nested ifs

2018-03-16 Thread Satoshi via Digitalmars-d-learn

On Tuesday, 13 March 2018 at 12:23:06 UTC, Ozan Süel wrote:

Hi

I have a construction like the following

if (source) {
  if (source.pool) {
if (source.pool.repository) {
  if (source.pool.repository.directory) {
if (source.pool.repository.directory.users) {
  // do something

Any chance to simplify this nested ifs?
I know some languages has a way like.

if (source?pool?repository?directory?users) // do something


Similar ways in D?

Thanks and Regards, Ozan


null conditional operators are not implemented in D because, as a 
(I think Walter) said, D is not language designed to work with 
classes or advanced OOP stuff. Nobody uses it, so please, if you 
are using it, stop and use structs and meta programming instead.


Re: signbit question

2018-03-16 Thread Seb via Digitalmars-d-learn

On Friday, 16 March 2018 at 08:35:58 UTC, Radu wrote:

On Friday, 16 March 2018 at 07:00:36 UTC, ashit axar wrote:

On Thursday, 15 March 2018 at 17:30:48 UTC, Seb wrote:


They generate the same assembly: https://godbolt.org/g/4ohTJx


import std.stdio;

void main()
{
writeln("hello");
}


this generate error for dmd there.


`writeln` is not supported in betterC for dmd. Use `printf` 
instead.


Or remove -betterC. I just used it because then no module 
constructors/destructors are generated and thus the assembly is 
even shorter.


Re: signbit question

2018-03-16 Thread Radu via Digitalmars-d-learn

On Friday, 16 March 2018 at 07:00:36 UTC, ashit axar wrote:

On Thursday, 15 March 2018 at 17:30:48 UTC, Seb wrote:


They generate the same assembly: https://godbolt.org/g/4ohTJx


import std.stdio;

void main()
{
writeln("hello");
}


this generate error for dmd there.


`writeln` is not supported in betterC for dmd. Use `printf` 
instead.


Re: Convert output range to input range

2018-03-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 16, 2018 07:57:04 John Chapman via Digitalmars-d-learn 
wrote:
> I need to write to a range created with outputRangeObject, then
> read from it. Is there a way to convert it to an input range?

The output range API only supports the put function. That's it. The output
range supports no way whatsoever to read data, and it has nothing to do with
the input range API. As such, an output range cannot be generically
converted into an input range, but some specific output ranges could be. For
instance, std.array.Appender is an output range, and you get a dynamic array
out of it, which would be an input range. So, if you have control over what
output range you're dealing with, the simplest would be to just use
Appender. If you don't have control over what output range you're dealing
with, then your options depend on what the type you're dealing with is, but
it won't work with fully generic code.

- Jonathan M Davis



Convert output range to input range

2018-03-16 Thread John Chapman via Digitalmars-d-learn
I need to write to a range created with outputRangeObject, then 
read from it. Is there a way to convert it to an input range?


Re: signbit question

2018-03-16 Thread ashit axar via Digitalmars-d-learn

On Thursday, 15 March 2018 at 17:30:48 UTC, Seb wrote:


They generate the same assembly: https://godbolt.org/g/4ohTJx


import std.stdio;

void main()
{
writeln("hello");
}


this generate error for dmd there.