---
title: "Discussion on \"std::string_view 函數傳值與編譯器最佳化\" | Hashnode"
description: "Discussion on \"std::string_view 函數傳值與編譯器最佳化\". std::string_view 函數傳值與編譯器最佳化\n在使用 c++17 的 std::string_view 時肯定會有這個疑問：\n\n我們該用 const string_view& 還是 string_view ？\n\n因為他本身就是 reference 的意思了，所以在函數傳值時，直接傳值比較符合語意。\n可是考慮到效能：他又至少是一個 struct 包含一個指標和整數，是不是該傳 const"
url: "https://hashnode.com/posts/string-view-and-compiler-optimize/62bb0726c2f205e7cdb17f8d"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [std::string\_view 函數傳值與編譯器最佳化](https://notes.mukyu.dev/string-view-and-compiler-optimize?utm_source=hashnode&utm_medium=feed)

std::string\_view 函數傳值與編譯器最佳化 在使用 c++17 的 std::string\_view 時肯定會有這個疑問： 我們該用 const string\_view& 還是 string\_view ？ 因為他本身就是 reference 的意思了，所以在函數傳值時，直接傳值比較符合語意。 可是考慮到效能：他又至少是一個 struct 包含一個指標和整數，是不是該傳 const

Jun 28, 2022 · 2 min read · notes.mukyu.dev  
Updated Oct 27  
Read the article

-   [#cpp](https://hashnode.com/tag/cpp)

## Written by

[Patchouli](https://hashnode.com/@mudream4869)

@mudream4869 · Uohout

  
[View profile](https://hashnode.com/@mudream4869)

工程師帕秋莉~

後端工程師。 不定時張貼一些寫扣時的筆記，有時英文，有時中文。 「如果，我是魔女的話...」

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
