Re: Avoiding __traits(getAttributes, ...) on alias
Vlad Levenfeld: but beware I've noticed that sometimes this is not equivalent to the previous version and I'm not sure how or why that happens. In particular I notice that mixin(const bool value = ~expr~;)); and const bool value = mixin(expr); are not the same, for some reason. What are the differences?
Re: Avoiding __traits(getAttributes, ...) on alias
because this works: foreach (type; mixin(`__traits (getAttributes, T.`~member~`)`)) static if (is (type == attribute)) return true;
Re: Avoiding __traits(getAttributes, ...) on alias
I'm not really sure. Here is an example of the problem: const bool has_attribute (T, string member, alias attribute) () { static if (1) // ok mixin( `foreach (type; __traits (getAttributes, T.`~member~`))` `static if (is (type == attribute))` `return true;` ); else // doesn't compile, member is not accessible error foreach (type; __traits (getAttributes, mixin(`T.`~member))) static if (is (type == attribute)) return true; return false; } Maybe its trying to use it inside of __traits that is causing it?
Re: Avoiding __traits(getAttributes, ...) on alias
I don't have any examples of the const bool thing not working, its just something I feel like I recall, though I could be mistaking it for the __traits example.
Re: Down the VisualD0.3.38-1.exe ,found virus!
I've been using VisualD for a long time without problems. If it makes you nervous, you can get the source from Github and compile it yourself. Hello,Meta When I compile the Visual D projects: at first,I compile the 'build' project,then get some error: --START ALL BUILD: PROJECT: c2d, Debug Win32 -- Building ..\bin\Debug\c2d.lib... Build time: 1 s -- START ALL BUILD: PROJECT: vsi2d, Debug Win32 -- Building ..\bin\Debug\vsi2d.exe... Converting debug information... Build time: 1 s -- START ALL BUILD: PROJECT: build, Debug Win32 -- Building ..\bin\Debug\build.sdk... 'C:\Program' is not recognized as an internal or external command, operable program or batch file. Building ..\bin\Debug\dte_idl.success failed! Here is my VSSDK AND WINSDK: VSSDK100Install = C:\Program Files (x86)\Microsoft Visual Studio 2010 SDK SP1 WindowsSdkDir = C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A How can I do? Thank you.
Re: Recommendation on option parsing
On 2014-05-10 01:09, Chris Piker wrote: Phobos' std.getopt is a bit spare for my taste, as there is no builtin general help facility with word-wrapping. Does anyone have a recommendation on which of the existing command line option parsing libraries floating around in the wild to use? If it doesn't compile against the current version of phobos I'm willing to put in a little work, but since I'm very new to D I probably would not make the best design decisions. I'm using the one in Tango [1] with some additions [2]. It's a bit messy and I don't consider it stable, but it will automatically generate the help text. You can see some of it's uses here [3]. [1] https://github.com/SiegeLord/Tango-D2 [2] https://github.com/jacob-carlborg/mambo/tree/master/mambo/arguments [3] https://github.com/jacob-carlborg/dstep/blob/master/dstep/driver/Application.d#L53 -- /Jacob Carlborg
Re: Avoiding __traits(getAttributes, ...) on alias
else // doesn't compile, member is not accessible error foreach (type; __traits (getAttributes, mixin(`T.`~member))) static if (is (type == attribute)) return true; return false; Maybe its trying to use it inside of __traits that is causing it? Maybe __traits is trying to extract attributes from the mixin expression, before the mixin injection? That looks like a bug to me, no?
Inspecting lambda parameters
I know that there are templates to inspect function parameters, like ParameterIdentifierTuple and ParameterTypeTuple. But these don't work for templated/untyped lambdas, they're apparently not callables. I don't expect ParameterTypeTuple to work, but it would be nice if ParameterIdentifierTuple and arity worked. Here's an example for clarify: void foo (alias func) () { alias Types = ParameterTypeTuple!(func); } void main () { foo!(x = x * 2); } Anyone know if this is fixable or if there's a workaround? I would like to avoid using hacks like .stringof. I know there's __parameters as well, but that doesn't work either. -- /Jacob Carlborg
Re: Recommendation on option parsing
On 05/10/2014 01:09 AM, Chris Piker via Digitalmars-d-learn wrote: Phobos' std.getopt is a bit spare for my taste, as there is no builtin general help facility with word-wrapping. Does anyone have a recommendation on which of the existing command line option parsing libraries floating around in the wild to use? If it doesn't compile against the current version of phobos I'm willing to put in a little work, but since I'm very new to D I probably would not make the best design decisions. -- Chris please help to make this happen https://github.com/D-Programming-Language/phobos/pull/2072
Curl Exception
First off a rant: I use the Code::Blocks IDE and at times it has been proven to a double-edged source because of various issueslike this one: http://forum.dlang.org/thread/ndeyzrifseipuebvy...@forum.dlang.org) and am now itching to search for other IDEs to suit my needs. Now on to the question: Anyway, I was using std.net.curl to implement an auto updater for my program. Function code is this: http://pastebin.com/i6WnwJF5(links removed due to it having private content. Original host is https://dropbox.com) And the overall function was working fine in the IDE except for an Access Violation that I thought would work itself out when it's (run by administrator). So I Exported it to a folder with all necessary files, including the cacert.pem file and run it. Well this little error popped out : http://pastebin.com/8MmPLg2Q Though in the Code:: Blocks IDE there was the object.Error Access Violation error And in the actual program(.exe) this : http://pastebin.com/8MmPLg2Q Though I'm also up for not verifying the link but I still can't figure out how. Anyway, can anyone give me an idea what went wrong?
Re: Curl Exception
On Saturday, 10 May 2014 at 13:02:39 UTC, Jack wrote: First off a rant: I use the Code::Blocks IDE and at times it has been proven to a double-edged source because of various issueslike this one: http://forum.dlang.org/thread/ndeyzrifseipuebvy...@forum.dlang.org) and am now itching to search for other IDEs to suit my needs. Now on to the question: Anyway, I was using std.net.curl to implement an auto updater for my program. Function code is this: http://pastebin.com/i6WnwJF5(links removed due to it having private content. Original host is https://dropbox.com) And the overall function was working fine in the IDE except for an Access Violation that I thought would work itself out when it's (run by administrator). So I Exported it to a folder with all necessary files, including the cacert.pem file and run it. Well this little error popped out : http://pastebin.com/8MmPLg2Q Though in the Code:: Blocks IDE there was the object.Error Access Violation error And in the actual program(.exe) this : http://pastebin.com/8MmPLg2Q Though I'm also up for not verifying the link but I still can't figure out how. Anyway, can anyone give me an idea what went wrong? Little typo there: Function code is this: http://pastebin.com/i6WnwJF5
Re: Avoiding __traits(getAttributes, ...) on alias
Agreed, new bug report submitted.
Re: Down the VisualD0.3.38-1.exe ,found virus!
On Saturday, 10 May 2014 at 08:42:14 UTC, FrankLike wrote: I've been using VisualD for a long time without problems. If it makes you nervous, you can get the source from Github and compile it yourself. Hello,Meta When I compile the Visual D projects: at first,I compile the 'build' project,then get some error: --START ALL BUILD: PROJECT: c2d, Debug Win32 -- Building ..\bin\Debug\c2d.lib... Build time: 1 s -- START ALL BUILD: PROJECT: vsi2d, Debug Win32 -- Building ..\bin\Debug\vsi2d.exe... Converting debug information... Build time: 1 s -- START ALL BUILD: PROJECT: build, Debug Win32 -- Building ..\bin\Debug\build.sdk... 'C:\Program' is not recognized as an internal or external command, operable program or batch file. Building ..\bin\Debug\dte_idl.success failed! Here is my VSSDK AND WINSDK: VSSDK100Install = C:\Program Files (x86)\Microsoft Visual Studio 2010 SDK SP1 WindowsSdkDir = C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A How can I do? Thank you. You have spaces in your path, which is not good. Put quotes around the file paths, like so: VSSDK100Install = C:\Program Files (x86)\Microsoft Visual Studio 2010 SDK SP1 WindowsSdkDir = C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A
Re: Inspecting lambda parameters
On Saturday, 10 May 2014 at 10:56:57 UTC, Jacob Carlborg wrote: I know that there are templates to inspect function parameters, like ParameterIdentifierTuple and ParameterTypeTuple. But these don't work for templated/untyped lambdas, they're apparently not callables. I don't expect ParameterTypeTuple to work, but it would be nice if ParameterIdentifierTuple and arity worked. Here's an example for clarify: void foo (alias func) () { alias Types = ParameterTypeTuple!(func); } void main () { foo!(x = x * 2); } Anyone know if this is fixable or if there's a workaround? I would like to avoid using hacks like .stringof. I know there's __parameters as well, but that doesn't work either. Wasn't there recently a pull request to add TemplateArgsOf, or something like that. Also, if you know what type the lambda is going to be instantiated with, you can turn it into a function by doing: void foo (alias func) () { alias Types = ParameterTypeTuple!(func!int); }
Re: Inspecting lambda parameters
On 2014-05-10 18:56, Meta wrote: Wasn't there recently a pull request to add TemplateArgsOf, or something like that. There's this pull request [1] that adds a couple of new traits that might help. Also, if you know what type the lambda is going to be instantiated with, you can turn it into a function by doing: void foo (alias func) () { alias Types = ParameterTypeTuple!(func!int); } Unfortunately I don't know the types it's going to be instantiated with. That's part of the introspecting to figure out. [1] https://github.com/D-Programming-Language/dmd/pull/3515 -- /Jacob Carlborg
Temporary silence output (stdout)
Hi! I sometimes got a useless messages in stdout from SDL_Image library, and I want to temporary silence it. How do I do?
Re: Temporary silence output (stdout)
On Saturday, 10 May 2014 at 20:24:50 UTC, MarisaLovesUsAll wrote: Hi! I sometimes got a useless messages in stdout from SDL_Image library, and I want to temporary silence it. How do I do? Consider using either version or debug statements. If you want the messages to be opt-in, debug statements are quite useful: debug(myModule) writeln(Hello world!); Which will only print when you compile with -debug=myModule If you want more power than that, version statements can be useful. First declare (or don't) a specific version (or several): version = MyVersion; Then conditionally compile code based on that: version(MyVersion) { writeln(Hello World); } Note that the compiler declares some versions automatically, such as version(unittest) when compiling with --unittest.
Re: Temporary silence output (stdout)
On 05/10/14 22:24, MarisaLovesUsAll via Digitalmars-d-learn wrote: I sometimes got a useless messages in stdout from SDL_Image library, and I want to temporary silence it. How do I do? One way would be something like: import std.stdio; void writeOutput () { static c = 1; printf(%d\n, c++); } void main() { writeOutput(); { auto ex = PushFD!1(/dev/null.ptr); writeOutput(); } writeOutput(); } struct PushFD(int fd) { import core.sys.posix.fcntl, core.sys.posix.unistd; int old; this(const char* fn) { // old = dup(fd); auto nfd = open(fn, O_RDWR); dup2(nfd, fd); close(nfd); } ~this() { dup2(old, fd); close(old); } } // In real code you'll want to check for errors from dup/dup2/open/close. artur
Re: Down the VisualD0.3.38-1.exe ,found virus!
You have spaces in your path, which is not good. Put quotes around the file paths, like so: VSSDK100Install = C:\Program Files (x86)\Microsoft Visual Studio 2010 SDK SP1 WindowsSdkDir = C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A Thank you.
Re: core.sync.rwmutex example
On Friday, 9 May 2014 at 23:12:44 UTC, Charles Hixson via Digitalmars-d-learn wrote: But I'm worried about the receiving end. It needs, somehow, to ensure that the message it receives is the appropriate message, and that other messages don't get dropped while it's waiting for the answer...or, perhaps worse, substituted for the expected answer. If I can depend on msg[0] of auto msg = receiveOnly!(Tid, bool) that will allow me to check that the message was received from the proper source If you are worried that other messages having the same signature will be sent from other sources than the expected source you could make use of message tagging. Simply wrap the boolean result in a struct with a descriptive name. struct SharedHashMapSetCB { bool flag; } void set (string s, uint64_t id) { tbl[s] = id; send (SharedHashMapSetCB(true)); } //On the receiving end auto msg = receiveOnly!SharedHashMapSetCB(); But doesn't this design lock the entire hash-table while the update is in progress? Is there a better way? I think a shared memory hash-map is better for your use case. Working with message passing is preferable done asynchronously. Blocking calls (send followed by receive) is likely to be slower then simply waiting on a semaphore.
Configuring Phobos from the 1-click installer
After using the 1-click Ubuntu installer, I'm having trouble figuring out how to import standard library functions for Phobos. I get the message: Error: module io is in file 'std/std/io.d' which cannot be read import path[0] = /usr/include/dmd/phobos import path[1] = /usr/include/dmd/druntime/import Sorry for such a basic question, but I am new to linux. Do I need to modify my path, or is Phobos just not located in the right directory?
Messy code in console
When there are Chinese characters in the output, the console will display messy code.I change the encoding of the source file into UTF-8 or UTF-16,but the messy code is still there... I use the dmd 2.065,Visual Studio 2013 with VisualD. How to solve this problem? Thank you!
Re: Messy code in console
On 05/10/2014 07:19 PM, IceNature via Digitalmars-d-learn wrote: When there are Chinese characters in the output, the console will display messy code.I change the encoding of the source file into UTF-8 or UTF-16,but the messy code is still there... I use the dmd 2.065,Visual Studio 2013 with VisualD. How to solve this problem? Thank you! If this is on Windows, you must 1) Set the console code page to 65001 e.g. by the command chcp 65001 (It is possible to make it the default through a Windows registry setting.) 2) Set the font to a unicode one e.g. Lucida Ali
Re: Configuring Phobos from the 1-click installer
On 05/10/2014 07:12 PM, Moses wrote: After using the 1-click Ubuntu installer, I'm having trouble figuring out how to import standard library functions for Phobos. I get the message: Error: module io is in file 'std/std/io.d' which cannot be read Judging from the repeated stds up there I think you put a dot before io: import std.std.io; // -- WRONG The second dot should not be there. Do this instead: import std.stdio; // -- correct Ali
Re: Down the VisualD0.3.38-1.exe ,found virus!
You have spaces in your path, which is not good. Put quotes around the file paths, like so: VSSDK100Install = C:\Program Files (x86)\Microsoft Visual Studio 2010 SDK SP1 WindowsSdkDir = C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A Sorry,Meta, the problem still exists,but I compile it by bat file. Then I compile the Visual D, found the error : [1] cannot read file port\sharedvenusids.d [2] no file in 'sdk/win32' -- start all build: project: vsi, Debug Win32 -- Building ..\bin\Debug\vsi.lib... Error: cannot read file port\sharedvenusids.d Building ..\bin\Debug\vsi.lib failed! Thank you,Meta
Re: Messy code in console
On Sunday, 11 May 2014 at 02:38:44 UTC, IceNature via Digitalmars-d-learn wrote: When there are Chinese characters in the output, the console will display messy code.I change the encoding of the source file into UTF-8 or UTF-16,but the messy code is still there... I use the dmd 2.065,Visual Studio 2013 with VisualD. How to solve this problem? Thank you You can get answer from here: http://forum.dlang.org/thread/ucfpqgzzxcacqxkdr...@forum.dlang.org
Re: Configuring Phobos from the 1-click installer
On Sunday, 11 May 2014 at 04:33:24 UTC, Ali Çehreli wrote: On 05/10/2014 07:12 PM, Moses wrote: After using the 1-click Ubuntu installer, I'm having trouble figuring out how to import standard library functions for Phobos. I get the message: Error: module io is in file 'std/std/io.d' which cannot be read Judging from the repeated stds up there I think you put a dot before io: import std.std.io; // -- WRONG The second dot should not be there. Do this instead: import std.stdio; // -- correct Ali Thanks, I also found that I need to include the flag -I/usr/include/dmd/phobos to get it to compile. I tried doing: export PATH=$PATH:/usr/include/dmd/phobos but apparently I still need the -I flag. Is there another way to get around this?