From Jason Turner

[swappable.requirements]

Diff to HTML by rtfpessoa

tmp/tmp20qnguxx/{from.md → to.md} RENAMED
@@ -32,44 +32,48 @@ swappable requirement includes the header `<utility>` to ensure an
32
  appropriate evaluation context. — *end note*]
33
 
34
  An rvalue or lvalue `t` is *swappable* if and only if `t` is swappable
35
  with any rvalue or lvalue, respectively, of type `T`.
36
 
 
 
 
37
  A type `X` meeting any of the iterator requirements
38
  [[iterator.requirements]] meets the *Cpp17ValueSwappable* requirements
39
  if, for any dereferenceable object `x` of type `X`, `*x` is swappable.
40
 
41
  [*Example 1*:
42
 
43
  User code can ensure that the evaluation of `swap` calls is performed in
44
  an appropriate context under the various conditions as follows:
45
 
46
  ``` cpp
 
47
  #include <utility>
48
 
49
- // Requires: std::forward<T>(t) shall be swappable with std::forward<U>(u).
50
  template<class T, class U>
51
  void value_swap(T&& t, U&& u) {
52
  using std::swap;
53
- swap(std::forward<T>(t), std::forward<U>(u)); // OK: uses ``swappable with'' conditions
54
  // for rvalues and lvalues
55
  }
56
 
57
- // Requires: lvalues of T shall be swappable.
58
  template<class T>
59
  void lv_swap(T& t1, T& t2) {
60
  using std::swap;
61
- swap(t1, t2); // OK: uses swappable conditions for lvalues of type T
62
  }
63
 
64
  namespace N {
65
  struct A { int m; };
66
  struct Proxy { A* a; };
67
  Proxy proxy(A& a) { return Proxy{ &a }; }
68
 
69
  void swap(A& x, Proxy p) {
70
- std::swap(x.m, p.a->m); // OK: uses context equivalent to swappable
71
  // conditions for fundamental types
72
  }
73
  void swap(Proxy p, A& x) { swap(x, p); } // satisfy symmetry constraint
74
  }
75
 
 
32
  appropriate evaluation context. — *end note*]
33
 
34
  An rvalue or lvalue `t` is *swappable* if and only if `t` is swappable
35
  with any rvalue or lvalue, respectively, of type `T`.
36
 
37
+ A type `X` meets the *Cpp17Swappable* requirements if lvalues of type
38
+ `X` are swappable.
39
+
40
  A type `X` meeting any of the iterator requirements
41
  [[iterator.requirements]] meets the *Cpp17ValueSwappable* requirements
42
  if, for any dereferenceable object `x` of type `X`, `*x` is swappable.
43
 
44
  [*Example 1*:
45
 
46
  User code can ensure that the evaluation of `swap` calls is performed in
47
  an appropriate context under the various conditions as follows:
48
 
49
  ``` cpp
50
+ #include <cassert>
51
  #include <utility>
52
 
53
+ // Preconditions: std::forward<T>(t) is swappable with std::forward<U>(u).
54
  template<class T, class U>
55
  void value_swap(T&& t, U&& u) {
56
  using std::swap;
57
+ swap(std::forward<T>(t), std::forward<U>(u)); // OK, uses ``swappable with'' conditions
58
  // for rvalues and lvalues
59
  }
60
 
61
+ // Preconditions: T meets the Cpp17Swappable requirements.
62
  template<class T>
63
  void lv_swap(T& t1, T& t2) {
64
  using std::swap;
65
+ swap(t1, t2); // OK, uses swappable conditions for lvalues of type T
66
  }
67
 
68
  namespace N {
69
  struct A { int m; };
70
  struct Proxy { A* a; };
71
  Proxy proxy(A& a) { return Proxy{ &a }; }
72
 
73
  void swap(A& x, Proxy p) {
74
+ std::swap(x.m, p.a->m); // OK, uses context equivalent to swappable
75
  // conditions for fundamental types
76
  }
77
  void swap(Proxy p, A& x) { swap(x, p); } // satisfy symmetry constraint
78
  }
79