[表示 : 全て 最新50 1-99 101- 201- 301- 401- 501- 601- 701- 2chのread.cgiへ]
Update time : 04/29 14:24 / Filesize : 158 KB / Number-of Response : 773
[このスレッドの書き込みを削除する]
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧] [類似スレッド一覧]


↑キャッシュ検索、類似スレ動作を修正しました、ご迷惑をお掛けしました

【C++】STL(Standard Template Library)相談室 10



1 名前:デフォルトの名無しさん mailto:sage [2008/08/26(火) 12:01:17 ]
C++標準ライブラリの一つ、STLについて。

前スレ
【C++】STL(Standard Template Library)相談室 9
pc11.2ch.net/test/read.cgi/tech/1204045410/

過去ログ・リンク・書籍紹介は >>2 以降

563 名前:デフォルトの名無しさん mailto:sage [2008/11/19(水) 16:28:10 ]
vector<T>(array).swap(array);

564 名前:デフォルトの名無しさん mailto:sage [2008/11/19(水) 16:32:01 ]
reserveは拡大する方向にしか働かないのでは

565 名前:デフォルトの名無しさん mailto:sage [2008/11/19(水) 16:36:13 ]
>>>562
§23.2.4.2.2
void reserve(size_type n);
2 Effects: A directive that informs a vector of a planned change in size, so that it can manage the storage
allocation accordingly. After reserve(), capacity() is greater or equal to the argument of
reserve if reallocation happens; and equal to the previous value of capacity() otherwise. Reallocation
happens at this point if and only if the current capacity is less than the argument of reserve().
3 Complexity: It does not change the size of the sequence and takes at most linear time in the size of the
sequence.

greater or qrual と書いてあるから等しいかもしくは大きいとなるので
ぴったりのsize()になる保証はない。

566 名前:デフォルトの名無しさん mailto:sage [2008/11/19(水) 16:37:52 ]
おっと

equal to the previous value of capacity() otherwise.

ともあるから、縮小しようとしてもcapacity()は変化しない事になる。
詰まるところ>>563のようにスワップ技法に頼るしかない。






[ 続きを読む ] / [ 携帯版 ]

前100 次100 最新50 [ このスレをブックマーク! 携帯に送る ] 2chのread.cgiへ
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧]( ´∀`)<158KB

read.cgi ver5.27 [feat.BBS2 +1.6] / e.0.2 (02/09/03) / eucaly.net products.
担当:undef