std::operator+(std::basic_string)
ヘッダ <string> で定義
|
||
(1) | ||
template< class CharT, class Traits, class Alloc > std::basic_string<CharT,Traits,Alloc> |
(C++20未満) | |
template< class CharT, class Traits, class Alloc > constexpr std::basic_string<CharT,Traits,Alloc> |
(C++20以上) | |
(2) | ||
template< class CharT, class Traits, class Alloc > std::basic_string<CharT,Traits,Alloc> |
(C++20未満) | |
template< class CharT, class Traits, class Alloc > constexpr std::basic_string<CharT,Traits,Alloc> |
(C++20以上) | |
(3) | ||
template<class CharT, class Traits, class Alloc> std::basic_string<CharT,Traits,Alloc> |
(C++20未満) | |
template<class CharT, class Traits, class Alloc> constexpr std::basic_string<CharT,Traits,Alloc> |
(C++20以上) | |
(4) | ||
template< class CharT, class Traits, class Alloc > std::basic_string<CharT,Traits,Alloc> |
(C++20未満) | |
template< class CharT, class Traits, class Alloc > constexpr std::basic_string<CharT,Traits,Alloc> |
(C++20以上) | |
(5) | ||
template< class CharT, class Traits, class Alloc > std::basic_string<CharT,Traits,Alloc> |
(C++20未満) | |
constexpr std::basic_string<CharT,Traits,Alloc> operator+( CharT lhs, |
(C++20以上) | |
(6) | ||
template< class CharT, class Traits, class Alloc > std::basic_string<CharT,Traits,Alloc> |
(C++11以上) (C++20未満) |
|
template< class CharT, class Traits, class Alloc > constexpr std::basic_string<CharT,Traits,Alloc> |
(C++20以上) | |
(7) | ||
template< class CharT, class Traits, class Alloc > std::basic_string<CharT,Traits,Alloc> |
(C++11以上) (C++20未満) |
|
template< class CharT, class Traits, class Alloc > constexpr std::basic_string<CharT,Traits,Alloc> |
(C++20以上) | |
(8) | ||
template< class CharT, class Traits, class Alloc > std::basic_string<CharT,Traits,Alloc> |
(C++11以上) (C++20未満) |
|
template< class CharT, class Traits, class Alloc > constexpr std::basic_string<CharT,Traits,Alloc> |
(C++20以上) | |
(9) | ||
template< class CharT, class Traits, class Alloc > std::basic_string<CharT,Traits,Alloc> |
(C++11以上) (C++20未満) |
|
template< class CharT, class Traits, class Alloc > constexpr std::basic_string<CharT,Traits,Alloc> |
(C++20以上) | |
(10) | ||
template< class CharT, class Traits, class Alloc > std::basic_string<CharT,Traits,Alloc> |
(C++11以上) (C++20未満) |
|
template< class CharT, class Traits, class Alloc > constexpr std::basic_string<CharT,Traits,Alloc> |
(C++20以上) | |
(11) | ||
template< class CharT, class Traits, class Alloc > std::basic_string<CharT,Traits,Alloc> |
(C++11以上) (C++20未満) |
|
template< class CharT, class Traits, class Alloc > constexpr std::basic_string<CharT,Traits,Alloc> |
(C++20以上) | |
(12) | ||
template< class CharT, class Traits, class Alloc > std::basic_string<CharT,Traits,Alloc> |
(C++11以上) (C++20未満) |
|
template< class CharT, class Traits, class Alloc > constexpr std::basic_string<CharT,Traits,Alloc> |
(C++20以上) | |
lhs
の文字列の後に rhs
の文字列が続いた内容を持つ文字列を返します。
結果に対して使用されるアロケ��タは以下の通りです。 1-3) std::allocator_traits<Alloc>::select_on_container_copy_construction(lhs.get_allocator())
4-5) std::allocator_traits<Alloc>::select_on_container_copy_construction(rhs.get_allocator())
6-9) lhs.get_allocator()
10-12) rhs.get_allocator()
別の言い方をすると、一方の被演算子が (6-12) の場合、すべての右辺値の |
(C++11以上) |
目次 |
[編集] 引数
lhs | - | 文字列、文字、またはヌル終端配列の最初の文字を指すポインタ |
rhs | - | 文字列、文字、またはヌル終端配列の最初の文字を指すポインタ |
[編集] 戻り値
上で述べたように決定されたアロケータを使用した、 (C++11以上) lhs
の文字列の後に rhs
の文字列が続いた内容を持つ文字列。
ノート
using my_string = std::basic_string<char, std::char_traits<char>, my_allocator<char>>; my_string cat(); const my_string& dog(); my_string meow = /* ... */, woof = /* ... */; meow + cat() + /*...*/; // meow のアロケータに対する SOCCC を使用します。 woof + dog() + /*...*/; // dog() の戻り値のアロケータを使用します。 meow + woof + meow; // meow のアロケータに対する SOCCC を使用します。 meow + (woof + meow); // woof のアロケータに対する SOCCC を使用します。 // 注: SOCCC = select_on_container_copy_construction
// 最終結果に対して my_favorite_allocator を使用します。 my_string(my_favorite_allocator) + meow + woof + cat() + dog(); アロケータの良好かつ移植性のある制御のためには、所望のアロケータを用いて構築した結果文字列に対して |
(C++11以上) |
[編集] 例
#include <iostream> #include <string> int main() { std::string s1 = "Hello"; std::string s2 = "world"; std::cout << s1 + ' ' + s2 + "!\n"; }
出力:
Hello world!
[編集] 欠陥報告
以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。
DR | 適用先 | 発行時の動作 | 正しい動作 |
---|---|---|---|
P1165R1 | C++11 | allocator propagation is haphazard and inconsistent | made more consistent |
[編集] 関連項目
文字を末尾に追加します (パブリックメンバ関数) | |
文字を末尾に追加します (パブリックメンバ関数) | |
文字を挿入します (パブリックメンバ関数) |