I'm trying to create a type that for all intents and purposes
behaves exactly like an int except that it limits its values to
be within a certain range [a,b]. Theoretically, I would think
this looks something like:
struct FixedRangeInt {
this(int min, int max, int value=0) {
this.min = m
On Thursday, 5 May 2016 at 12:54:08 UTC, Nordlöw wrote:
Is there a way to calculate unique enum members without using
sort, such as *not* done in my current implementation:
auto uniqueEnumMembers(T)()
{
import std.traits: EnumMembers;
import std.algorithm: sort, uniq;
return [EnumMe
Oh well :(.
Yeah, it's just for debugging. I want to publish a script that
automatically gathers relevant debug information so that my users
can just copy paste it all into one place, ready for me to take a
look even if I can't repro. One of the primitives in my script is
a wrapper around std.pro
I'd like to be able to know if my destructor is being called
because an exception was thrown. Any way to do that?
I tried this: http://ideone.com/JbXH2w
(Pasted here for convenience):
import std.stdio, std.exception;
struct Catcher {
~this() {
try {} catch (Exception e
On Saturday, 18 April 2015 at 01:04:24 UTC, Adam D. Ruppe wrote:
map evaluates its arguments on demand. Think of it as returning
a function that does the work instead of actually doing the
work - you still need to call that function, which happens when
you loop over it.
std.algorithm.each is
Why can't I print things using the map algorithm?
Specifically: http://ideone.com/VLp4Xa
Not quite. You'll note that I am creating the elements in the
associative array, not just iterating over them; some of them
just happen to be duplicates. FWIW: That foreach happens to be
over an input stream.
I'm presently trying to create the value of a key in an
associative array if it does not exist, and then maintain a
reference/pointer to the value. This is what I came up with, but
it seems really crufty and I feel that there must be a cleaner
way:
Value[string] assocArray;
foreach (...) {
On Monday, 2 March 2015 at 23:07:30 UTC, Ali Çehreli wrote:
immutable string bar;
shared static this()
{
bar = painfulToInitialize();
}
void foo() {
}
Clever :).
> I don't need the thread-safety that C++ provides in that case,
I am not aware of such safety. (?) Is that a newer C++ fea
I'm looking for the D equivalent of:
//C++
void foo() {
static string bar = painfulToInitialize(); //Always returns the
same value
/* A bunch of code */
}
I don't need the thread-safety that C++ provides in that case,
though it wouldn't hurt. I'm essentially trying to memoize the
result
Ahhh right - forgot about that. Thanks!
Not that it's super important, but the link didn't copy well, so
here's that:
http://www.informit.com/articles/article.aspx?p=1407357&seqNum=12
What's the idiomatic way of getting everything *before* the
results of a call to find?
assert("hello world".find(" world").what_goes_here??? == "hello");
In an article Andrei wrote a few years ago
(http://www.informit.com/articles/article.aspx…) he mentioned a
function like this with the name
Loading multiple D shared libraries isn't supported on OS X
yet, see these warnings in druntime:
https://github.com/D-Programming-Language/druntime/blob/master/src/rt/sections_osx.d#L198
If you only have a single D shared library, I think it's
possible, you just may have to tweak dmd/druntim
I am presently trying to port a driver I wrote for Windows to
OSX. The one thing standing in my way is figuring out how to get
the equivalent of DllMain on OSX.
I need a place to call Runtime.initialize() and whatnot.
Reading the wiki, it seemed like `shared static this()` was the
appropriat
Resolved the issue.
Managed to build it successfully I think, but have actually
returned to the problem that initially caused me to want to try
and build the library in the first place:
If I try to build a simple program:
import std.stdio;
import std.net.curl;
void main() {
writeln("Hello world");
}
The progra
I am attempting to make use of std.net.curl and having trouble
acquiring libcurl for 64 bit Windows. I need to be able to link
with the MSVC linker (which happens to be the default when
compiling using dmd with -m64). I've looked on the libcurl
website and not found any downloads that look promisi
How can I free the memory used by an associative array?
I need to be able to reuse the same array, but set it to an empty
state and free up the memory it used previously.
I do not believe that setting the associative array to null is
sufficient to free the memory, as it is possible that someone
I found that if I told dmd rather than gcc to do the linking that
everything just magically worked.
In other words:
gcc -c cstuff.c
dmd -c dstuff.d
dmd cstuff.o dstuff.o
I presume that dmd would be similarly smart with static libraries.
Still unresolved, but a thought:
I decided to take a step back and try to link with C on Linux
first. I found out that if I did the linking step with dmd things
worked, but not with gcc. The reason then became apparent: dmd
knows to pass druntime and phobos and all of that stuff to the
linker. Ru
On Thursday, 5 June 2014 at 22:59:48 UTC, bearophile wrote:
Mark Isaacson:
My attempts to have either the MinGW linker or the Visual
Studio
linker accept my D .objs have all failed.
Try using the dmc compiler for the C code.
Bye,
bearophile
I'd considered that, but in the long term
I'm having a very difficult time figuring out exactly how to do
this. I've compiled my D code into a .obj file with dmd, but I
don't know what C compiler I should use (or if it makes any
difference). I've attempted to use MinGW gcc, which spits out .o
files, and Visual Studio, which does... someth
I'm having fun running some unittests. I set up a simple homemade
mock of std.net.curl's functions that essentially just consists
of a global queue that I can add strings to and get back in a
predictable order when calling std.net.curl.get/post/etc.
I use this mock in a couple of different module
On Wednesday, 28 May 2014 at 20:20:37 UTC, Adam D. Ruppe wrote:
On Wednesday, 28 May 2014 at 20:19:45 UTC, Mark Isaacson wrote:
Is there a mechanism that allows you to loop over all of an
enum's values? I've wanted to do so a couple times now for
CTFE/mixin templates.
__traits(allM
Is there a mechanism that allows you to loop over all of an
enum's values? I've wanted to do so a couple times now for
CTFE/mixin templates.
I was able to loop over the underlying type when my enum was
integer-based, but I can't do that if the values are strings
(also that solution is quite hacky
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
An exceptionally generous offer! May take you up on that. Thank
you :).
Indeed. However, doing so looks more painful than redefining my
goals. Upon further examination it seems that I had more
flexibility than I originally estimated. Besides, the real reason
I'm implementing this project is just to practice for when I get
to write production D code in a week anyway
Fair enough. I've done stuff like that in the past. I'm trying to
implement a university project that was originally designed for
C++ style I/O... and so where I'd have otherwise jumped at
something like that from the beginning, my hands are slightly
tied.
Suppose I'll make due/not fully comp
I'm trying my hand at reading from standard input and having
little luck. In particular, I would like to be able to do the
rough equivalent of C++'s:
cin >> myString;
As opposed to reading the whole line.
I attempted to do this with readf:
string result;
readf(" %s ", &result);
However th
On Monday, 5 May 2014 at 03:57:54 UTC, Andrey wrote:
Guys, could someone help me with suitable template?
I have C macro, which calculates the offset of the field in a
struct:
#define offsetof(type, field) ((long) &((type *)0)->field)
A similar D code is, as far as I know,
type.field.offse
Interesting. I clearly have more to learn about Tuple. I think I
concur with Dicebot's alterations for self-documentation.
Thanks for all of your suggestions gentlemen.
On Sunday, 4 May 2014 at 21:40:04 UTC, bearophile wrote:
Mark Isaacson:
2) Create a wrapper struct that contains key and value and
whose comparison operator is defined only on the key. This
would essentially be doing what the C++ implementation does.
Until we have a tree-based associative
I'm looking for a means to associate a key with a value and
iterate over said container in-order. My natural choice in C++
would be std::map. When I look in std.container, I see that there
is a RedBlackTree implementation, however this does not associate
a key with a value (it is the equivale
Thanks for the insights! I suppose we'll get a chance to see
where things stand at this year's dconf.
It's quite interesting that D's concept of r-values seems less
developed than C++. Here's hoping that that only results in a
better thought out solution.
What actually fails is the initialization of 'a'.
Add another
this(A a) { /* Stuff */ }
constructor to the 'A' struct, and it will work.
And, yes, the missing cpctors are a language problem.
artur
Thanks. Yeah, I figured I could do that, I was just hoping that I
could leverage the po
@bearophile - Unless I'm missing something, alas, no. Neither A
nor B is a subtype of the other. In particular, in the real code
one is a CartesianVector and the other a PolarVector. For what
it's worth, 'foo' is actually opBinary addition.
Thanks for the thought though.
Did some thinking: Realized that the appropriate mechanism to
express that A and B are two ways of representing the same thing
is to do so via opCast. I had not considered this option
carefully initially as I am translating someone else's C++ code
to D and hoped that they had used the appropria
I have just discovered that the postblit constructor is not able
to be invoked like a "normal" constructor, or, as one would
manually do so in C++ with a copy constructor. Accordingly I have
a couple questions:
1) What are the various ways to invoke the postblit constructor?
I have not tested
Auto ref parameters seem to be just what I need. Thanks! I'd
still be curious if anyone has additional information regarding
the rationale at play (I'm spoiled, reading TDPL and having each
decision explained in text).
I'm in the process of learning/practicing D and I noticed
something that seems peculiar coming from a C++ background:
If I compile and run:
void fun(const ref int x) {
//Stuff
}
unittest {
fun(5); //Error! Does not compile
}
I get the specified error in my unit test. I understand that the
Much appreciated everyone! I had a vague intuition that these
were the reasons, but it was helpful to spell them out. I'm
especially partial to the self-documentation reasoning.
I am presently working my way through TDPL for the second time,
and there's an example in chapter 1 to the effect of:
[code]
string currentParagraph;
foreach(line; stdin.byLine()) {
if (line.length > 2) {
currentParagraph = to!string(line[2 .. $]);
}
}
[/code]
The explicit conversion
Hi everyone - I'm a D newbie with a very strong C++ background
looking to get started. I've read "The D Programming Language" a
couple of times now, but I've heard rumblings at several points
in time from several people that some if its contents are now out
of date or no longer reflect best pra
45 matches
Mail list logo