teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

追記

2020/02/23 00:00

投稿

hoshi-takanori
hoshi-takanori

スコア7903

answer CHANGED
@@ -1,15 +1,19 @@
1
- C++20 仕様書ドラフト [https://github.com/cplusplus/draft/blob/master/source/classes.tex#L1786](https://github.com/cplusplus/draft/blob/master/source/classes.tex#L1786) に、
1
+ C++20 仕様書ドラフト [https://github.com/cplusplus/draft/blob/master/source/classes.tex#L1783](https://github.com/cplusplus/draft/blob/master/source/classes.tex#L1783) に、
2
2
 
3
+ > A user-declared __copy__ assignment operator `X::operator=` is a
4
+ > non-static **non-template** member function of class `X` with(略)
5
+
3
- > Because a template assignment operator or an assignment operator
6
+ > Because a **template** assignment operator or an assignment operator
4
7
  > taking an rvalue reference parameter is never a copy assignment operator,
5
8
  > the presence of such an assignment operator does not suppress the
6
9
  > implicit declaration of a copy assignment operator.
7
10
 
8
- とありますので、
11
+ とあります(太字は回答者。ちなみに 1998 版にも同様記述があります)ので、
9
12
 
10
13
  ```cpp
11
14
  template <typename U>
12
15
  Foo<T> operator=(const Foo<U> &arg) {
13
16
  ```
14
17
 
15
- は copy assignment operator とは認められず、デフォルトのコピー代入演算子が使われるのでしょう。
18
+ は copy assignment operator とは認められず、デフォルトのコピー代入演算子が使われるのでしょう。
19
+ なお、代入演算子の戻り値は、無駄なコピーを防ぐために参照(Foo<T> &)にした方が良いと思われます。