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