On Wednesday, 6 August 2014 at 04:14:51 UTC, Puming wrote:
1. The only way that I can initialize it is to assign a value.
But I want to initialize an empty AA, is that possible?
workaround:
string[string] aa;
assert(aa is null);
aa[""] = "";
aa.remove("");
assert(aa !is null);
On Wednesday, 6 August 2014 at 04:14:51 UTC, Puming wrote:
On Thursday, 31 July 2014 at 10:22:28 UTC, Marc Schütz wrote:
On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote:
1. Are AAs reference type? if so, why does the compiler copy
it?
This is probably your problem. They are reference
On Thursday, 31 July 2014 at 10:22:28 UTC, Marc Schütz wrote:
On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote:
1. Are AAs reference type? if so, why does the compiler copy
it?
This is probably your problem. They are reference types, but
initially that reference is `null`. When you wri
On Thursday, 31 July 2014 at 02:03:37 UTC, Puming wrote:
1. Are AAs reference type? if so, why does the compiler copy it?
This is probably your problem. They are reference types, but
initially that reference is `null`. When you write:
auto cmds = CONFIG.commands;
`cmds` contains a copy
V Thu, 31 Jul 2014 02:03:35 +
Puming via Digitalmars-d-learn
napsáno:
> Hi,
>
> I'm writing this global Config class, with an AA member:
>
> ```d
> module my.config;
>
> class Config
> {
> Command[string] commands;
> }
>
> __gshared Config CONFIG;
> ```
>
> and initialize it in anot
Hi,
I'm writing this global Config class, with an AA member:
```d
module my.config;
class Config
{
Command[string] commands;
}
__gshared Config CONFIG;
```
and initialize it in another module:
```d
module my.app;
import my.config;
void main()
{
CONFIG = new Config();
CONFIG.command
true size of an
object:
MyClass* buffer =
cast(MyClass*)GC.calloc(__traits(classInstanceSize,
MyClass) * 10);
That got me thinking, how would i actually 'fill' this memory
with
instances of that class?
std.conv.emplace:
http://dlang.org/phobos/std_conv.html#.emplace
Wow, t
On Thu, 24 Jul 2014 17:07:29 +, Justin Whear wrote:
> On Thu, 24 Jul 2014 17:05:17 +, Gary Willoughby wrote:
>
>> I was reading Ali's book (http://ddili.org/ders/d.en/index.html)
>> and saw this piece of code on how to get the true size of an object:
>>
>
Am 24.07.2014 19:05, schrieb Gary Willoughby:
I was reading Ali's book (http://ddili.org/ders/d.en/index.html) and saw
this piece of code on how to get the true size of an object:
MyClass* buffer = cast(MyClass*)GC.calloc(__traits(classInstanceSize,
MyClass) * 10);
That got me thinking
On Thursday, 24 July 2014 at 17:05:18 UTC, Gary Willoughby wrote:
I was reading Ali's book
(http://ddili.org/ders/d.en/index.html) and saw this piece of
code on how to get the true size of an object:
MyClass* buffer =
cast(MyClass*)GC.calloc(__traits(classInstanceSize, MyClass)
I was reading Ali's book (http://ddili.org/ders/d.en/index.html)
and saw this piece of code on how to get the true size of an
object:
MyClass* buffer =
cast(MyClass*)GC.calloc(__traits(classInstanceSize, MyClass) *
10);
That got me thinking, how would i actually 'fill' th
On Thu, 24 Jul 2014 17:05:17 +, Gary Willoughby wrote:
> I was reading Ali's book (http://ddili.org/ders/d.en/index.html)
> and saw this piece of code on how to get the true size of an object:
>
> MyClass* buffer = cast(MyClass*)GC.calloc(__traits(classInstanceSize
You can also try class invariant.
On Saturday, 19 July 2014 at 17:05:27 UTC, Sean Campbell wrote:
surely not by writing another class with wrapper methods for
the existing one.
If you don't want to write the class, you can write a generator
for it. See BlackHole wrapper for an example.
On Saturday, 19 July 2014 at 17:28:13 UTC, Frustrated wrote:
If you do this you are potentially asking for a lot of access
violation errors or undefined behavior.
Of course, the object should not be used after destruction. The
trick is to reliably diagnose it. If such uses are not
On Saturday, 19 July 2014 at 12:02:50 UTC, Sean Campbell wrote:
is there any way for an object to make it self no longer
usable? eg
class someclass {
string somevalue;
bool someflag;
int somelength;
this (value,length,flag) {
somevalue = value
On Saturday, 19 July 2014 at 13:46:08 UTC, Kagamin wrote:
You can encapsulate it in a wrapper, which will control access
to the object and reject if necessary.
how ?
surely not by writing another class with wrapper methods for the
existing one.
You can encapsulate it in a wrapper, which will control access to
the object and reject if necessary.
is there any way for an object to make it self no longer usable?
eg
class someclass {
string somevalue;
bool someflag;
int somelength;
this (value,length,flag) {
somevalue = value;
someflag = flag;
somelength
On Wednesday, 16 July 2014 at 00:38:46 UTC, Puming wrote:
3. define all classes and use template magic to generate
companion builders just like protobuffer does. But that would
be complicated and I don't know how to do it. Do you have any
suggestion for this approach?
This would probably be a
the docs, it does what
'freeze' does, and is considered idiomatic.
But the draw back is that you can't garanteed that the mutable
object is never used.
I got the impression that assumeUnique has the same problem.
Regards
On Tuesday, 15 July 2014 at 17:06:14 UTC, Ali Çehreli wrote:
On 07/15/2014 09:39 AM, Anonymous wrote:
> struct Subscription {
> const Object handle;
> private immutable size_t index;
> @disable this();
> private this(Object o, size_t i) {
>
class
at compile time?
There's no real idiomatic approach, I think, because this is
somewhat unexplored territory. I'd say constructing the object
inside a pure method so it can be implicitly cast to immutable
is more typesafe, but if you're storing the immutable reference
to t
c approach, I think, because this is
somewhat unexplored territory. I'd say constructing the object
inside a pure method so it can be implicitly cast to immutable is
more typesafe, but if you're storing the immutable reference to
the object in a class or struct, it can only be initiali
On 07/15/2014 09:39 AM, Anonymous wrote:
> struct Subscription {
> const Object handle;
> private immutable size_t index;
> @disable this();
> private this(Object o, size_t i) {
> handle = o;
> index = i;
> }
> }
>
> I
struct Subscription {
const Object handle;
private immutable size_t index;
@disable this();
private this(Object o, size_t i) {
handle = o;
index = i;
}
}
I'd like this to be constructed with a handle to some object
On Tuesday, 15 July 2014 at 13:59:24 UTC, Ali Çehreli wrote:
On 07/15/2014 05:20 AM, Puming wrote:
I found another way to do this, namely first create a class
that is
mutable, then cast it to an immutable object before using it.
```d
class A {
int a;
B b;
this(int a, int b
On 07/15/2014 05:20 AM, Puming wrote:
I found another way to do this, namely first create a class that is
mutable, then cast it to an immutable object before using it.
```d
class A {
int a;
B b;
this(int a, int b)
{
this.a = a;
this.b = new B(b
I found another way to do this, namely first create a class that
is mutable, then cast it to an immutable object before using it.
```d
class A {
int a;
B b;
this(int a, int b)
{
this.a = a;
this.b = new B(b);
}
}
class B
class is companioned by a Builder class, with the
same field of the immutable data class.
3. To create a data object, first create a Builder, then set the
fields when ever you want.
I want to emulate this process, but without needing to create two
classes for one data class (protobuff does this
Thanks! that was perfect.
-Harpo
On Wednesday, 4 June 2014 at 04:46:59 UTC, ed wrote:
On Wednesday, 4 June 2014 at 03:49:25 UTC, Harpo wrote:
Hello I am having the following problem. I am trying to turn a
program I have written into a shared object. I have ran into
some problems however. When I use writeln instead of printf
On Wednesday, 4 June 2014 at 03:49:25 UTC, Harpo wrote:
Hello I am having the following problem. I am trying to turn a
program I have written into a shared object. I have ran into
some problems however. When I use writeln instead of printf my
program segfaults. I have edited the code to just
Hello I am having the following problem. I am trying to turn a
program I have written into a shared object. I have ran into some
problems however. When I use writeln instead of printf my program
segfaults. I have edited the code to just the parts causing the
problem.
=main.d
On Monday, 19 May 2014 at 20:18:40 UTC, Adam D. Ruppe wrote:
On Monday, 19 May 2014 at 20:11:45 UTC, Spacen wrote:
The same code works on windows DMD 1.65. But on linux:
It's because of caching. isDir on Linux calls a function with
this comment:
/++
This is to support la
On Monday, 19 May 2014 at 20:11:45 UTC, Spacen wrote:
The same code works on windows DMD 1.65. But on linux:
It's because of caching. isDir on Linux calls a function with
this comment:
/++
This is to support lazy evaluation, because doing
stat's is
expensive
The same code works on windows DMD 1.65. But on linux:
delold.d(54): Error: mutable method std.file.DirEntry.isDir is
not callable using
a const object
[code]
bool printFile(in DirEntry dirEntry, in Duration age, Options
options)
{
immutable string type = dirEntry.isDir ? "dire
Chris Piker:
Is there any way to get a list of the properties and functions
provided by a module or class or generic variable in D at
runtime?
In D there are various traits to do that a compile-time. Like:
http://dlang.org/traits.html#allMembers
There are also the Phobos traits:
http://dlang
Is there any way to get a list of the properties and functions
provided by a module or class or generic variable in D at
runtime? I've grown quite accustomed to doing the following
kinds of exploration in Python.
With in the python interperter I can issue:
a = some_barely_understood_functio
On Tuesday, 8 April 2014 at 14:26:46 UTC, Adam D. Ruppe wrote:
On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote:
Is there a documentation page about the 'uniform function call
syntax'?
http://dlang.org/function.html#pseudo-member
Oh beat me to it.
On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote:
Is there a documentation page about the 'uniform function call
syntax'?
http://dlang.org/function.html#pseudo-member
On Tuesday, 8 April 2014 at 14:23:02 UTC, Jeroen Bollen wrote:
Is there a documentation page about the 'uniform function call
syntax'?
Never mind, I think I understand all there is to it.
rence to each method would be a double pointer and wasted
effort most the time; all most methods care about is where to
get the object data, they don't need to know how the caller was
getting to the object data.
I don't see why this needs to be a new variable and cannot
simply be '
most
the time; all most methods care about is where to get the object
data, they don't need to know how the caller was getting to the
object data.
I don't see why this needs to be a new variable and cannot
simply be 'passed-by-reference'.
You can get that with UFCS btw:
c
This topic is somewhat related to this question I asked yesterday
on StackOverflow: http://stackoverflow.com/q/22921395/2558778
Basically, why is this its own variable? Why doesn't D simply use
the variable it was called with?
https://gist.github.com/Binero/10128826
I don't see why this need
Yes, in some cases C++ const does not provide const-guarantees,
it's more like convention.
For example, you can write this:
class Class
{
public:
Class() : ptr(new int()) {}
~Class() { delete ptr; }
void setData(int data) const {
*ptr = data;
}
private:
int *ptr;
};
On Thursday, 6 March 2014 at 17:47:34 UTC, bearophile wrote:
There was a very long discussion on this. I think the short
answer is to keep the syntax and semantics composed of a
sufficiently low number of parts (in D you don't have syntax to
tell apart objects from their references).
Thank yo
On Thursday, 6 March 2014 at 15:54:13 UTC, FreeSlave wrote:
You probably need Rebindable template from std.typecons.
Thank you! Rebindable does exactly what I need.
I'm just curious why there is no some syntax to describe the same.
E.g.
const(Foo) foo; // mutable ref to const o
Vadim Lopatin:
Const sub-tree is object itself and its data.
Reference to object is outside of tree.
Why references to const object should be const?
There was a very long discussion on this. I think the short
answer is to keep the syntax and semantics composed of a
sufficiently low number
data they refer to:
http://dlang.org/const3.html
Bye,
bearophile
Const sub-tree is object itself and its data.
Reference to object is outside of tree.
Why references to const object should be const?
Such references cannot be used to modify object anyway.
Vadim Lopatin:
In C++, following code works as I'm expecting:
Different language, different (hopefully better) semantics. In D
const and immutable are transitive, this means they make
const/immutable the whole sub-tree of data they refer to:
http://dlang.org/const3.html
Bye,
bearophile
You probably need Rebindable template from std.typecons.
Hello,
Is there a possibility to define mutable reference to const
object?
I need variable which can be used to iterate through const
objects.
But it seems like const(Foo)p makes constant reference to
constant object instead of mutable reference to const object.
class Bar {
}
unittest
On Saturday, 22 February 2014 at 11:08:41 UTC, evilrat wrote:
On Saturday, 22 February 2014 at 09:09:42 UTC, Tolga Cakiroglu
wrote:
I have written a DLL file in Linux (x86_64). It is as below:
File: lib.dll
=
class A{}
extern(C) void foo(){
Object obj = new Object
On Saturday, 22 February 2014 at 09:09:42 UTC, Tolga Cakiroglu
wrote:
I have written a DLL file in Linux (x86_64). It is as below:
File: lib.dll
=
class A{}
extern(C) void foo(){
Object obj = new Object(); // test 1
A objA = new A(); // test 2
I have written a DLL file in Linux (x86_64). It is as below:
File: lib.dll
=
class A{}
extern(C) void foo(){
Object obj = new Object(); // test 1
A objA = new A(); // test 2
char[] c = new char[ 1024 ]; // test 3
}
Compilation code is below
On Monday, 13 January 2014 at 20:48:11 UTC, Jesse Phillips wrote:
I have a pre-built sqlite3 object file which I'd like to
include as part of the linking for the final executable. I have
been unable to find a way to do this with dub.
I have attempted adding:
"sourceFiles":
I have a pre-built sqlite3 object file which I'd like to include
as part of the linking for the final executable. I have been
unable to find a way to do this with dub.
I have attempted adding:
"sourceFiles": ["csqlite3.obj"],
This doesn't work since it is a
On 12/2/12, 21:25, js.mdnq wrote:
I'm not just comparing them but using them as a unique ID for the
objects in an algorithm to prevent computing over the same object more
than once.
o.toHash() ??
(Which incidentally just casts the reference to a hash_t, exactly what
you want to do.)
s of maps or an object with few
structs inside ?
I rolled my own generalized dup:
https://github.com/patefacio/d-help/blob/master/d-help/opmix/dup.d
I have since changed my philosophy to allow sharing more often
than not - but it can be scary still so dup has advantages.
Here is an example us
Dfr:
I searched through various D documentation sources and did not
found anything except 'std.copy', but it's only for slices.
Is there such feature in standart library ? Or some easy way to
clone for example map of slices of maps or an object with few
structs inside ?
Hi
I searched through various D documentation sources and did not
found anything except 'std.copy', but it's only for slices.
Is there such feature in standart library ? Or some easy way to
clone for example map of slices of maps or an object with few
structs inside ?
parent object is done
this wastes memory for no real reason except ease of use.
Since many objects may contain a ptr to the array, what would
be the best way to deal with deallocating them? I could wrap
the array in a collection an use ARC but is there a better way?
Is there something in
On Saturday, 30 November 2013 at 08:35:23 UTC, Frustrated wrote:
I need to pass around some objects(specifically int[]) that may
be used by several other objects at the same time. While I
could clone these and free them when the parent object is done
this wastes memory for no real reason
the parent object is done
this wastes memory for no real reason except ease of use.
Since many objects may contain a ptr to the array, what would
be the best way to deal with deallocating them? I could wrap
the array in a collection an use ARC but is there a better way?
Is there something in
On Saturday, 30 November 2013 at 08:35:23 UTC, Frustrated wrote:
I need to pass around some objects(specifically int[]) that may
be used by several other objects at the same time. While I
could clone these and free them when the parent object is done
this wastes memory for no real reason
Frustrated:
I need to pass around some objects(specifically int[]) that may
be used by several other objects at the same time. While I
could clone these and free them when the parent object is done
this wastes memory for no real reason except ease of use.
Since many objects may contain a
I need to pass around some objects(specifically int[]) that may
be used by several other objects at the same time. While I could
clone these and free them when the parent object is done this
wastes memory for no real reason except ease of use.
Since many objects may contain a ptr to the array
Michael,
thank you for these links.
Regards, Florian.
Additional discussions
http://forum.dlang.org/thread/jpl93e$1mns$1...@digitalmars.com
and
http://forum.dlang.org/thread/l3dj7b$2tvc$1...@digitalmars.com
Jonathan,
Dicebot,
thank you very much for your response. So you are confirming my
conclusion, that finalizers/destructors in D work pretty much
like in C++ and there is no way to do Java/C#/Managed C++-like
finalization.
For the records, since Dicebot asked: I am using DMD32 v2.063.2
on De
On Tuesday, 12 November 2013 at 22:40:26 UTC, Florian wrote:
The example below prints the following output:
~Connection
~Session
segmentation fault
Same example prints this for me (no segfault):
~Session
shutdown
~Connection
2.064.2 @ linux-64
What is your system / compiler? Outp
On Tuesday, 12 November 2013 at 23:18:11 UTC, Jonathan M Davis
wrote:
You can't do that in
finalizer, because the GC can choose to free it before the
finalizer even runs
(this avoids issues with circular references).
Ah, damn, have forgotten about it. Disregard previous post.
(and not on the GC heap aside from the
fact that the instance of the class is itself on the GC heap) or which is not
managed by the GC at all (e.g. it was malloced, or it was some other sort of
system resource that the GC doesn't manage).
If you want your Connection object to shutdown when
I understood very well, that the garbage collector is not
guaranteed to run. However, it does not explain the segmentation
fault in my example, does it?
On Tuesday, November 12, 2013 23:40:24 Florian wrote:
> it would be possible to move the shutdown() sequence into the
> destructor of the "Connection" class.
Classes in D do not have destructors. Only structs to. ~this is a destructor
in a struct, but it's a finalizer in a class. Finalizers are n
destructed
have been destroyed themselfes (or at least have been brought
into an invalid state). Therefore, these members cannot be
accessed savely from inside the destructor.
What made you think so? It must be other way around. Destructor
is expected to release resources held by object, it is
brought into an
invalid state). Therefore, these members cannot be accessed
savely from inside the destructor.
What made you think so? It must be other way around. Destructor
is expected to release resources held by object, it is necessary
that those resources are still valid at destructor call
.
Managed C++ offers both, C#-like finalizers and conventional C++
destructors, where the destructor is called ~className and the
finalizer is called !className. Is their a best practice to
mimikry this behaviour, i.e. to call a certain block of code when
an object is being garbage collected, but
10.11.2013 23:22, Benjamin Thaut пишет:
Am 10.11.2013 17:06, schrieb Alexandr Druzhinin:
Because in D Classes are reference types. That means the code you wrote
is equivalent to the following C++ source:
class Foo
{
public:
Foo(Object* o)
{
printf("%x\n", &this);
reference types. That means the code you wrote
is equivalent to the following C++ source:
class Foo
{
public:
Foo(Object* o)
{
printf("%x\n", &this); // print a Foo**
}
}
class Bar
{
public:
Bar()
{
printf("%x\n", &this); // print a Bar**
}
}
voi
?
The "bar" values are different, too. And they are, because you're
printing the addresses of the references (variables), not the
addresses of the objects. You can use cast(void*) to get the
address of an object:
class Bar
{
this()
{
writeln(c
Could somebody explain why this http://dpaste.dzfl.pl/248262b9 return this:
Foo:
7FBFD59A50
7FBFD59A80
Bar:
7FBFD59A58
7FBFD59A88
Why this value in ctor is different from this value out of ctor if ctor
gets an argument?
On Tuesday, 1 October 2013 at 17:58:58 UTC, Jacob Carlborg wrote:
On 2013-10-01 18:03, Gary Willoughby wrote:
Are there any plans to allow rdmd to emit object files?
I ask because i have a debugger id like to use that uses
object files
and my project is of sufficient complexity that rdmd is
On 2013-10-01 18:03, Gary Willoughby wrote:
Are there any plans to allow rdmd to emit object files?
I ask because i have a debugger id like to use that uses object files
and my project is of sufficient complexity that rdmd is needed to
correctly compile the dependencies.
What happens if you
Are there any plans to allow rdmd to emit object files?
I ask because i have a debugger id like to use that uses object
files and my project is of sufficient complexity that rdmd is
needed to correctly compile the dependencies.
On Fri, 06 Sep 2013 14:08:19 -0700, Ali Çehreli wrote:
> I think it is the same issue then.
>
> On 09/06/2013 02:00 PM, Jonathan Crapuchettes wrote:
>
> >> > inout(DataT*) opIndex(const Address addr) inout {
>
> Unless Address is an alias of int, there is no matching opIndex overload
>
On 09/06/2013 01:27 PM, Ali Çehreli wrote:
the compiler should
error about not finding a matching foo() overload instead of bringing
the inout into the discussion.
http://d.puremagic.com/issues/show_bug.cgi?id=10982
Ali
On Fri, 06 Sep 2013 13:27:20 -0700, Ali Çehreli wrote:
> On 09/06/2013 01:14 PM, Jonathan Crapuchettes wrote:
>
> > Can someone help me understand how to correct this error?
> >
> > Error: inout method ...ValidSparseDataStore.opIndex is not callable
> > using
I think it is the same issue then.
On 09/06/2013 02:00 PM, Jonathan Crapuchettes wrote:
>> > inout(DataT*) opIndex(const Address addr) inout {
Unless Address is an alias of int, there is no matching opIndex overload
for the following call:
>auto dp = cStore[16057];//<-- ER
Can someone help me understand how to correct this error?
Error: inout method ...ValidSparseDataStore.opIndex is not callable using
a const object
The specific method is defined as:
struct ValidSparseDataStore
{
inout(DataT*) opIndex(const Address addr) inout
{
if (auto node
On 09/06/2013 01:14 PM, Jonathan Crapuchettes wrote:
> Can someone help me understand how to correct this error?
>
> Error: inout method ...ValidSparseDataStore.opIndex is not callable using
> a const object
That error is about opIndex but we don't see any code that makes
On Monday, 12 August 2013 at 19:44:56 UTC, Jacob Carlborg wrote:
On 2013-08-12 17:49, JS wrote:
Sorry but this doesn't work. b is a B, not an A.
try
I a = new A;
I b = new B;
Right, forgot about the interface.
NP, happens to all of us. Simen's method of casting to object
s
On 2013-08-12 17:49, JS wrote:
Sorry but this doesn't work. b is a B, not an A.
try
I a = new A;
I b = new B;
Right, forgot about the interface.
--
/Jacob Carlborg
On Monday, 12 August 2013 at 11:34:25 UTC, Jacob Carlborg wrote:
On 2013-08-11 21:08, Simen Kjaeraas wrote:
If you're looking for a no-overhead solution, then this might
not be
good enough. I'm surprised that a virtual function call is
fine,
though.
How about this:
interface I
{
size_t
On 2013-08-11 21:08, Simen Kjaeraas wrote:
If you're looking for a no-overhead solution, then this might not be
good enough. I'm surprised that a virtual function call is fine,
though.
How about this:
interface I
{
size_t size (this T) ()
{
return __traits(classInstanceSize, T
On Sunday, 11 August 2013 at 18:29:15 UTC, JS wrote:
On Sunday, 11 August 2013 at 18:18:22 UTC, Dicebot wrote:
On Sunday, 11 August 2013 at 17:03:04 UTC, JS wrote:
This is essentially what I'm doing BUT I am trying to avoid
having to repeat the exact same crap in every class because
it is time
Object - it might also be a C++
class, or a COM object, or maybe even a slice into another vtbl
if an Object implements multiple interfaces (not completely
sure about the latter, I'd have to read some source, but it
seems logical to me).
Possibly. Since I program to interfaces,
On Sunday, 11 August 2013 at 19:58:26 UTC, Adam D. Ruppe wrote:
Oh, I see it now. I think typeid(interface) gives a different
set of info.
Thinking about it a bit more, this makes sense because an
interface is not necessarily an Object - it might also be a C++
class, or a COM object, or
writeln(typeid(cast(Object)(f)).init.length);
Just casting the interface to Object before fetching the info.
901 - 1000 of 1502 matches
Mail list logo