On 12/09/2012 10:43 PM, js.mdnq wrote:
> I thought `alias this` essentially treats the object as the alias.
>
> struct A {
> alias value this;
> int value;
> void func();
> }
>
> A a;
>
> then a is essentially the same as a.value?
No. 'alias value this' means "when this object is used in a conte
On Monday, 10 December 2012 at 04:50:17 UTC, Ali Çehreli wrote:
On 12/09/2012 11:52 AM, js.mdnq wrote:
> Well, I would not say they are exactly the same.
Do they have to be exactly the same? You are showing a method
that fails to satisfy a requirement, I show another method
which according to
On 12/09/2012 11:52 AM, js.mdnq wrote:
> Well, I would not say they are exactly the same.
Do they have to be exactly the same? You are showing a method that fails
to satisfy a requirement, I show another method which according to fail
to satisfy another requirement. Software is engineering as
On 12/09/2012 12:02 PM, deed wrote:
> void main()
> {
> auto c = new C;
D is a strongly statically typed language. The type of c is C, period.
The compiler will compile the following lines of code all under that
observation.
> c.setx(5); // Should set x to 5 through i1
> c.getSum(); // Should
On Sunday, 9 December 2012 at 19:54:17 UTC, js.mdnq wrote:
On Sunday, 9 December 2012 at 19:34:05 UTC, anonymous wrote:
On Sunday, 9 December 2012 at 19:24:24 UTC, js.mdnq wrote:
In this particular case you can do this:
mixin template GenStruct(string stringname)
{
struct S
{
}
If you need a small example for code generation, the following code will
generate code for translating any enum value into a string:
string EnumToStringGenerate(T,string templateVar = "T", string pre =
"")(string var){
string res = "final switch(" ~ var ~ "){";
foreach(m;__trai
Thanks for your replies. How about this:
interface I {}
interface I1 : I
{
void setx(int x);
int getx();
int getSum();
}
interface I2 : I
{
void sety(int y);
int gety();
int getSum();
}
class Impl : I1, I2
{
int x, y;
void setx(int x) { this.x = x; }
in
On Sunday, 9 December 2012 at 19:34:05 UTC, anonymous wrote:
On Sunday, 9 December 2012 at 19:24:24 UTC, js.mdnq wrote:
In this particular case you can do this:
mixin template GenStruct(string stringname)
{
struct S
{
}
mixin("alias S " ~ stringname ~ "alpha;");
}
But w
On Sunday, 9 December 2012 at 19:38:28 UTC, Ali Çehreli wrote:
On 12/09/2012 11:23 AM, js.mdnq wrote:
> but b is not private, only the internal representation of it.
e.g.,
> `alias Value_ this` is public. I do realize that it sort of
makes Value_
> and b one and the same but they are not quite t
On 12/09/2012 11:23 AM, js.mdnq wrote:
> but b is not private, only the internal representation of it. e.g.,
> `alias Value_ this` is public. I do realize that it sort of makes Value_
> and b one and the same but they are not quite the same.
>
> To me, it breaks encapsulation. writeln(c.b) is acc
On Sunday, 9 December 2012 at 19:24:24 UTC, js.mdnq wrote:
In this particular case you can do this:
mixin template GenStruct(string stringname)
{
struct S
{
}
mixin("alias S " ~ stringname ~ "alpha;");
}
But what if I use more than one mixin? I'll have multiple
str
On Sunday, 9 December 2012 at 19:09:49 UTC, anonymous wrote:
On Sunday, 9 December 2012 at 10:42:40 UTC, js.mdnq wrote:
How can I create mixes of stringified code and code itself?
[...]
mixin template GenStruct(stringname)
{
struct stringname ~ "alpha"
{
}
}
mixin Ge
On Sunday, 9 December 2012 at 16:50:55 UTC, Ali Çehreli wrote:
On 12/09/2012 01:42 AM, js.mdnq wrote:
> Actually, it doesn't seem to work ;/ Your code worked but
mine does
> unless I make it public. It is a public/private issue and I
get a ton of
> errors:
This is not adding to the discussion m
On Sunday, 9 December 2012 at 10:42:40 UTC, js.mdnq wrote:
How can I create mixes of stringified code and code itself?
[...]
mixin template GenStruct(stringname)
{
struct stringname ~ "alpha"
{
}
}
mixin GenStruct!("Helpme");
would be equivalent to do the followi
On Sunday, 9 December 2012 at 11:25:25 UTC, Philippe Sigaud wrote:
You can use a templated string-returning function and mix it in:
string codeGenerator(compileTimeArguments, Other...)(Other
others)
{
string result = ...
(...) // build your code here
return result;
}
(...)
cla
On Sunday, 9 December 2012 at 18:23:15 UTC, deed wrote:
- Is it possible to enforce, from within the class, a certain
static interface type or ancestor type when instantiating with
new? If so, how is it done?
No, but you could make the constructor private so new doesn't
work on it at all, and
On 12/09/2012 10:23 AM, deed wrote:
> interface I
> {
> void setX(int x);
> int getX();
> }
>
> class C : I
> {
> int x, y;
>
> void setX(int x) { this.x = x; }
> int getX() { return x; }
> void setY(int y) { this.y = y }
> int getY() { return y; }
> }
>
>
> void main()
> {
> auto obj = new C; //
interface I
{
void setX(int x);
int getX();
}
class C : I
{
int x, y;
void setX(int x) { this.x = x; }
int getX() { return x; }
void setY(int y) { this.y = y }
int getY() { return y; }
}
void main()
{
auto obj = new C; // Want new C to instantia
On 12/09/2012 01:42 AM, js.mdnq wrote:
> Actually, it doesn't seem to work ;/ Your code worked but mine does
> unless I make it public. It is a public/private issue and I get a ton of
> errors:
This is not adding to the discussion much but it is again because the
member is private. writeln() is
On Sunday, 9 December 2012 at 10:42:40 UTC, js.mdnq wrote:
How can I create mixes of stringified code and code itself?
http://dlang.org/mixin.html
explains how to create structs using strings. But what if I do
not want to have to encode the whole struct as a string but
only parts of it?
mi
Actually, it doesn't seem to work ;/ Your code worked but mine
does unless I make it public. It is a public/private issue and I
get a ton of errors:
module main;
import std.stdio;
class A
{
public:
string Name;
struct B(T)
{
On Sunday, 9 December 2012 at 09:06:28 UTC, Maxim Fomin wrote:
On Sunday, 9 December 2012 at 06:54:33 UTC, js.mdnq wrote:
Why can't a struct inside a class access the members of that
class without a this pointer? It would seem natural to me that
a nested struct should probably be special in tha
On Sunday, 9 December 2012 at 08:56:00 UTC, Maxim Fomin wrote:
On Sunday, 9 December 2012 at 07:39:29 UTC, js.mdnq wrote:
On Sunday, 9 December 2012 at 07:24:57 UTC, Jonathan M Davis
wrote:
On Sunday, December 09, 2012 07:54:25 js.mdnq wrote:
Why can't a struct inside a class access the member
On Sunday, 9 December 2012 at 06:54:33 UTC, js.mdnq wrote:
Why can't a struct inside a class access the members of that
class without a this pointer? It would seem natural to me that
a nested struct should probably be special in that it is really
just a special container to reduce clutter in th
On Sunday, 9 December 2012 at 07:39:29 UTC, js.mdnq wrote:
On Sunday, 9 December 2012 at 07:24:57 UTC, Jonathan M Davis
wrote:
On Sunday, December 09, 2012 07:54:25 js.mdnq wrote:
Why can't a struct inside a class access the members of that
class without a this pointer? It would seem natural to
On Sunday, 9 December 2012 at 08:27:45 UTC, Ali Çehreli wrote:
On 12/08/2012 11:05 PM, js.mdnq wrote:
> Can it not be possible to use alias this on a private field?
I've just tested it. It is possible with dmd 2.060:
struct Q
{
private:
int _x;
public:
alias _x this;
}
void main()
{
On 12/08/2012 11:05 PM, js.mdnq wrote:
> Can it not be possible to use alias this on a private field?
I've just tested it. It is possible with dmd 2.060:
struct Q
{
private:
int _x;
public:
alias _x this;
}
void main()
{
auto q = Q();
q = 42;
assert(q._x == 42);
}
> struct
27 matches
Mail list logo