Discussion:
Comparison categories: strong equivalence and partial ordering.
(too old to reply)
Olivier Kannengieser
2018-09-17 10:36:16 UTC
Permalink
Comparison categories are based on qualities of object of a given types:
1. order-ability: The type is comparable (using < > <= >=)
2. substitutability: for all a,b of the given type, for all function f:
(a==b) implies (f(a)==f(b))
3. strong order-ability (sorry): for all a,b of the given type: (a<b)
implies (!(a>=b)), (a!=b) implies (a<b) || (a>b), ...

For types that are not orderable only substitutability make sense, so there
are two categories:
1: strong_equality if the types ensure substitutability;
2: weak_equality if the types does not ensure substitutability.

For comparable type, two qualities applies substitutability and strong
order-ability. So their should be 4 comparison categories, but only 3
exists:
1: strong_ordering: if the type ensures substitutability and strong
order-ability
2: weak_ordering: if the type does not ensure substitutability but
ensures strong order-ability
3: partial_ordering: if the type does not ensure susbstitutability and
does not ensure strong order-ability
4: xxxxxxxxxxxxx?: if the type does ensure substitutability but ensure
strong order-ability.

Such categories would apply very well to types representing the location of
a point in a space which has more than one dimension.

Let's consider this example:
// represent a memory allocation suitable for a given type:
struct memory_dimension{
size_t size;
size_t alignment;
};

For this kind of type, it seems intuitive to define a comparison that would
indicate if an object of type T can be reliably constructed in a memory
which where allocated with size, and alignment:
`new(size,align_val_t{alignment})`:
T* build_t(void* location, memory_dimension m){
if (memory_of<T>()> m)
retun build<T>(p);
return nullptr;
}
In this case one would define operators < and > as follow:
bool operator <(memory_dimension a, memory_dimension b){
return a.size < b.size && a.alignment < b.alignment;
}
bool operator >(memory_dimension a, memory_dimension b){
return a.size > b.size && a.alignment > b.alignment;
}

So memory_dimension would not be strong-order-able, but it would ensures
substitutability.

Why the standard does not define comparison category of types that provides
substitutability but not strong order-ability?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Olivier Kannengieser
2018-09-17 10:48:41 UTC
Permalink
Correction:
4: xxxxxxxxxxxxx?: if the type does ensure substitutability but does not
ensure strong order-ability.
Post by Olivier Kannengieser
1. order-ability: The type is comparable (using < > <= >=)
(a==b) implies (f(a)==f(b))
3. strong order-ability (sorry): for all a,b of the given type: (a<b)
implies (!(a>=b)), (a!=b) implies (a<b) || (a>b), ...
For types that are not orderable only substitutability make sense, so
1: strong_equality if the types ensure substitutability;
2: weak_equality if the types does not ensure substitutability.
For comparable type, two qualities applies substitutability and strong
order-ability. So their should be 4 comparison categories, but only 3
1: strong_ordering: if the type ensures substitutability and strong
order-ability
2: weak_ordering: if the type does not ensure substitutability but
ensures strong order-ability
3: partial_ordering: if the type does not ensure susbstitutability and
does not ensure strong order-ability
4: xxxxxxxxxxxxx?: if the type does ensure substitutability but ensure
strong order-ability.
Such categories would apply very well to types representing the location
of a point in a space which has more than one dimension.
struct memory_dimension{
size_t size;
size_t alignment;
};
For this kind of type, it seems intuitive to define a comparison that would
indicate if an object of type T can be reliably constructed in a memory
T* build_t(void* location, memory_dimension m){
if (memory_of<T>()> m)
retun build<T>(p);
return nullptr;
}
bool operator <(memory_dimension a, memory_dimension b){
return a.size < b.size && a.alignment < b.alignment;
}
bool operator >(memory_dimension a, memory_dimension b){
return a.size > b.size && a.alignment > b.alignment;
}
So memory_dimension would not be strong-order-able, but it would ensures
substitutability.
Why the standard does not define comparison category of types that
provides substitutability but not strong order-ability?
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Continue reading on narkive:
Loading...