GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::operator+ - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. string_view
  3. basic_string_view
  4. operator+

最終更新日時: 2026年09月19日 21時31分51秒 (JST)
rotarymars が更新

履歴 編集

function template
<string_view>

std::operator+(C++26)

namespace std {
  template <class charT, class traits, class Allocator>
  constexpr basic_string<charT, traits, Allocator>
    operator+(type_identity_t<basic_string_view<charT, traits>> lhs,
              const basic_string<charT, traits, Allocator>& rhs); // (1) C++26

  template <class charT, class traits, class Allocator>
  constexpr basic_string<charT, traits, Allocator>
    operator+(type_identity_t<basic_string_view<charT, traits>> lhs,
              basic_string<charT, traits, Allocator>&& rhs);      // (2) C++26
}

概要

basic_string_viewオブジェクトとbasic_stringオブジェクトを連結する。

  • (1) : basic_string_viewオブジェクトとbasic_stringオブジェクトを連結する
  • (2) : basic_string_viewオブジェクトと右辺値のbasic_stringオブジェクトを連結する

basic_string_view側の引数にtype_identity_tを使用することで非推論コンテキストとし、basic_string_viewに暗黙変換可能な型からの連結を可能にしている。

戻り値

  • (1) : 以下と等価

    basic_string<charT, traits, Allocator> r = rhs;
    r.insert(0, lhs);
    return r;
    

  • (2) : 以下と等価

    rhs.insert(0, lhs);
    return std::move(rhs);
    

例

#include <iostream>
#include <string>
#include <string_view>

int main()
{
  std::string_view sv = "Hello, ";
  std::string s = "World!";

  // string_view + string (1)
  std::string result1 = sv + s;
  std::cout << result1 << '\n';

  // string_view + string&& (2)
  std::string result2 = sv + std::string("World!");
  std::cout << result2 << '\n';
}

出力

Hello, World!
Hello, World!

バージョン

言語

  • C++26

処理系

  • Clang: 19.1.6 ✅
  • GCC: ??
  • Visual C++: ??

関連項目

名前 説明
basic_string::operator+ 文字列の連結

参照

  • P2591R5 Concatenation of strings and string views
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.