Capturing by value in the thread

2024-10-18 Thread Kadir Erdem Demir via Digitalmars-d-learn
It seems [=] functionality C++ does not exist in D. By using a helper function I made that example work. ```d import std.stdio; auto localFoo(int x) { return (){ return x;}; } void main() { int x = 10; auto lambda = (int capturedX = x) { writeln("Captured reference : ", ca

Re: Using C library libsndfile with D

2015-06-25 Thread Kadir Erdem Demir via Digitalmars-d-learn
D has the pragma(lib) feature where you can tell the compiler to link with a specific library as well. For example: pragma(lib, "curl"); I want to try that as soon as I get home from work. You probably need to make a .lib file from the dll too. The implib program does that. If you don't

Re: Utf8 to Utf32 cast cost

2015-06-08 Thread Kadir Erdem Demir via Digitalmars-d-learn
Thanks a lot, your answers are very useful for me . Nothing wrong with toUtf32, I just didn't know it.

Utf8 to Utf32 cast cost

2015-06-08 Thread Kadir Erdem Demir via Digitalmars-d-learn
I want to use my char array with awesome, cool std.algorithm functions. Since many of this algorithms requires like slicing etc.. I prefer to create my string with Utf32 chars. But by default all strings literals are Utf8 for performance. With my current knowledge I use to!dhar to convert Utf8

Getting the socket information from HTTP and DNS sessions

2015-03-04 Thread Kadir Erdem Demir via Digitalmars-d-learn
I have been ask to write a test tool which initiates DNS-HTTP-HTTPS-TCP sessions. And ofcourse I wrote this with D. For HTTP I used std.net like "m_HTTP = HTTP(m_url);m_HTTP.perform();" For DNS I simply used "getAddressInfo(m_domainName);" Than tool makes some simple checks which are npt su

Re: Filling a char array with letters and element type of char[]

2015-03-04 Thread Kadir Erdem Demir via Digitalmars-d-learn
@Tobias @Ali @Jonathan @Steven Thanks alot for your answers. I will try to learn as much as I can from them. Regards Erdem

Filling a char array with letters and element type of char[]

2015-03-03 Thread Kadir Erdem Demir via Digitalmars-d-learn
I have an char[]; char[] strArr = "http://www.hurriyet.com.tr/ekonomi".dup; I stripped the domain out of url like: auto domain = findSplitAfter(strArr, "http://";)[1].until('/'); Than because I am new to the language I became curious if I change domain(which I believe a input iterator); the v

Re: Starting a HTTPS session with D

2015-02-12 Thread Kadir Erdem Demir via Digitalmars-d-learn
get("https://dlang.org";, http); It works as I wanted, thanks a lot . Regards Erdem

Starting a HTTPS session with D

2015-02-12 Thread Kadir Erdem Demir via Digitalmars-d-learn
Hi We have a network traffic logger module at office. We need to a tool which creates simple traffic with different protocols and test our product's output to see if we parse the headers correctly or not. And of course I proposed writing this tool with D!!! When it comes to create a HTTP ses

Re: Using "reduce" with user types

2015-02-07 Thread Kadir Erdem Demir via Digitalmars-d-learn
auto sum = aArr.map!`a.count`.reduce!((a,b) => a + b); Rikki Thanks a lot. It works. Function map!"a.count"(aArr) surprises me a little. Because when I read std.algorithm reference: `Implements the homonym function (also known as transform)`. Which reminds me C++ transform and it will never

Using "reduce" with user types

2015-02-07 Thread Kadir Erdem Demir via Digitalmars-d-learn
I can use filter algorithm with my types easily. struct A { string value; int count; } void main( string[] args ) { A[] aArr; aArr ~= A("HTTP", 3); aArr ~= A("HTTPS", 2); aArr ~= A("UNKNOWN_TCP", 4); aArr.filter!( a => a.count == 2);

Re: Record separator is being lost after string cast

2015-02-04 Thread Kadir Erdem Demir via Digitalmars-d-learn
Thanks a lot, I will follow your advise and implement this part same as your example. Regards Kadir Erdem

Re: Record separator is being lost after string cast

2015-02-04 Thread Kadir Erdem Demir via Digitalmars-d-learn
don't beleive what you see! ;-) I am sorry make a busy community more busy with false alarms. When I write to file I saw Record Separator really exists. I hope my second question is a valid one. How can I write the code below better? How can I reduce the number of foreach? statements. Fi

Record separator is being lost after string cast

2015-02-04 Thread Kadir Erdem Demir via Digitalmars-d-learn
I am opening a .gz file and reading it chunk by chunk for uncompressing it. The data in the uncompressed file is like : aRSbRScRSd, There are record separators(ASCII code 30) between each record(records in my dummy example a,b,c). File file = File(mylog.gz, "r"); auto uc = new UnComp