From 75cf20cace3a5993dc62716ca1dd75357e8196e9 Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Sat, 18 Apr 2009 09:06:31 +0000 Subject: [PATCH] primary operand type must be class type, see ticket #2938 [SVN r52463] --- operators.htm | 55 +++++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/operators.htm b/operators.htm index a33e814..37820e1 100644 --- a/operators.htm +++ b/operators.htm @@ -132,18 +132,18 @@ class MyInt : boost::operators<MyInt> { - bool operator<(const MyInt& x) const; + bool operator<(const MyInt& x) const; bool operator==(const MyInt& x) const; - MyInt& operator+=(const MyInt& x); - MyInt& operator-=(const MyInt& x); - MyInt& operator*=(const MyInt& x); - MyInt& operator/=(const MyInt& x); - MyInt& operator%=(const MyInt& x); - MyInt& operator|=(const MyInt& x); - MyInt& operator&=(const MyInt& x); - MyInt& operator^=(const MyInt& x); - MyInt& operator++(); - MyInt& operator--(); + MyInt& operator+=(const MyInt& x); + MyInt& operator-=(const MyInt& x); + MyInt& operator*=(const MyInt& x); + MyInt& operator/=(const MyInt& x); + MyInt& operator%=(const MyInt& x); + MyInt& operator|=(const MyInt& x); + MyInt& operator&=(const MyInt& x); + MyInt& operator^=(const MyInt& x); + MyInt& operator++(); + MyInt& operator--(); }; @@ -345,7 +345,7 @@ class MyInt

As Daniel Krügler pointed out, this technique violates 14.6.5/2 - and is thus non-portable. The reasoning is, that the operators injected + and is thus non-portable. The reasoning is, that the operators injected by the instantiation of e.g. less_than_comparable<myclass> can not be found by ADL according to the rules given by 3.4.2/2, since myclass is @@ -445,6 +445,9 @@ const point<float> pi_over_4_normalized = pi_over_4 / length(pi_over_4); optional template parameter B, which is not shown, for the base class chaining technique.

+

The primary operand type T needs to be of class type, + built-in types are not supported.

+
Simple Arithmetic Operator Template Classes @@ -917,7 +920,7 @@ T operator+( const T& lhs, const T& rhs ) created, operator+= is called on it and it is copied to the function return value (which is another unnamed object of type T). The standard doesn't generally allow the intermediate - object to be optimized away: + object to be optimized away:
3.7.2/2: Automatic storage duration
@@ -928,7 +931,7 @@ T operator+( const T& lhs, const T& rhs ) unused, except that a class object or its copy may be eliminated as specified in 12.8.
- The reference to 12.8 is important for us: + The reference to 12.8 is important for us:
12.8/15: Copying class objects
@@ -942,7 +945,7 @@ T operator+( const T& lhs, const T& rhs )
This optimization is known as the named return value optimization (NRVO), which leads us to the following implementation for - operator+: + operator+:
 T operator+( const T& lhs, const T& rhs )
 {
@@ -956,7 +959,7 @@ T operator+( const T& lhs, const T& rhs )
     even implement it in an incorrect way which makes it useless here.
     Without the NRVO, the NRVO-friendly code is no worse than the original
     code showed above, but there is another possible implementation, which
-    has some very special properties: 
+    has some very special properties:
 
 T operator+( T lhs, const T& rhs )
 {
@@ -982,7 +985,7 @@ T operator+( T lhs, const T& rhs )
     will force the NRVO-friendly implementation to be used even for compilers
     that don't implement the NRVO. 

- +

Grouped Arithmetic Operators

The following templates provide common groups of related operations. @@ -1864,7 +1867,7 @@ T operator+( T lhs, const T& rhs ) V, D, P, R>

- Supports the operations and has the requirements of + Supports the operations and has the requirements of - Supports the operations and has the requirements of + Supports the operations and has the requirements of
- Supports the operations and has the requirements of + Supports the operations and has the requirements of - Supports the operations and has the requirements of + Supports the operations and has the requirements of
- Supports the operations and has the requirements of + Supports the operations and has the requirements of