[問題] constexpr作用
開發平台(Platform): (Ex: Win10, Linux, ...)
Linux
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
GCC
最近再努力看懂rvalue相關的東西,看到一篇文章
有個人寫了is_lvalue他本來沒加"constexpr"可是有人建議他補上
他後來也補上了~想請問這個會有什麼差別嘛??
我看這好像看反編譯的結果好像也不能再編譯期就知道結果?
想問真的有加上的必要嘛??
https://reurl.cc/mLl5Wl
#include <iostream>
template <typename T>
constexpr bool is_lvalue(T&) {
return true;
}
template <typename T>
constexpr bool is_lvalue(T&&) {
return false;
}
int main()
{
std::string a = std::string("Hello");
std::cout << "Is lValue ? " << '\n';
std::cout << "std::string() : " << is_lvalue(std::string()) << '\n';
std::cout << "a : " << is_lvalue(a) << '\n';
std::cout << "a+b : " << is_lvalue(a+ std::string(" world!!! ")) << '\n';
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 39.13.128.208 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1623926961.A.965.html
→
06/17 19:18,
2年前
, 1F
06/17 19:18, 1F
→
06/17 19:18,
2年前
, 2F
06/17 19:18, 2F
推
06/17 19:19,
2年前
, 3F
06/17 19:19, 3F
→
06/17 19:23,
2年前
, 4F
06/17 19:23, 4F
→
06/17 19:42,
2年前
, 5F
06/17 19:42, 5F
→
06/17 22:58,
2年前
, 6F
06/17 22:58, 6F
推
06/17 23:07,
2年前
, 7F
06/17 23:07, 7F
→
06/17 23:08,
2年前
, 8F
06/17 23:08, 8F
→
06/17 23:09,
2年前
, 9F
06/17 23:09, 9F
→
06/17 23:10,
2年前
, 10F
06/17 23:10, 10F
→
06/17 23:10,
2年前
, 11F
06/17 23:10, 11F
推
06/18 05:32,
2年前
, 12F
06/18 05:32, 12F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章