enum tuple subscript as template parameter => Tuple(A(0)) must be an array or pointer type, not Tuple!(A)

2017-05-07 Thread bastien penavayre via Digitalmars-d-learn

Hi,

I'm having a bit of an issue here and the compiler is not really 
explicit.

Here's the code:

import std.typecons;

struct A { int i; }

void main()
{
   enum t = tuple(A());
   f!(t[0].i); //Error: Tuple(A(0)) must be an array or pointer 
type, not Tuple!(A)

   f!(([0]).i) //Ok
   enum v = t[0];
   f!(v.i); //Error: template instance f!(i) does not match 
template declaration f(int T)()

   f!((v.i)); //Ok
}

void f(int T)() {}


Re: Looking for an equivalent to C++ std::getline in D

2017-05-07 Thread Patrick Schluter via Digitalmars-d-learn

On Sunday, 7 May 2017 at 13:16:16 UTC, bachmeier wrote:

On Sunday, 7 May 2017 at 10:33:25 UTC, k-five wrote:

Although I found D for being more better, nicer,and fun than 
C++ is, but there is a few questions on Stack-Over-Flow, 
videos on Youtube, and  some other forums in my country. So, 
why D is not popular?


If by popular you mean C++ or Java levels of usage, that's a 
pretty high standard. While D is not among the most used 
languages in large enterprises, it is definitely not an obscure 
language. For example, just a few days ago I was reading about 
the new Scala Native project. Among the motivations for that 
project is


"Scala Native provides an interop layer that makes it easy to 
interact with foreign native code. This includes C and other 
languages that can expose APIs via C ABI (e.g. C++, D, Rust 
etc.)" [0]


You have to be careful about using stackoverflow as a measure 
of language popularity. Most activity takes place on this 
mailing list, which was going long before stackoverflow, and 
there was little motivation to move there (Google searches will 
bring you here).


One of the few quantitative measures (and even that's of 
limited use) is DMD downloads from this site. Most recently 
they have been at about 50,000 per month.[1]


[0] http://www.scala-native.org/en/latest/user/interop.html
[1] http://erdani.com/d/downloads.daily.png


If you look on TIOBE [1] newest stats, D does not look so bad 
after all. It's ranked 23 with a 1.38% share. The so fashionable 
and noisy Rust is only ranked 40 with 0.41% of share and classics 
like COBOL, FORTRAN, Lisp, Scala, Ada, bash are all behind. So 
it's not yet in the top 20 but I think that it will continue 
growing, slowly and steadily.


[1]: https://www.tiobe.com/tiobe-index/


Re: Looking for an equivalent to C++ std::getline in D

2017-05-07 Thread Patrick Schluter via Digitalmars-d-learn

On Sunday, 7 May 2017 at 12:29:20 UTC, Stanislav Blinov wrote:

On Sunday, 7 May 2017 at 10:33:25 UTC, k-five wrote:

[...]


Because everyone is asking this question instead of actually 
doing something about it :)
To be fair, D has a good amount of usage even today, it's just 
not being screamed about ecstatically.



[...]


Today is the last day of the D Conference 2017, last three days 
it was livestreaming. There were quite a bit of talks on 
current developments and future progress. The videos from those 
streams should appear at 
https://www.youtube.com/user/sociomantic/videos hopefully early 
next week. They also have previous conference videos out there.


Some of them have started to appear already 3 hours ago.


Re: File Input

2017-05-07 Thread k-five via Digitalmars-d-learn

On Sunday, 7 May 2017 at 15:59:25 UTC, JV wrote:

On Sunday, 7 May 2017 at 15:16:58 UTC, k-five wrote:

On Sunday, 7 May 2017 at 13:57:47 UTC, JV wrote:


I'm kinda getting it but how do i write the stored user 
input(string) varaible into a .txt??im getting confused since D 
has so many read and write


 ->sample below
string num;
auto attendance= File("studAttendance.txt","a+");

writeln("Add Student Attendance");
readf("%s ",);//im not sure if this is correct but 
assuming it works
  //how do i write what is stored in 
num in the studAttendance.txt

  //file??

attendance.close();


--

You have the right for confusing :) there is many read and write 
names. But I assumed you are familiar with [Type] and [Object] 
concept.


in:
auto output_file_stream = File( "file.txt", "w" );

auto = File  == A type
File( "file.txt", "w" ); == Constructor

So this type has its own property, like read for "r" mode and 
write for "w" mode.


So you should use output_file_stream.write(), not readf or so on.

Still I am very new in D, but this is the same concept in other 
language like C++


in C++:
#include 
#include 
#include 

int main(int argc, char **argv)
{

std::ofstream ofs( "file.txt" );
std::string line = "This is the first line";
// write is a method in class ofstream
ofs.write( &*line.begin(), line.length() );
ofs.close();
}


Re: File Input

2017-05-07 Thread JV via Digitalmars-d-learn

On Sunday, 7 May 2017 at 15:16:58 UTC, k-five wrote:

On Sunday, 7 May 2017 at 13:57:47 UTC, JV wrote:

Hi guys

I'd like to know how to get an input from the user to be 
stored in a .txt file using import std.file and is it possible 
to directly write in a .txt file without using a variable to 
store the user input?


Thanks for the answer in advance my mind is kinda jumbled 
about this since im new to this language.


First of all see here:
https://dlang.org/phobos/std_stdio.html#.File

also:

import std.stdio; // for File

void main(){

// an output file with name file.txt
// w for writing
auto ofs = File( "file.txt", "w" );

// output file stream:
ofs.write( stdin.readln() ); // get a line from console
ofs.close();
}


cat file.txt:
This is the first line.


and for std.file:
https://dlang.org/phobos/std_file.html




I'm kinda getting it but how do i write the stored user 
input(string) varaible into a .txt??im getting confused since D 
has so many read and write


 ->sample below
string num;
auto attendance= File("studAttendance.txt","a+");

writeln("Add Student Attendance");
readf("%s ",);//im not sure if this is correct but 
assuming it works
  //how do i write what is stored in num 
in the studAttendance.txt

  //file??

attendance.close();


Re: File Input

2017-05-07 Thread Suliman via Digitalmars-d-learn

On Sunday, 7 May 2017 at 13:57:47 UTC, JV wrote:

Hi guys

I'd like to know how to get an input from the user to be stored 
in a .txt file using import std.file and is it possible to 
directly write in a .txt file without using a variable to store 
the user input?


Thanks for the answer in advance my mind is kinda jumbled about 
this since im new to this language.


http://nomad.so/2015/09/working-with-files-in-the-d-programming-language/


Deprecation: foo.bar is not visible from module traits

2017-05-07 Thread Anonymouse via Digitalmars-d-learn
I'm reworking my code to use UDAs, and I'm running into a wall of 
text of deprecation warnings when compiling.



import std.traits;

private:

struct SomeUDA {}

@SomeUDA
void foo() {}

@SomeUDA
void bar() {}

@SomeUDA
void etc() {}

public:

void main()
{
mixin("static import thisModule = " ~ __MODULE__ ~ ";");

foreach (symbol; getSymbolsByUDA!(thisModule, SomeUDA))
{
static if (isSomeFunction!symbol)
{
pragma(msg, symbol.stringof);
}
}
}


See https://wandbox.org/permlink/6Z01koyGGRxjsNWG for the output 
it gives. In the real code it's unmanageably many lines.


Is there any way to get rid of these warnings except by making 
everything public? Ideally I wouldn't want to copy the source of 
getSymbolsByUDA into each file doing this either.


Re: File Input

2017-05-07 Thread k-five via Digitalmars-d-learn

On Sunday, 7 May 2017 at 13:57:47 UTC, JV wrote:

Hi guys

I'd like to know how to get an input from the user to be stored 
in a .txt file using import std.file and is it possible to 
directly write in a .txt file without using a variable to store 
the user input?


Thanks for the answer in advance my mind is kinda jumbled about 
this since im new to this language.


First of all see here:
https://dlang.org/phobos/std_stdio.html#.File

also:

import std.stdio; // for File

void main(){

// an output file with name file.txt
// w for writing
auto ofs = File( "file.txt", "w" );

// output file stream:
ofs.write( stdin.readln() ); // get a line from console
ofs.close();
}


cat file.txt:
This is the first line.


and for std.file:
https://dlang.org/phobos/std_file.html


Error writing file a *.obj

2017-05-07 Thread dummy via Digitalmars-d-learn

Hi :)

  - OS: Winodws 10 Pro KN
  -  DMD: 2.073.2(ofcourse, i tried dmd of 2.074.x version. but 
same result)


When i build some application with dub, i got this error:
--

dub build

xx ~master: building configuration "application"...
Error: Error writing file 
'.dub\build\application-debug-windows-x86-dmd_2073-FEC52DAD217DFEA46ECF98CA4240FA06\xx.obj'

dmd failed with exit code 1
--



What's mean? my dub.json here:
--
{
"name": "xx",
"authors": [
"dummy"
],
"description": "A minimal D application.",
"copyright": "Copyright © 2017, dummy",
"license": "proprietary",
"dependencies": {
"requests": "~>0.4.1"
},
"subConfigurations": {
"requests": "vibed"
}
}
--
app.d is default file, so i didn't modify it.


File Input

2017-05-07 Thread JV via Digitalmars-d-learn

Hi guys

I'd like to know how to get an input from the user to be stored 
in a .txt file using import std.file and is it possible to 
directly write in a .txt file without using a variable to store 
the user input?


Thanks for the answer in advance my mind is kinda jumbled about 
this since im new to this language.









Re: How can I pass an argument to rdmd --evel=

2017-05-07 Thread Vladimir Panteleev via Digitalmars-d-learn

On Sunday, 7 May 2017 at 11:29:30 UTC, k-five wrote:

It should be possible!
rdmd --eval=, without accepting argument is useless.


FWIW, you can still pass input through stdin.



Re: Looking for an equivalent to C++ std::getline in D

2017-05-07 Thread bachmeier via Digitalmars-d-learn

On Sunday, 7 May 2017 at 10:33:25 UTC, k-five wrote:

Although I found D for being more better, nicer,and fun than 
C++ is, but there is a few questions on Stack-Over-Flow, videos 
on Youtube, and  some other forums in my country. So, why D is 
not popular?


If by popular you mean C++ or Java levels of usage, that's a 
pretty high standard. While D is not among the most used 
languages in large enterprises, it is definitely not an obscure 
language. For example, just a few days ago I was reading about 
the new Scala Native project. Among the motivations for that 
project is


"Scala Native provides an interop layer that makes it easy to 
interact with foreign native code. This includes C and other 
languages that can expose APIs via C ABI (e.g. C++, D, Rust 
etc.)" [0]


You have to be careful about using stackoverflow as a measure of 
language popularity. Most activity takes place on this mailing 
list, which was going long before stackoverflow, and there was 
little motivation to move there (Google searches will bring you 
here).


One of the few quantitative measures (and even that's of limited 
use) is DMD downloads from this site. Most recently they have 
been at about 50,000 per month.[1]


[0] http://www.scala-native.org/en/latest/user/interop.html
[1] http://erdani.com/d/downloads.daily.png


Re: Looking for an equivalent to C++ std::getline in D

2017-05-07 Thread Stanislav Blinov via Digitalmars-d-learn

On Sunday, 7 May 2017 at 10:33:25 UTC, k-five wrote:

On Sunday, 7 May 2017 at 09:46:22 UTC, Patrick Schluter wrote:

On Saturday, 6 May 2017 at 10:15:03 UTC, k-five wrote:


If you want to learn the basis of the range concept and their 
link to C++ Iterators, you should definitively read Andrei's 
article on them in the InformIT magazine. Here is the link

http://www.informit.com/articles/printerfriendly/1407357
required read for every aspiring D programmer ;-)


---

Thanks for the article.

Although I found D for being more better, nicer,and fun than 
C++ is, but there is a few questions on Stack-Over-Flow, videos 
on Youtube, and  some other forums in my country. So, why D is 
not popular?


Because everyone is asking this question instead of actually 
doing something about it :)
To be fair, D has a good amount of usage even today, it's just 
not being screamed about ecstatically.



I am a big fan of Perl-one-liner and after seeing
rdmd --evel='one-line-code'
I gasped! Oh, really? a one-liner with D!

Or even Unix Command Line, that D has Uniform Function Call 
Syntax.

line.sort.uniq.writeln();

It may you know about the future of D or may introduce some 
other articles about the future of D to me. Since after 
learning C++ I am not very comfortable with.


Today is the last day of the D Conference 2017, last three days 
it was livestreaming. There were quite a bit of talks on current 
developments and future progress. The videos from those streams 
should appear at https://www.youtube.com/user/sociomantic/videos 
hopefully early next week. They also have previous conference 
videos out there.


Re: How can I pass an argument to rdmd --evel=

2017-05-07 Thread k-five via Digitalmars-d-learn

On Sunday, 7 May 2017 at 11:11:05 UTC, Vladimir Panteleev wrote:

On Sunday, 7 May 2017 at 10:49:25 UTC, k-five wrote:

After reading about rdmd and --eval, I tried this:

rdmd --eval='auto f=File("ddoc.html");foreach(line;f.byLine) 
if(line.length<10) writeln(line);f.close'


and worked!

Now I am wonder if there is a way to pass "ddoc.html" to this 
one-liner? that can work with --loop.


I mean:
// --loop by default has foreach(line ...
// like perl -n
rdmd --loop='if( line.length < 10 ) writeln( line );' ddoc.html

but it is an error in syntax and rdmd says:
Cannot have both --eval and a program file ('ddoc.html')


Currently it's not possible:


It should be possible!
rdmd --eval=, without accepting argument is useless.


Re: How can I pass an argument to rdmd --evel=

2017-05-07 Thread Vladimir Panteleev via Digitalmars-d-learn

On Sunday, 7 May 2017 at 11:11:05 UTC, Vladimir Panteleev wrote:

Currently it's not possible:


https://issues.dlang.org/show_bug.cgi?id=13345



Re: How can I pass an argument to rdmd --evel=

2017-05-07 Thread Vladimir Panteleev via Digitalmars-d-learn

On Sunday, 7 May 2017 at 10:49:25 UTC, k-five wrote:

After reading about rdmd and --eval, I tried this:

rdmd --eval='auto f=File("ddoc.html");foreach(line;f.byLine) 
if(line.length<10) writeln(line);f.close'


and worked!

Now I am wonder if there is a way to pass "ddoc.html" to this 
one-liner? that can work with --loop.


I mean:
// --loop by default has foreach(line ...
// like perl -n
rdmd --loop='if( line.length < 10 ) writeln( line );' ddoc.html

but it is an error in syntax and rdmd says:
Cannot have both --eval and a program file ('ddoc.html')


Currently it's not possible:



How can I pass an argument to rdmd --evel=

2017-05-07 Thread k-five via Digitalmars-d-learn

After reading about rdmd and --eval, I tried this:

rdmd --eval='auto f=File("ddoc.html");foreach(line;f.byLine) 
if(line.length<10) writeln(line);f.close'


and worked!

Now I am wonder if there is a way to pass "ddoc.html" to this 
one-liner? that can work with --loop.


I mean:
// --loop by default has foreach(line ...
// like perl -n
rdmd --loop='if( line.length < 10 ) writeln( line );' ddoc.html

but it is an error in syntax and rdmd says:
Cannot have both --eval and a program file ('ddoc.html')


Re: Looking for an equivalent to C++ std::getline in D

2017-05-07 Thread k-five via Digitalmars-d-learn

On Sunday, 7 May 2017 at 09:46:22 UTC, Patrick Schluter wrote:

On Saturday, 6 May 2017 at 10:15:03 UTC, k-five wrote:


If you want to learn the basis of the range concept and their 
link to C++ Iterators, you should definitively read Andrei's 
article on them in the InformIT magazine. Here is the link

http://www.informit.com/articles/printerfriendly/1407357
required read for every aspiring D programmer ;-)


---

Thanks for the article.

Although I found D for being more better, nicer,and fun than C++ 
is, but there is a few questions on Stack-Over-Flow, videos on 
Youtube, and  some other forums in my country. So, why D is not 
popular?


I am a big fan of Perl-one-liner and after seeing
rdmd --evel='one-line-code'
I gasped! Oh, really? a one-liner with D!

Or even Unix Command Line, that D has Uniform Function Call 
Syntax.

line.sort.uniq.writeln();

It may you know about the future of D or may introduce some other 
articles about the future of D to me. Since after learning C++ I 
am not very comfortable with.


Re: Looking for an equivalent to C++ std::getline in D

2017-05-07 Thread Patrick Schluter via Digitalmars-d-learn

On Saturday, 6 May 2017 at 10:15:03 UTC, k-five wrote:


Although I am not sure but it may Range in D, has the same 
concept that C++ has on iterator, like InputIterator or 
OutputIterator, since I realized that the output of [ filter ] 
does not have RandomAccessRange so I can not use input[ 0 ]. 
But I can use input.front().




If you want to learn the basis of the range concept and their 
link to C++ Iterators, you should definitively read Andrei's 
article on them in the InformIT magazine. Here is the link

http://www.informit.com/articles/printerfriendly/1407357
required read for every aspiring D programmer ;-)