View mode: basic / threaded / horizontal-split · Log in · Help
September 27, 2006
Re: Boost::Any ported to D
Oskar Linde skrev:
> Fredrik Olsson wrote:
>> Oskar Linde skrev:
>>> Fredrik Olsson wrote:
>>>> Perhaps a prefix is in order, in your example:
>> <snip>
>>> There is already a postfix: []
>>>
>>> "test"[] // Dynamic
>>> "test" // Static
>>>
>>
>> Ah, stupid of me. I like it.
>>
>> But where is this documented? I can not find any mention about it 
>> under StringLiterals, and ArrayLiterals under expressions.
> 
> Not very well documented, but:
> 
> http://www.digitalmars.com/d/expression.html
> 
> """
> SliceExpression:
>     PostfixExpression [ ]
>     PostfixExpression [ AssignExpression .. AssignExpression ]
> """
> 
> The first form is the full slice. It seems to be missing from
> 
> http://www.digitalmars.com/d/expression.html#SliceExpression
> 
> though.
> 
Aah, I see. Not as much an intentional postfix, as an useful side-effect 
of slicing. Goot thing(tm), a small amount of highly flexible stuff, is 
way better then tons of specialization.

// Fredrik Olsson

> /Oskar
September 27, 2006
Re: Boost::Any ported to D
Fredrik Olsson wrote:

> Bruno Medeiros skrev:
>>> 2. Arrays with static size are not fully supported e.g. function can not
>>> return static array. Also static arrays are not implicitly converted to
>>> dynamic arrays, so when assigning string to Any class there is a need to
>>> cast to dynamic array:
>>>         (new Any).assign(cast(char[])("char[] test"));
>> 
>> Static arrays are teh suck. :(
>> "Certain aspects of D are a pathway to many issues some consider to
>> be... unnatural." :P
>> 
> Perhaps a prefix is in order, in your example:
> (new Any).assign(d"char[] test"); // Dynamic
> (new Any).assign(s"char[] test"); // Static
> 
> And same for the new array literals (That I love).
> (new Any).assign(d[1,2,3]); // Dynamic
> (new Any).assign(s[1,2,3]); // Static
> 
> I guess no prefix would default to static as is?
> 
> 
> (And before you even think about going about to complain about choosing
> 'd', and 's' as prefixes have in mind: I do not care if any other
> character is used, if it is postfix instead, or whatere. It is the
> functionality I want!)
> 
> 
> // Fredrik Olsson

Unfortunately this functionality doesn't work with my installed compiler
(dmd 0.167 / Linux) :-( I assume it is a bug?

None of your examples work (I get "undefined identifier d" error)
(new Any).assign(d"char[] test"); // Dynamic
(new Any).assign(s"char[] test"); // Static
(new Any).assign(d[1,2,3]); // Dynamic
(new Any).assign(s[1,2,3]); // Static

Does it work on Windows?

-- 
Regards
Marcin Kuszczak
(Aarti_pl)
September 27, 2006
Re: Boost::Any ported to D
Oskar Linde wrote:

> Fredrik Olsson wrote:
>> Perhaps a prefix is in order, in your example:
>> (new Any).assign(d"char[] test"); // Dynamic
>> (new Any).assign(s"char[] test"); // Static
>> 
>> And same for the new array literals (That I love).
>> (new Any).assign(d[1,2,3]); // Dynamic
>> (new Any).assign(s[1,2,3]); // Static
>> 
>> I guess no prefix would default to static as is?
>> 
>> 
>> (And before you even think about going about to complain about choosing
>> 'd', and 's' as prefixes have in mind: I do not care if any other
>> character is used, if it is postfix instead, or whatere. It is the
>> functionality I want!)
> 
> There is already a postfix: []
> 
> "test"[] // Dynamic
> "test" // Static
> 
> /Oskar

Postfix form works well, opposite to prefix form which doesn't...

-- 
Regards
Marcin Kuszczak
(Aarti_pl)
September 27, 2006
Re: Boost::Any ported to D
notknown wrote:

>  wondering if this is still the case with D, but iirc at least
> some time ago I remember that you should use "is" keyword to test if
> object is null because "==" means opEquals.

Probably you are right :-) Thanks for remark.

-- 
Regards
Marcin Kuszczak
(Aarti_pl)
September 28, 2006
Re: Boost::Any ported to D
Marcin Kuszczak skrev:
> Fredrik Olsson wrote:
<snip>
>> // Fredrik Olsson
> 
> Unfortunately this functionality doesn't work with my installed compiler
> (dmd 0.167 / Linux) :-( I assume it is a bug?
> 
> None of your examples work (I get "undefined identifier d" error)
> (new Any).assign(d"char[] test"); // Dynamic
> (new Any).assign(s"char[] test"); // Static
> (new Any).assign(d[1,2,3]); // Dynamic
> (new Any).assign(s[1,2,3]); // Static
> 
> Does it work on Windows?
> 
I seriously doubt it :). This was just a suggestion for how it could be 
done.

Oskar Linde has since then teached me that this would be the correct and 
working way:
(new Any).assign("char[] test"[]); // Dynamic
(new Any).assign("char[] test"); // Static
(new Any).assign([1,2,3][]); // Dynamic
(new Any).assign([1,2,3]); // Static


// Fredrik Olsson
October 02, 2006
Re: Boost::Any ported to D
Marcin Kuszczak wrote:
> Bruno Medeiros wrote:
> 
>> Marcin Kuszczak wrote:
>>> 3. I can not compile program after putting PlaceHolder interface and
>>> Holder class into Any class (like in the original approach). Is it bug or
>>> am I doing something wrong?
>> Hum, C++ allows member(=inner) classes? Didn't know that. Are they
>> static or "instance"(meaning they require an outer class context) classes?
>> Recall that in D they are "instance" by default, and static on option
>> only.
> 
> As I know outer class works just as namespace for inner class. So I would
> say static class definitions.
> 

And when you ported to D, did you make the D inner classes static too?

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
October 02, 2006
Re: Boost::Any ported to D
Bruno Medeiros wrote:

> Marcin Kuszczak wrote:
>> Bruno Medeiros wrote:
>> 
>>> Marcin Kuszczak wrote:
>>>> 3. I can not compile program after putting PlaceHolder interface and
>>>> Holder class into Any class (like in the original approach). Is it bug
>>>> or am I doing something wrong?
>>> Hum, C++ allows member(=inner) classes? Didn't know that. Are they
>>> static or "instance"(meaning they require an outer class context)
>>> classes? Recall that in D they are "instance" by default, and static on
>>> option only.
>> 
>> As I know outer class works just as namespace for inner class. So I would
>> say static class definitions.
>> 
> 
> And when you ported to D, did you make the D inner classes static too?
> 

After some more experiments it occurs that I can move Holder class into Any
class without problems. It could be putted into public or private section.
It doesn't have to have keyword static to work well.

Problems are beginning when I move interface PlaceHolder into private
section of Any. After that I get linking errors:

dmd test_any.d any.d
gcc test_any.o any.o -o test_any -m32 -lphobos -lpthread -lm -Xlinker -ldl
test_any.o: In function
`_D5doost3any3any3Any31__T6assignTC5doost3any3any3AnyZ6assignFC5doost3any3any3AnyZC5doost3any3any3Any':test_any.d
(.gnu.linkonce.t_D5doost3any3any3Any31__T6assignTC5doost3any3any3AnyZ6assignFC5doost3any3any3AnyZC5doost3any3any3Any+0x1b):
undefined reference to
`_D5doost3any3any3Any11PlaceHolder5cloneFZC5doost3any3any3Any11PlaceHolder'
any.o: In function `_D5doost3any3any3Any4typeFZC8TypeInfo':any.d
(.gnu.linkonce.t_D5doost3any3any3Any4typeFZC8TypeInfo+0x1b): undefined
reference to `_D5doost3any3any3Any11PlaceHolder4typeFZC8TypeInfo'
collect2: ld returned 1 exit status
--- errorlevel 1


What is more interesting there is no problem when I put interface into
public section of Any.

In attachment best code which works.

-- 
Regards
Marcin Kuszczak
(Aarti_pl)
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home