C++'s "defaulted comparison operators" proposal
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 17 22:49:30 PDT 2014
Can you come up with a D library solution to the following C++11 proposal:
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3950.html
The idea is to be able to have standard comparison behavior for structs
without boilerplate. For example, if the ordering should consider all
members of the following struct one after the other (first 'i', then
'l', and finally 's'):
struct S
{
int i;
long l;
string s;
mixin DefaultComparisons!(); // something like this?
}
Or perhaps with an explicit comparison order? For example, to use 'l' as
the primary key instead, and 'i' as the secondary key, and to ignore
'buffer' altogether:
struct S
{
@Order(2) int i;
@Order(1) long l;
@OrderIgnore string buffer;
mixin DefaultComparisons!(); // ?
}
Thank you,
Ali
More information about the Digitalmars-d-learn
mailing list