On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
...
I think reflection will be a bad choice for this because of
private members and what not.
I think the correct way is:
void reset(C)(ref C c)
{
static if(is(C == class))
{
auto init =
On Friday, 4 December 2015 at 04:08:33 UTC, Tofu Ninja wrote:
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
...
I think reflection will be a bad choice for this because of
private members and what not.
I think the correct way is:
void reset(C)(ref C c)
{
static
On Friday, 4 December 2015 at 01:10:41 UTC, Jim Barnett wrote:
Really? If it leads to "hard to detect errors", I have a hard
time believing that can be "idiomatic D".
It's used throughout the standard library, granted I don't think
there's any occurrences of importing inside a while loop. The
On Friday, 4 December 2015 at 03:33:55 UTC, Meta wrote:
I have never seen a language that encourages the user to
specify dependencies inside a loop. I am hoping I
misunderstood something here.
Sorry, I thought you were referring more generally to nested
imports. No, imports in a while loop
void main()
{
auto router = new URLRouter;
router.get("/",
serveStaticFiles("D:\\code\\onlineTest\\index.html"));
router.get("/admin",
serveStaticFiles("D:\\code\\onlineTest\\admin.html"));
router.any("/foo", );
auto settings = new HTTPServerSettings;
settings.port =
On Wednesday, December 02, 2015 06:33:32 Andre via Digitalmars-d-learn wrote:
> Hi,
>
> for following coding there is an error during compilation:
>
>module utils;
>
>package string toBulkString(string s)
>{
> import std.string: format;
> return "$%s\r\n%s\r\n".format(s.length,
Hi,
I started an experiment with the informations that are available for
compile time reflection.
What I wanted to create is a thor like cli parser library, that forces
you to encapsulate your programs into subclasses of Dli. The commands
and options, that are understood by the generated cli
On Thu, 03 Dec 2015 06:38:20 +, Mike Parker wrote:
> AFAIK, your only option is to use a struct constructor. This is the sort
> of thing they're used for.
Which brings be back to positional arguments, which means that someone
wishing to supply a limit on the number of query results must
On Thursday, 3 December 2015 at 21:13:59 UTC, Nordlöw wrote:
Need to assert that not a function and mutability
(std.traits.isMutable)
Yeah you need to do that.
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
Given
class C
{
// lots of members
}
and a function
f(C c)
{
}
is there a generic way, perhaps through reflection, to reset
(inside f) all members of `c` to their default values?
Something along
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
Something along
foreach(ref member; __traits(allMembers, c))
{
member = typeof(member).init;
}
This works for me:
void resetAllMembers(T)(T c)
if (is(T == class))
{
foreach (ref m; c.tupleof)
{
On Thu, 03 Dec 2015 21:40:05 +, Jim Barnett wrote:
> TL;DR I couldn't figure out how to write `isPalindrome` in terms of
> std.algorithm.mutation.reverse
>
> I recognize it's more efficient in terms of CPU time and memory than my
> C++ solution, but I suspect there is a shorter expression to
On Thursday, 3 December 2015 at 22:14:02 UTC, Justin Whear wrote:
I don't think you want reverse because it works in-place; you'd
need to make a copy to compare against. std.range.retro is
probably what you're looking for:
bool isPalindrome(R)(R range) if (isBidirectionalRange!R)
{
On Thursday, 3 December 2015 at 21:38:48 UTC, Chris Wright wrote:
The terrible way is something like:
void reset(Object o)
in {
assert(!(o is null));
}
body {
auto p = cast(ubyte*)*cast(void**)
auto ci = o.classinfo;
auto init = cast(ubyte)ci.init;
p[0..init.length] = init[];
if
On Thu, 03 Dec 2015 21:55:04 +, Nordlöw wrote:
> On Thursday, 3 December 2015 at 21:38:48 UTC, Chris Wright wrote:
>> The terrible way is something like:
>>
>> void reset(Object o)
>> in {
>> assert(!(o is null));
>> }
>> body {
>> auto p = cast(ubyte*)*cast(void**)
>> auto ci =
On Thursday, 3 December 2015 at 15:31:49 UTC, Chris Wright wrote:
On Thu, 03 Dec 2015 06:38:20 +, Mike Parker wrote:
AFAIK, your only option is to use a struct constructor. This
is the sort of thing they're used for.
Which brings be back to positional arguments, which means that
Given
class C
{
// lots of members
}
and a function
f(C c)
{
}
is there a generic way, perhaps through reflection, to reset
(inside f) all members of `c` to their default values? Something
along
foreach(ref member; __traits(allMembers, c))
{
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
is there a generic way, perhaps through reflection, to reset
(inside f) all members of `c` to their default values?
You could always copy the init back over it. For a struct:
s = Struct.init;
for a class... well, the code is a lot
TL;DR I couldn't figure out how to write `isPalindrome` in terms
of std.algorithm.mutation.reverse
I have dabbled in D a few times over the past few years, but
still pretty inexperienced. I decided to work on some project
euler problems in D for fun. A problem requires detecting a
On Thursday, 3 December 2015 at 21:04:00 UTC, Nordlöw wrote:
Given
class C
{
// lots of members
}
and a function
f(C c)
{
}
is there a generic way, perhaps through reflection, to reset
(inside f) all members of `c` to their default values?
Something along
Haven't compiled but it should look something like this:
foreach(member; __traits(allMembers, typeof(c)))
__traits(getMember, c, member) = typeof(__traits(getMember,
c, member)).init;
On Thursday, 3 December 2015 at 21:08:30 UTC, Sebastiaan Koppe
wrote:
Haven't compiled but it should look something like this:
foreach(member; __traits(allMembers, typeof(c)))
__traits(getMember, c, member) = typeof(__traits(getMember,
c, member)).init;
Need to assert that not a function
The terrible way is something like:
void reset(Object o)
in {
assert(!(o is null));
}
body {
auto p = cast(ubyte*)*cast(void**)
auto ci = o.classinfo;
auto init = cast(ubyte)ci.init;
p[0..init.length] = init[];
if (ci.defaultConstructor) {
ci.defaultConstructor(o);
} else {
On Saturday, 21 November 2015 at 14:16:26 UTC, Laeeth Isharc
wrote:
Not sure it is a great idea to use a variant as the basic
option when very often you will know that every cell in a
particular column will be of the same type.
I'm reading today about an n-dim extension to pandas named
On Thursday, 3 December 2015 at 21:40:05 UTC, Jim Barnett wrote:
Thanks for reading.
My version slightly adjusted version:
/** Returns: If range is a palindrome larger than $(D minLength).
See also:
On Friday, 4 December 2015 at 00:23:45 UTC, Jim Barnett wrote:
The `import` statement inside the `for`-loop kind of smells to
me.
Sorry, inside the `while` loop
On Friday, 4 December 2015 at 00:26:23 UTC, Jim Barnett wrote:
On Friday, 4 December 2015 at 00:23:45 UTC, Jim Barnett wrote:
The `import` statement inside the `for`-loop kind of smells to
me.
Sorry, inside the `while` loop
In D it's considered idiomatic, but it can also cause some very
On Thursday, 3 December 2015 at 23:42:31 UTC, Nordlöw wrote:
On Thursday, 3 December 2015 at 21:40:05 UTC, Jim Barnett wrote:
Thanks for reading.
My version slightly adjusted version:
/** Returns: If range is a palindrome larger than $(D
minLength).
See also:
On Friday, 4 December 2015 at 00:50:17 UTC, Meta wrote:
On Friday, 4 December 2015 at 00:26:23 UTC, Jim Barnett wrote:
On Friday, 4 December 2015 at 00:23:45 UTC, Jim Barnett wrote:
The `import` statement inside the `for`-loop kind of smells
to me.
Sorry, inside the `while` loop
In D
On Friday, 4 December 2015 at 00:50:17 UTC, Meta wrote:
On Friday, 4 December 2015 at 00:26:23 UTC, Jim Barnett wrote:
On Friday, 4 December 2015 at 00:23:45 UTC, Jim Barnett wrote:
The `import` statement inside the `for`-loop kind of smells
to me.
Sorry, inside the `while` loop
In D
30 matches
Mail list logo