File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ string_view hello = sv.substr(0, 5); // 先頭5文字を抽出する
8989
9090| 名前 | 説明 | 対応バージョン |
9191| ------| ------| ----------------|
92- | [ ` copy ` ] ( basic_string_view/copy.md.nolink ) | 他の文字列にコピーする | C++17 |
92+ | [ ` copy ` ] ( basic_string_view/copy.md ) | 他の文字列に、自身の文字列をコピーする | C++17 |
9393| [ ` substr ` ] ( basic_string_view/substr.md ) | 部分文字列を取得する | C++17 |
9494| [ ` compare ` ] ( basic_string_view/compare.md ) | 他の文字列との比較を行う | C++17 |
9595| [ ` find ` ] ( basic_string_view/find.md.nolink ) | 指定文字列を検索する | C++17 |
Original file line number Diff line number Diff line change 1+ # copy
2+ * string_view[ meta header]
3+ * std[ meta namespace]
4+ * basic_string_view[ meta class]
5+ * function[ meta id-type]
6+ * cpp17[ meta cpp]
7+
8+ ``` cpp
9+ size_type copy (CharT* s, size_type n, size_type pos = 0) const;
10+ ```
11+
12+ ## 概要
13+ 他の文字列に、自身の文字列をコピーする。
14+
15+
16+ ## 要件
17+ `n`と[`size()`](size.md) `- pos`のうち、小さい方を`rlen`とする。
18+
19+ - `[s, s + rlen)`が妥当な範囲であり、その範囲内の要素にアクセスできること
20+
21+
22+ ## 効果
23+ 以下と同等の処理を行う:
24+
25+ ```cpp
26+ Traits::copy(s, data() + pos, rlen);
27+ ```
28+ * copy[ link /reference/string/char_traits/copy.md]
29+ * data()[ link data.md]
30+
31+
32+ ## 戻り値
33+ ` rlen `
34+
35+
36+ ## 例外
37+ ` pos > ` [ ` size() ` ] ( size.md ) の場合、[ ` std::out_of_range ` ] ( /reference/stdexcept.md ) 例外を送出する。
38+
39+
40+ ## 例
41+ ``` cpp example
42+ #include < iostream>
43+ #include < string_view>
44+
45+ int main ()
46+ {
47+ const std::string_view sv = "hello";
48+
49+ // 全体をコピーする
50+ {
51+ char result[ 5 + 1] = {};
52+ sv.copy(result, 5);
53+
54+ std::cout << result << std::endl;
55+ }
56+
57+ // 先頭3要素だけコピーする
58+ {
59+ char result[ 3 + 1] = {};
60+ sv.copy(result, 3);
61+
62+ std::cout << result << std::endl;
63+ }
64+
65+ // 2番目以降の要素をコピーする
66+ {
67+ char result[ 3 + 1] = {};
68+ sv.copy(result, 3, 2);
69+
70+ std::cout << result << std::endl;
71+ }
72+ }
73+ ```
74+ * copy[ color ff0000]
75+
76+ ### 出力
77+ ```
78+ hello
79+ hel
80+ llo
81+ ```
82+
83+
84+ ## バージョン
85+ ### 言語
86+ - C++17
87+
88+ ### 処理系
89+ - [ Clang, C++17 mode] ( /implementation.md#clang ) : 4.0
90+ - [ GCC, C++17 mode] ( /implementation.md#gcc ) : 7.1
91+ - [ ICC] ( /implementation.md#icc ) : ??
92+ - [ Visual C++] ( /implementation.md#visual_cpp ) : ??
You can’t perform that action at this time.
0 commit comments