January 25, 2013 Re: Incorporating D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | In C++ rv-refs do not help with structs (PODs). Do you mean D has no refs / pointers for struct passing?
On Friday, 25 January 2013 at 22:13:25 UTC, Namespace wrote:
> On Friday, 25 January 2013 at 21:50:22 UTC, Timon Gehr wrote:
>> On 01/25/2013 10:39 PM, Namespace wrote:
>>> On Friday, 25 January 2013 at 20:45:22 UTC, Szymon wrote:
>>>> Hi,
>>>>
>>>> I would really like to start using D in our small company as a
>>>> C++ replacement. With that in mind I do have few questions:
>>>>
>>>> 1) Is D2 really ready for production code?
>>>
>>> Not really. A big pain in the ass is the missing rvalue ref that C++
>>> has. So using structs is a big disaster.
>>
>> No. Also, it is not stopping production use at all.
>
> No? Still, that's the fact and it doesn't matter whether you agree or not. You don't use structs as many as I do I think.
> And I'm not saying that it is stopping production at all. I'm saying that D is far away from productive usage and that the missing rvalue ref is a big pain.
|
January 25, 2013 Re: Incorporating D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Szymon | On Friday, 25 January 2013 at 22:16:11 UTC, Szymon wrote:
> In C++ rv-refs do not help with structs (PODs). Do you mean D has no refs / pointers for struct passing?
I meant that we have nothing comparable with const&.
const& int C++ accept both, lvalues and rvalues. If it is an lvalue it is taken by reference and isn't copied.
|
January 25, 2013 Re: Incorporating D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | So structs in D are always passed by-value? That is unfortunate...
On Friday, 25 January 2013 at 22:20:32 UTC, Namespace wrote:
> On Friday, 25 January 2013 at 22:16:11 UTC, Szymon wrote:
>> In C++ rv-refs do not help with structs (PODs). Do you mean D has no refs / pointers for struct passing?
>
> I meant that we have nothing comparable with const&.
> const& int C++ accept both, lvalues and rvalues. If it is an lvalue it is taken by reference and isn't copied.
|
January 25, 2013 Re: Incorporating D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Namespace | And yes, I meant of course D structs and that D has nothing to receive these as rvalue _and_ rvalue. Sorry for confusing you. |
January 25, 2013 Re: Incorporating D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Szymon | On 01/25/2013 11:22 PM, Szymon wrote: > So structs in D are always passed by-value? No. > That is unfortunate... > |
January 25, 2013 Re: Incorporating D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Szymon | On Friday, 25 January 2013 at 22:22:44 UTC, Szymon wrote:
> So structs in D are always passed by-value? That is unfortunate...
>
> On Friday, 25 January 2013 at 22:20:32 UTC, Namespace wrote:
>> On Friday, 25 January 2013 at 22:16:11 UTC, Szymon wrote:
>>> In C++ rv-refs do not help with structs (PODs). Do you mean D has no refs / pointers for struct passing?
>>
>> I meant that we have nothing comparable with const&.
>> const& int C++ accept both, lvalues and rvalues. If it is an lvalue it is taken by reference and isn't copied.
Not if you pass them as ref.
struct A { }
void foo(ref A a) { }
Now foo takes A's by reference. But _only_ lvalues:
A a;
foo(a);
So this is (currently) not possible:
foo(A());
|
January 25, 2013 Re: Incorporating D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Szymon | On Friday, 25 January 2013 at 22:22:44 UTC, Szymon wrote:
> So structs in D are always passed by-value? That is unfortunate...
>
No, that is what he speaks about:
--------
struct SomeStruct
{
int a, b;
}
void f1(ref SomeStruct input) { }
void f2(const ref SomeStruct input) { }
void main()
{
SomeStruct a;
f1(a); // fine
f2(a); // fine
// f1(SomeStruct(0,0)); // invalid, predictable
// f2(SomeStruct(0,0)); // invalid, surprise to C++ guys
}
--------
|
January 25, 2013 Re: Incorporating D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Szymon | On Friday, 25 January 2013 at 22:22:44 UTC, Szymon wrote:
> So structs in D are always passed by-value? That is unfortunate...
It has both pointers and ref but they both only work with lvalues, regardless of const:
struct S {}
void test(const ref S s) {}
void test2(const S* s) {}
S getS() { return S(); }
void main() {
S s;
test(s); // ok
test2(&s); // ok
test(getS()); // not ok (line 12)
test2(&getS()); // not ok (line 13)
}
test.d(12): Error: function test.test (ref const(S) s) is not callable using argument types (S)
test.d(12): Error: getS() is not an lvalue
test.d(13): Error: getS() is not an lvalue
|
January 25, 2013 Re: Incorporating D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | LOL 3 of us said the same thing at the same time! |
January 25, 2013 Re: Incorporating D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | Ah, perfectly clear now. Thanks guys. At one point I though maybe it was about move semantics but it indeed about something much more fundamental. And indeed surprising coming from C++.
On Friday, 25 January 2013 at 22:29:44 UTC, Adam D. Ruppe wrote:
> On Friday, 25 January 2013 at 22:22:44 UTC, Szymon wrote:
>> So structs in D are always passed by-value? That is unfortunate...
>
> It has both pointers and ref but they both only work with lvalues, regardless of const:
>
> struct S {}
>
> void test(const ref S s) {}
> void test2(const S* s) {}
>
> S getS() { return S(); }
>
> void main() {
> S s;
> test(s); // ok
> test2(&s); // ok
> test(getS()); // not ok (line 12)
> test2(&getS()); // not ok (line 13)
> }
>
> test.d(12): Error: function test.test (ref const(S) s) is not callable using argument types (S)
> test.d(12): Error: getS() is not an lvalue
> test.d(13): Error: getS() is not an lvalue
|
Copyright © 1999-2021 by the D Language Foundation