開發平台(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';
}
作者:
LPH66 (-6.2598534e+18f)
2021-06-17 23:07:00標 constexpr 的函數若參數也都是 constexpr 的話這樣子的呼叫可以用在文法其他地方需要 constexpr 值的位置例如這裡回傳的 bool 能放在模版參數裡需要一個 bool 之處至於這個 bool 值如果是執行期呼叫, 那是否 inline 或化簡仍然是交給編譯器決定, 並沒有強迫一定要展開