constexpr

    0熱度

    1回答

    我正在爲學習目的創建自己的字符串視圖類,並試圖使其100%constexpr。 爲了測試它,我有一個返回散列值的成員函數。然後,我在switch語句中構造我的字符串視圖,並調用該成員函數,如果它通過,則該成員函數已完全歸檔其目的。 要了解,我使用了/讀/比較我的實現與Visual Studio 2017年最新的更新std::string_view,但是,我注意到,儘管swap被標記爲constex

    2熱度

    1回答

    我有一個CRTP模板類在這裏: template <typename S> class Base { public: constexpr static S NOT_SET{0}; }; struct Derived : public Base<Derived> { }; 鏘(5.0.0)不接受這一點: 5 : <source>:5:24: error: con

    0熱度

    1回答

    考慮一個static constexpr成員的這種使用情況: // smart_enum.h class smart_enum { // Some data, operations, etc. // Cannot use constexpr here, smart_enum is incomplete at this point static const smart

    5熱度

    2回答

    內const int的我有一個配置類 // config.hpp class Config { public: static constexpr int a = 1; static constexpr int b = 1; } 和main.cpp中包括 // main.cpp #include "config.hpp" int main() {

    1熱度

    1回答

    結果我有constexpr函數計算佔位符https://godbolt.org/g/JcxSiu的數量, e.g: 「Hello %1」 返回1和 「Hello %1, time is %2」 返回2。 然後,我想作出一個函數,如果參數的數量不等於佔位符的數量,它不會編譯。 template <typename... Args> inline std::string make(const cha

    2熱度

    1回答

    我正在探索constexpr的世界,並決定創建一個只應用於constexpr上下文和其他編譯時構造的類。 通常情況下,我非常謹慎地提供所有必要的重載類可根據需要,例如: template <typename T> struct Thing { Thing(T value) : m_value(value) {} T &value() & { return m_value;

    2熱度

    1回答

    我試圖編譯C++庫(與海灣合作委員會5.3.1-14ubuntu2),並得到了這種類型的錯誤: > In file included from > /root/pitchfork/workspace/unanimity/include/pacbio/consensus/ModelConfig.h:49:0, > from /root/pitchfork/workspace/unanim

    4熱度

    3回答

    在下面的示例中main可以static_assert如果字符串文字以'v'開頭,但verify不能。 爲什麼會發生?有沒有一種方法允許verify到static_assert條件字符串中的字符? #include <cstddef> template <std::size_t N> constexpr char get_first(const char (&str)[N]) {

    3熱度

    1回答

    編譯constexpr代碼時編譯以下代碼(godbolt): constexpr bool f(const char *&s) { do { ++s; } while (*s); return true; } constexpr bool g(const char *s) { return f(s); } int main() {

    11熱度

    1回答

    我遇到了一個g ++問題,使用static_cast在constexpr上下文中上傳了一個成員指針。看代碼示例。 當使用g ++版本6.3和7.0進行編譯時,他們給出編譯錯誤,說reinterpret_cast不是一個常量表達式。 雖然鐺4.0版沒有提供任何錯誤,我認爲這是正確的,因爲這裏沒有reinterpret_cast。 這是g ++或clang中的錯誤嗎?什麼是正確的行爲? struct