Namespaces
Variants

Standard library header <string_view> (C++17)

From cppreference.net
Standard library headers

이 헤더는 strings 라이브러리의 일부입니다.

목차

포함 파일

(C++20)
3-way 비교 연산자 지원

클래스

읽기 전용 문자열 뷰
(클래스 템플릿)
std::string_view (C++17) std:: basic_string_view < char >
std::u8string_view (C++20) std:: basic_string_view < char8_t >
std::u16string_view (C++17) std:: basic_string_view < char16_t >
std::u32string_view (C++17) std:: basic_string_view < char32_t >
std::wstring_view (C++17) std:: basic_string_view < wchar_t >
문자열 뷰에 대한 해시 지원
(클래스 템플릿 특수화)
전방 선언
헤더 파일에 정의됨 <functional>
(C++11)
해시 함수 객체
(클래스 템플릿)

함수

(C++17) (C++20에서 제거됨) (C++20에서 제거됨) (C++20에서 제거됨) (C++20에서 제거됨) (C++20에서 제거됨) (C++20)
두 string view를 사전식으로 비교
(함수 템플릿)
(C++17)
string view에 대한 스트림 출력 수행
(함수 템플릿)
두 객체의 값을 교환합니다
(함수 템플릿)
범위 접근
(C++11) (C++14)
컨테이너나 배열의 시작 부분에 대한 반복자를 반환합니다
(함수 템플릿)
(C++11) (C++14)
컨테이너나 배열의 끝을 가리키는 반복자를 반환합니다
(함수 템플릿)
컨테이너나 배열의 시작 부분에 대한 역방향 반복자를 반환합니다
(함수 템플릿)
(C++14)
컨테이너나 배열에 대한 역방향 끝 반복자를 반환합니다
(함수 템플릿)
(C++17) (C++20)
컨테이너나 배열의 크기를 반환합니다
(함수 템플릿)
(C++17)
컨테이너가 비어 있는지 확인합니다
(함수 템플릿)
(C++17)
기본 배열에 대한 포인터를 획득함
(함수 템플릿)
리터럴
인라인 네임스페이스에 정의됨 std::literals::string_view_literals
문자 배열 리터럴의 string view를 생성합니다
(함수)

시놉시스

#include <compare>
namespace std {
  // 클래스 템플릿 basic_string_view
  template<class CharT, class Traits = char_traits<CharT>>
  class basic_string_view;
  template<class CharT, class Traits>
    inline constexpr bool ranges::enable_view<basic_string_view<CharT, Traits>> = true;
  template<class CharT, class Traits>
    inline constexpr bool ranges::enable_borrowed_range<basic_string_view<CharT, Traits>> =
      true;
  // 비멤버 비교 함수들
  template<class CharT, class Traits>
    constexpr bool operator==(basic_string_view<CharT, Traits> x,
                              basic_string_view<CharT, Traits> y) noexcept;
  template<class CharT, class Traits>
    constexpr /* 설명 참조 */
      operator<=>(basic_string_view<CharT, Traits> x,
                  basic_string_view<CharT, Traits> y) noexcept;
  // 충분한 추가 비교 함수 오버로드들
  // 삽입자와 추출자
  template<class CharT, class Traits>
    basic_ostream<CharT, Traits>&
      operator<<(basic_ostream<CharT, Traits>& os,
                 basic_string_view<CharT, Traits> str);
  // basic_string_view typedef 이름들
  using string_view    = basic_string_view<char>;
  using u8string_view  = basic_string_view<char8_t>;
  using u16string_view = basic_string_view<char16_t>;
  using u32string_view = basic_string_view<char32_t>;
  using wstring_view   = basic_string_view<wchar_t>;
  // 해시 지원
  template<class T> struct hash;
  template<> struct hash<string_view>;
  template<> struct hash<u8string_view>;
  template<> struct hash<u16string_view>;
  template<> struct hash<u32string_view>;
  template<> struct hash<wstring_view>;
  inline namespace literals {
  inline namespace string_view_literals {
    // basic_string_view 리터럴 접미사
    constexpr string_view    operator""sv(const char* str, size_t len) noexcept;
    constexpr u8string_view  operator""sv(const char8_t* str, size_t len) noexcept;
    constexpr u16string_view operator""sv(const char16_t* str, size_t len) noexcept;
    constexpr u32string_view operator""sv(const char32_t* str, size_t len) noexcept;
    constexpr wstring_view   operator""sv(const wchar_t* str, size_t len) noexcept;
  }
  }
}

클래스 템플릿 std::basic_string_view

namespace std {
  template<class CharT, class Traits = char_traits<CharT>>
  class basic_string_view {
  public:
    // 타입
    using Traits_type            = Traits;
    using value_type             = CharT;
    using pointer                = value_type*;
    using const_pointer          = const value_type*;
    using reference              = value_type&;
    using const_reference        = const value_type&;
    using const_iterator         = /* 구현 정의 */
    using iterator               = const_iterator;
    using const_reverse_iterator = reverse_iterator<const_iterator>;
    using reverse_iterator       = const_reverse_iterator;
    using size_type              = size_t;
    using difference_type        = ptrdiff_t;
    static constexpr size_type npos = size_type(-1);
    // construction and assignment
    constexpr basic_string_view() noexcept;
    constexpr basic_string_view(const basic_string_view&) noexcept = default;
    constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default;
    constexpr basic_string_view(const CharT* str);
    constexpr basic_string_view(nullptr_t) = delete;
    constexpr basic_string_view(const CharT* str, size_type len);
    template<class It, class End>
      constexpr basic_string_view(It begin, End end);
    template<class R>
      constexpr explicit basic_string_view(R&& r);
    // iterator support
    constexpr const_iterator begin() const noexcept;
    constexpr const_iterator end() const noexcept;
    constexpr const_iterator cbegin() const noexcept;
    constexpr const_iterator cend() const noexcept;
    constexpr const_reverse_iterator rbegin() const noexcept;
    constexpr const_reverse_iterator rend() const noexcept;
    constexpr const_reverse_iterator crbegin() const noexcept;
    constexpr const_reverse_iterator crend() const noexcept;
    // capacity
    constexpr size_type size() const noexcept;
    constexpr size_type length() const noexcept;
    constexpr size_type max_size() const noexcept;
    constexpr bool empty() const noexcept;
    // 요소 접근
    constexpr const_reference operator[](size_type pos) const;
    constexpr const_reference at(size_type pos) const;
    constexpr const_reference front() const;
    constexpr const_reference back() const;
    constexpr const_pointer data() const noexcept;
    // modifiers
    constexpr void remove_prefix(size_type n);
    constexpr void remove_suffix(size_type n);
    constexpr void swap(basic_string_view& s) noexcept;
    // 문자열 연산
    constexpr size_type copy(CharT* s, size_type n, size_type pos = 0) const;
    constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
    constexpr int compare(basic_string_view s) const noexcept;
    constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
    constexpr int compare(size_type pos1, size_type n1, basic_string_view s,
                          size_type pos2, size_type n2) const;
    constexpr int compare(const CharT* s) const;
    constexpr int compare(size_type pos1, size_type n1, const CharT* s) const;
    constexpr int compare(size_type pos1, size_type n1, const CharT* s,
                          size_type n2) const;
    constexpr bool starts_with(basic_string_view x) const noexcept;
    constexpr bool starts_with(CharT x) const noexcept;
    constexpr bool starts_with(const CharT* x) const;
    constexpr bool ends_with(basic_string_view x) const noexcept;
    constexpr bool ends_with(CharT x) const noexcept;
    constexpr bool ends_with(const CharT* x) const;
    constexpr bool contains(basic_string_view x) const noexcept;
    constexpr bool contains(CharT x) const noexcept;
    constexpr bool contains(const CharT* x) const;
    // 검색 중
    constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
    constexpr size_type find(CharT c, size_type pos = 0) const noexcept;
    constexpr size_type find(const CharT* s, size_type pos, size_type n) const;
    constexpr size_type find(const CharT* s, size_type pos = 0) const;
    constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
    constexpr size_type rfind(CharT c, size_type pos = npos) const noexcept;
    constexpr size_type rfind(const CharT* s, size_type pos, size_type n) const;
    constexpr size_type rfind(const CharT* s, size_type pos = npos) const;
    constexpr size_type find_first_of(basic_string_view s,
                                      size_type pos = 0) const noexcept;
    constexpr size_type find_first_of(CharT c, size_type pos = 0) const noexcept;
    constexpr size_type find_first_of(const CharT* s, size_type pos, size_type n) const;
    constexpr size_type find_first_of(const CharT* s, size_type pos = 0) const;
    constexpr size_type find_last_of(basic_string_view s,
                                     size_type pos = npos) const noexcept;
    constexpr size_type find_last_of(CharT c, size_type pos = npos) const noexcept;
    constexpr size_type find_last_of(const CharT* s, size_type pos, size_type n) const;
    constexpr size_type find_last_of(const CharT* s, size_type pos = npos) const;
    constexpr size_type find_first_not_of(basic_string_view s,
                                          size_type pos = 0) const noexcept;
    constexpr size_type find_first_not_of(CharT c, size_type pos = 0) const noexcept;
    constexpr size_type find_first_not_of(const CharT* s, size_type pos,
                                          size_type n) const;
    constexpr size_type find_first_not_of(const CharT* s, size_type pos = 0) const;
    constexpr size_type find_last_not_of(basic_string_view s,
                                       size_type pos = npos) const noexcept;
    constexpr size_type find_last_not_of(CharT c, size_type pos = npos) const noexcept;
    constexpr size_type find_last_not_of(const CharT* s, size_type pos,
                                         size_type n) const;
    constexpr size_type find_last_not_of(const CharT* s, size_type pos = npos) const;
  private:
    const_pointer data_;          // 설명 전용
    size_type size_;              // 설명 전용
  };
  // deduction guides
  template<class It, class End>
    basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
  template<class R>
    basic_string_view(R&&) -> basic_string_view<ranges::range_value_t<R>>;
}