partial-ordering

Class template specialization partial ordering and function synthesis

情到浓时终转凉″ 提交于 2019-11-28 17:25:54
The rules for picking which class template specialization is preferred involve rewriting the specializations into function templates and determining which function template is more specialized via the ordering rules for function templates [temp.class.order]. Consider this example, then: #include <iostream> template <class T> struct voider { using type = void; }; template <class T> using void_t = typename voider<T>::type; template <class T, class U> struct A { }; template <class T> int foo(A<T, void_t<T>> ) { return 1; } template <class T> int foo(A<T*, void> ) { return 2; } int main() { std:

partial specialization ordering with non-deduced context

泪湿孤枕 提交于 2019-11-27 22:26:39
According to [temp.class.order] §14.5.5.2, the selection of a partial specialization of t in this example: template< typename > struct s { typedef void v, w; }; template< typename, typename = void > struct t {}; template< typename c > struct t< c, typename c::v > {}; template< typename c > struct t< s< c >, typename s< c >::w > {}; t< s< int > > q; is equivalent to the selection of an overload of f in this example: template< typename > struct s { typedef void v, w; }; template< typename, typename = void > struct t {}; template< typename c > constexpr int f( t< c, typename c::v > ) { return 1;

Why does Rust not implement total ordering via the Ord trait for f64 and f32?

江枫思渺然 提交于 2019-11-27 09:40:09
While all the integer types in Rust implement Ord which emphasizes total ordering, the floating point types only implement PartialOrd . This means that there could be floating point values which cannot be compared. This seems difficult to digest since floating point numbers can be thought of as approximations to real numbers which happen to be a totally ordered set. Even the addition of positive and negative infinity keeps the set of real numbers totally ordered. Why this odd choice in Rust? This restriction means that a generic sort/search algorithm can only assume partial ordering on numbers

Template partial ordering - why does partial deduction succeed here

£可爱£侵袭症+ 提交于 2019-11-26 22:33:33
Consider the following simple (to the extent that template questions ever are) example: #include <iostream> template <typename T> struct identity; template <> struct identity<int> { using type = int; }; template<typename T> void bar(T, T ) { std::cout << "a\n"; } template<typename T> void bar(T, typename identity<T>::type) { std::cout << "b\n"; } int main () { bar(0, 0); } Both clang and gcc print "a" there. According to the rules in [temp.deduct.partial] and [temp.func.order], to determine partial ordering, we need to synthesize some unique types. So we have two attempts at deduction: +---+--

Why does Rust not implement total ordering via the Ord trait for f64 and f32?

丶灬走出姿态 提交于 2019-11-26 22:18:33
问题 While all the integer types in Rust implement Ord which emphasizes total ordering, the floating point types only implement PartialOrd. This means that there could be floating point values which cannot be compared. This seems difficult to digest since floating point numbers can be thought of as approximations to real numbers which happen to be a totally ordered set. Even the addition of positive and negative infinity keeps the set of real numbers totally ordered. Why this odd choice in Rust?

partial specialization ordering with non-deduced context

时光总嘲笑我的痴心妄想 提交于 2019-11-26 20:59:36
问题 According to [temp.class.order] §14.5.5.2, the selection of a partial specialization of t in this example: template< typename > struct s { typedef void v, w; }; template< typename, typename = void > struct t {}; template< typename c > struct t< c, typename c::v > {}; template< typename c > struct t< s< c >, typename s< c >::w > {}; t< s< int > > q; is equivalent to the selection of an overload of f in this example: template< typename > struct s { typedef void v, w; }; template< typename,

Why can't I use the method __cmp__ in Python 3 as for Python 2?

ぃ、小莉子 提交于 2019-11-26 20:20:30
The following piece of code class point: def __init__(self, x, y): self.x = x self.y = y def dispc(self): return ('(' + str(self.x) + ',' + str(self.y) + ')') def __cmp__(self, other): return ((self.x > other.x) and (self.y > other.y)) works fine in Python 2, but in Python 3 I get an error: >>> p=point(2,3) >>> q=point(3,4) >>> p>q Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unorderable types: point() > point() It only works for == and != . Jesse Dhillon You need to provide the rich comparison methods for ordering in Python 3, which are __lt__ , __gt__ , _

Partial ordering with function template having undeduced context

无人久伴 提交于 2019-11-26 19:52:08
问题 While reading another question, i came to a problem with partial ordering, which i cut down to the following test-case template<typename T> struct Const { typedef void type; }; template<typename T> void f(T, typename Const<T>::type*) { cout << "Const"; } // T1 template<typename T> void f(T, void*) { cout << "void*"; } // T2 int main() { // GCC chokes on f(0, 0) (not being able to match against T1) void *p = 0; f(0, p); } For both function templates, the function type of the specialization

What is the partial ordering procedure in template deduction

南楼画角 提交于 2019-11-26 17:28:43
Reading the C++11 standard I can't fully understand the meaning of the following statement. Example are very welcome. Two sets of types are used to determine the partial ordering. For each of the templates involved there is the original function type and the transformed function type. [Note: The creation of the transformed type is described in 14.5.6.2. — end note ] The deduction process uses the transformed type as the argument template and the original type of the other template as the parameter template. This process is done twice for each type involved in the partial ordering comparison:

Why can&#39;t I use the method __cmp__ in Python 3 as for Python 2?

社会主义新天地 提交于 2019-11-26 12:16:11
问题 The following piece of code class point: def __init__(self, x, y): self.x = x self.y = y def dispc(self): return (\'(\' + str(self.x) + \',\' + str(self.y) + \')\') def __cmp__(self, other): return ((self.x > other.x) and (self.y > other.y)) works fine in Python 2, but in Python 3 I get an error: >>> p=point(2,3) >>> q=point(3,4) >>> p>q Traceback (most recent call last): File \"<stdin>\", line 1, in <module> TypeError: unorderable types: point() > point() It only works for == and != . 回答1: