On Monday, 30 April 2018 at 10:57:51 UTC, Jonathan M Davis wrote:
On Monday, April 30, 2018 10:36:52 bauss via
Digitalmars-d-learn wrote:
On Saturday, 28 April 2018 at 04:56:26 UTC, lempiji wrote:
> On Friday, 27 April 2018 at 02:59:16 UTC, Dr.No wrote:
>> In C# you can have a readon
On Monday, April 30, 2018 10:36:52 bauss via Digitalmars-d-learn wrote:
> On Saturday, 28 April 2018 at 04:56:26 UTC, lempiji wrote:
> > On Friday, 27 April 2018 at 02:59:16 UTC, Dr.No wrote:
> >> In C# you can have a readonly member assignable either at
> >> declaratio
On Saturday, 28 April 2018 at 04:56:26 UTC, lempiji wrote:
On Friday, 27 April 2018 at 02:59:16 UTC, Dr.No wrote:
In C# you can have a readonly member assignable either at
declaration or constructor time, like this:
class C
{
readonly myClass mc;
this()
{
mc = new myClass
On Friday, 27 April 2018 at 02:59:16 UTC, Dr.No wrote:
In C# you can have a readonly member assignable either at
declaration or constructor time, like this:
class C
{
readonly myClass mc;
this()
{
mc = new myClass();
}
void doSomething()
{
mc = new myClass(); // wrong
On Friday, April 27, 2018 02:59:16 Dr.No via Digitalmars-d-learn wrote:
> In C# you can have a readonly member assignable either at
> declaration or constructor time, like this:
>
> class C
> {
>readonly myClass mc;
>
>this()
>{
> mc = new m
In C# you can have a readonly member assignable either at
declaration or constructor time, like this:
class C
{
readonly myClass mc;
this()
{
mc = new myClass();
}
void doSomething()
{
mc = new myClass(); // wrong! result in compiler error, mc is
readonly
}
}
Does D
On 03/15/2018 03:16 AM, Andrey wrote:
Hello, is there way to declare read only field for class type with
ability to call inner non constant methods? i.e.:
class A {
int value = 12;
void updateValue() {
value = 13;
}
}
class B {
const A a;
this() {
a = new
On Thursday, 15 March 2018 at 13:44:20 UTC, Seb wrote:
On Thursday, 15 March 2018 at 10:57:52 UTC, Mike Parker wrote:
On Thursday, 15 March 2018 at 10:55:16 UTC, Mike Parker wrote:
class A {
private int _value = 12;
int value() @property { return _value; }
void updateValue() { va
On Thursday, 15 March 2018 at 13:44:20 UTC, Seb wrote:
On Thursday, 15 March 2018 at 10:57:52 UTC, Mike Parker wrote:
On Thursday, 15 March 2018 at 10:55:16 UTC, Mike Parker wrote:
[...]
Sorry. I overlooked that B.a is const.
It still works, the `value` just needs to be `const` (or
`inout
On Thursday, 15 March 2018 at 10:57:52 UTC, Mike Parker wrote:
On Thursday, 15 March 2018 at 10:55:16 UTC, Mike Parker wrote:
class A {
private int _value = 12;
int value() @property { return _value; }
void updateValue() { value = 13; }
}
...
auto a = new A();
writeln(a.value);
a
On Thursday, 15 March 2018 at 10:16:49 UTC, Andrey wrote:
Hello, is there way to declare read only field for class type
with ability to call inner non constant methods? i.e.:
class A {
int value = 12;
void updateValue() {
value = 13;
}
}
class B {
const A a;
this(
On Thursday, 15 March 2018 at 10:16:49 UTC, Andrey wrote:
Hello, is there way to declare read only field for class type
with ability to call inner non constant methods? i.e.:
class A {
int value = 12;
void updateValue() {
value = 13;
}
}
class B {
const A a;
this(
On Thursday, 15 March 2018 at 10:55:16 UTC, Mike Parker wrote:
class A {
private int _value = 12;
int value() @property { return _value; }
void updateValue() { value = 13; }
}
...
auto a = new A();
writeln(a.value);
a.updateValue();
writeln(a.value);
Sorry. I overlooked that B.a
Hello, is there way to declare read only field for class type
with ability to call inner non constant methods? i.e.:
class A {
int value = 12;
void updateValue() {
value = 13;
}
}
class B {
const A a;
this() {
a = new A();
a.updateValue(); // error
On Monday, 29 June 2015 at 20:12:12 UTC, Assembly wrote:
I believe it's a design choice, if so, could someone explain
why? is immutable better than C#'s readonly so that the
readonly keyword isn't even needed? for example, I'd like to
declare a member as readonly but I
I believe it's a design choice, if so, could someone explain why?
is immutable better than C#'s readonly so that the readonly
keyword isn't even needed? for example, I'd like to declare a
member as readonly but I can't do it directly because immutable
create a ne
On Monday, 29 June 2015 at 22:11:16 UTC, sigod wrote:
`new immutable(MyClass)()` is invalid code.
It's perfectly fine, actually.
On Monday, 29 June 2015 at 20:12:12 UTC, Assembly wrote:
I believe it's a design choice, if so, could someone explain
why? is immutable better than C#'s readonly so that the
readonly keyword isn't even needed? for example, I'd like to
declare a member as readonly but I
On Monday, 29 June 2015 at 22:22:46 UTC, anonymous wrote:
On Monday, 29 June 2015 at 22:11:16 UTC, sigod wrote:
`new immutable(MyClass)()` is invalid code.
It's perfectly fine, actually.
Yes, you're right. It seems I've mistyped `immutable` when was
checking it with compiler.
On Tuesday, 28 April 2015 at 19:30:06 UTC, tcak wrote:
Is there any way to define a variable or an attribute as
read-only without defining a getter function/method for it?
Thoughts behind this question are:
1. For every reading, another function call process for CPU
while it could directly rea
uld reduce it to a simple access.
2. You can clean it up if it annoys you with something like this:
mixin template readonly(T, string name)
{
mixin(`private T _`~name~`;T `~name~`()@property{return _`~name~`;}`);
}
Use it like:
class Foo
{
// injects a private int _x, public int x()
mixin readonly!(int, "x");
}
Is there any way to define a variable or an attribute as
read-only without defining a getter function/method for it?
Thoughts behind this question are:
1. For every reading, another function call process for CPU while
it could directly read the value from memory.
2. Repetition of same name fo
On 9/27/14 5:48 AM, "Marc =?UTF-8?B?U2Now7x0eiI=?= "
Yes, that's what I originally intended. Just forgot the const, and
didn't even notice it after I reread it :-P
I wondered... ;)
-Steve
bers would need to have different names:
class Foo {
union {
private int a;
public int b;
}
}
Hm.. that doesn't provide readonly access to either a or b.
But it gave me an idea:
class Foo {
union {
private int _a;
public const
bers would need to have different names:
class Foo {
union {
private int a;
public int b;
}
}
Hm.. that doesn't provide readonly access to either a or b.
But it gave me an idea:
class Foo {
union {
private int _a;
public const
union {
private int a;
public int b;
}
}
Hm.. that doesn't provide readonly access to either a or b.
But it gave me an idea:
class Foo {
union {
private int _a;
public const int a;
}
void setA(int x) { _a = x; }
}
Hot damn! It works to
On Friday, 26 September 2014 at 17:52:58 UTC, bearophile wrote:
Marc Schütz:
Alternatively, you could create a union with a private and a
public member with the same types, but I wouldn't recommend
it. Besides, the members would need to have different names:
class Foo {
union {
Marc Schütz:
Alternatively, you could create a union with a private and a
public member with the same types, but I wouldn't recommend it.
Besides, the members would need to have different names:
class Foo {
union {
private int a;
public int b;
}
()
{
return a;
}
}
This is the C#'s to do which I'm translated to D within my
limited knowledge. I don't do much OOP, maybe it's possible and
I don't know. I'm using @property to make 'a' accessible and
readonly at same time but I wanted to do t
it is
indeed mark the variable public const:
import std.stdio;
class Foo
{
public const int a;
this (int x)
{
a = 2 * x;
}
}
void main()
{
Foo f = new Foo(21);
writeln(f.a); // output value of a
Foo f2 = f; // copy works
f2 = f;// assignment works
// f.a = 10; // compile error: a is readonly outside Foo's methods.
}
Ali
()
{
return a;
}
}
This is the C#'s to do which I'm translated to D within my
limited knowledge. I don't do much OOP, maybe it's possible and
I don't know. I'm using @property to make 'a' accessible and
readonly at same time but I wanted to do t
which I'm translated to D within my
limited knowledge. I don't do much OOP, maybe it's possible and I
don't know. I'm using @property to make 'a' accessible and
readonly at same time but I wanted to do that without this a_
extra variable, i.e, only the method
On Tuesday, 24 December 2013 at 16:11:15 UTC, Ali Çehreli wrote:
On 12/24/2013 04:13 AM, Lemonfiend wrote:
std.file.rmdirRecurse refuses to remove readonly files.
How would I go about deleting them anyway?
Call std.file.setAttributes() first, which has apparently been
added just three days
On 12/24/2013 04:13 AM, Lemonfiend wrote:
std.file.rmdirRecurse refuses to remove readonly files.
How would I go about deleting them anyway?
Call std.file.setAttributes() first, which has apparently been added
just three days ago: :)
https://github.com/D-Programming-Language/phobos/blob
std.file.rmdirRecurse refuses to remove readonly files.
How would I go about deleting them anyway?
On 2013-02-04 14:35, o3o wrote:
So, let me continue the example (I remove "const" for simplicity)...
I would like check that bar.gun() call fun() function from IFoo
unittest {
auto foo = new Mock(); //Will not compile.Mock doesn't (yet)
exist
auto bar = new Bar(foo);
bar.gun()
First, AFAIK, there is no equivalent of C# "readonly" in D,
despite the fact that D uses 3 keywords for various kinds of
immutability.
Second, here you can find a mocking library for D:
http://www.dsource.org/projects/dmocks/wiki/DMocks
On Monday, 4 February 2013 at 13:35:2
On Monday, 4 February 2013 at 10:26:55 UTC, simendsjo wrote:
[cut]
So.. Every method you call through a const instance must also
be const, otherwise you have the ability to change something
that should be a constant.
Thanks simendsjo, now I get it...
So, let me continue the example (I remove
On 2013-02-04 10:02, o3o wrote:
I'm a C# programmer, when I apply IoC pattern I use "readonly" keyword
(http://msdn.microsoft.com/en-us/library/acdd6hb7%28v=vs.71%29.aspx) in
this manner:
:// C# code
:interface IFoo {
: void Fun();
:}
:
:class Foo: IFoo {
: void Fun() {...
On Monday, 4 February 2013 at 10:26:55 UTC, simendsjo wrote:
On Monday, 4 February 2013 at 09:02:31 UTC, o3o wrote:
I'm a C# programmer, when I apply IoC pattern I use
"readonly" keyword
(http://msdn.microsoft.com/en-us/library/acdd6hb7%28v=vs.71%29.aspx)
in this manner
On Monday, 4 February 2013 at 09:02:31 UTC, o3o wrote:
I'm a C# programmer, when I apply IoC pattern I use "readonly"
keyword
(http://msdn.microsoft.com/en-us/library/acdd6hb7%28v=vs.71%29.aspx)
in this manner:
:// C# code
:interface IFoo {
: void Fun();
:}
:
:class Foo: IFo
I'm a C# programmer, when I apply IoC pattern I use "readonly"
keyword
(http://msdn.microsoft.com/en-us/library/acdd6hb7%28v=vs.71%29.aspx)
in this manner:
:// C# code
:interface IFoo {
: void Fun();
:}
:
:class Foo: IFoo {
: void Fun() {...}
:}
:class Bar {
: private re
On 07/12/12 01:09, Jonathan M Davis wrote:
> On Wednesday, July 11, 2012 10:56:23 Artur Skawina wrote:
>> Can anybody think of a reason to keep the current (broken) behavior?
>
> Easily.
You misunderstand the "current (broken) behavior" part - it is about
what 'C*' is, it is not at all about clas
On Wednesday, July 11, 2012 10:56:23 Artur Skawina wrote:
> Can anybody think of a reason to keep the current (broken) behavior?
Easily.
Making Object* point to the object itself rather than the reference would be
so broken that it's not even funny. I can understand why you would think that
suc
On Wednesday, July 11, 2012 23:09:17 Artur Skawina wrote:
> The advantages of having pointers to classes? Eg solving the problem that
> triggered this thread w/o hacks like ClassPtr (Rebindable is an even worse
> hack). [1]
You'd also lose polymorphism, which you don't with Rebindable. In D,
refe
On Wednesday, July 11, 2012 09:51:37 Ali Çehreli wrote:
> On 07/11/2012 08:52 AM, David Nadlinger wrote:
> > I fail to see anything inconsistent here.
>
> Most other operations act on the object:
>
> class B
> {
> // ...
> }
>
> auto b = new B();
>
> ++b; // on the object
> b > b; // on the obj
On Tuesday, 10 July 2012 at 19:27:56 UTC, Namespace wrote:
Maybe D need's a readonly keyword.
[...]
Or has D an alternative?
https://github.com/D-Programming-Language/dmd/pull/3
On 07/11/12 17:54, David Nadlinger wrote:
> On Wednesday, 11 July 2012 at 10:05:40 UTC, Artur Skawina wrote:
>> Because it doesn't let you have a real pointer to a class.
>
> What is a »real pointer«? Class references are really just pointers, in a way
> – you can cast them to void*.
A "real poi
On 07/11/2012 08:52 AM, David Nadlinger wrote:
> I fail to see anything inconsistent here.
Most other operations act on the object:
class B
{
// ...
}
auto b = new B();
++b;// on the object
b > b; // on the object
// etc.
&b; // on the reference
That can be seen as an inconsiste
On Wednesday, 11 July 2012 at 10:05:40 UTC, Artur Skawina wrote:
Because it doesn't let you have a real pointer to a class.
What is a »real pointer«? Class references are really just
pointers, in a way – you can cast them to void*.
The obvious alternative would be:
auto r = new Bar(); /
On Wednesday, 11 July 2012 at 10:00:33 UTC, Tobias Pankrath wrote:
The languages conflates reference and instance type for
classes. See here http://dpaste.dzfl.pl/a55ad2b6 . I wouldn't
say this should change but it is a minor inconsistency I just
stumbled on.
This is not an inconsistency, but
On 07/11/12 11:49, David Nadlinger wrote:
> On Wednesday, 11 July 2012 at 08:56:39 UTC, Artur Skawina wrote:
>> On 07/11/12 09:00, Tobias Pankrath wrote:
>>> Bar b = new Bar;
>>> auto b2 = &b; // type of b2 is Bar*
>>>
>>> So does it meen, that a pointer of type Bar* does not point to the real
>>>
On Wednesday, 11 July 2012 at 09:49:43 UTC, David Nadlinger wrote:
On Wednesday, 11 July 2012 at 08:56:39 UTC, Artur Skawina wrote:
On 07/11/12 09:00, Tobias Pankrath wrote:
Bar b = new Bar;
auto b2 = &b; // type of b2 is Bar*
So does it meen, that a pointer of type Bar* does not point
to the
On Wednesday, 11 July 2012 at 08:56:39 UTC, Artur Skawina wrote:
On 07/11/12 09:00, Tobias Pankrath wrote:
Bar b = new Bar;
auto b2 = &b; // type of b2 is Bar*
So does it meen, that a pointer of type Bar* does not point to
the real object?
Yeah, unfortunately.
Can anybody think of a reason t
On 07/11/12 09:00, Tobias Pankrath wrote:
> On Wednesday, 11 July 2012 at 06:48:59 UTC, David Nadlinger wrote:
>> On Wednesday, 11 July 2012 at 06:34:29 UTC, Tobias Pankrath wrote:
This escapes a stack reference.
>>>
>>> Ins't b supposed to be allocated on the heap?
>>
>> The Bar instance is,
ndamentally
different. And instances of classes are intended to be referred to by
references, _not_ be pointed to by pointers.
Rebindable is the correct solution to this "readonly" issue.
- Jonathan M Davis
On Wednesday, 11 July 2012 at 06:48:59 UTC, David Nadlinger wrote:
On Wednesday, 11 July 2012 at 06:34:29 UTC, Tobias Pankrath
wrote:
This escapes a stack reference.
Ins't b supposed to be allocated on the heap?
The Bar instance is, but the pointer to it is not. Making _b a
Rebindable inste
On Wednesday, 11 July 2012 at 06:34:29 UTC, Tobias Pankrath wrote:
This escapes a stack reference.
Ins't b supposed to be allocated on the heap?
The Bar instance is, but the pointer to it is not. Making _b a
Rebindable instead of using a pointer (to what effectively is a
pointer to the real
On Wednesday, July 11, 2012 08:34:28 Tobias Pankrath wrote:
> > This escapes a stack reference.
>
> Ins't b supposed to be allocated on the heap?
The object is. The reference is not. &b is taking the address of the
reference, not the object.
- Jonathan M Davis
This escapes a stack reference.
Ins't b supposed to be allocated on the heap?
On 07/11/2012 12:58 AM, Ali Çehreli wrote:
On 07/10/2012 03:53 PM, Namespace wrote:
const(T)* ?
Example?
class Bar
{}
class Foo
{
const(Bar) * _b;
void SetBar(const(Bar) * b) {
_b = b;
}
}
void main()
{
auto b = new Bar();
auto f = new Foo();
f.SetBa
class Bar
{}
class Foo
{
const(Bar) * _b;
void SetBar(const(Bar) * b) {
_b = b;
}
}
void main()
{
auto b = new Bar();
auto f = new Foo();
f.SetBar(&b);
}
Ali
Hmm... That's good. Thanks.
On 07/10/2012 03:53 PM, Namespace wrote:
const(T)* ?
Example?
class Bar
{}
class Foo
{
const(Bar) * _b;
void SetBar(const(Bar) * b) {
_b = b;
}
}
void main()
{
auto b = new Bar();
auto f = new Foo();
f.SetBar(&b);
}
Ali
const(T)* ?
Example?
On Tuesday, 10 July 2012 at 19:27:56 UTC, Namespace wrote:
Maybe D need's a readonly keyword.
Sometimes i have a class which can take an object from
everywhere to store it. So it can not be const, because i
didn't just initialized it with a ctor.
But i don't want to change the
On Tue, 10 Jul 2012 21:27:54 +0200, Namespace
wrote:
Maybe D need's a readonly keyword.
Sometimes i have a class which can take an object from everywhere to
store it. So it can not be const, because i didn't just initialized it
with a ctor.
But i don't want to change the
Maybe D need's a readonly keyword.
Sometimes i have a class which can take an object from
everywhere to store it. So it can not be const, because i didn't
just initialized it with a ctor.
But i don't want to change the object, i only want to read or
call const methods. What now?
67 matches
Mail list logo