cost 336 ms
运算符 && 在 constexpr 上下文中的奇怪行为 - strange behaviour of operator && in constexpr context

以下代码尝试根据参数包中传递的最后一个参数做出编译时决策。 它包含一个比较,如果参数包 arguments 的数量 > 0,然后尝试获取它的最后一个元素。 但是,构造的元组是在一个无效索引处访问的,该索引应该大于最大元组索引(如static_assert所示)。 如果我做cnt-1那怎么可能? ...

如果设置了可选的 function 参数,如何启用模板参数? - How to enable template parameter if optional function parameter is set?

我有一个解析 function,我想根据是否设置长度选项进行分支。 如果设置了长度选项,function 应该始终检查减少的长度是否等于 0。如果不是,它只检查 null 终止。 基于这个小细节,我不想重写我的整个 function,所以这就是我想出的: 神栓让我烦恼的是,我总是必须使用长度选项 ...

将用于类型检查的 if constexpr 中的 static_assert 转换为 C++14 - Convert static_assert in if constexpr for type checking to C++14

我正在努力将 C++ 17 项目降级到 C++ 14。我找到了以下代码: 它使用if constexpr检查类型并相应地返回类型名称。 如果没有类型匹配,它会调用一个使用static_assert的模板函数get_assertion_message 。 我正在考虑根据我之前的问题在这里应用解决 ...

将基于 constexpr 的 C++17 模板化代码转换为 C++14 - Convert if constexpr based C++17 templatized code to C++14

我正在将一个用 C++ 17 编写的项目降级到 C++ 14。降级时,我遇到了一段涉及if constexpr的代码,我希望将其转换为 C++ 14(据我所知, if constexpr是 C++ 17 功能)。 Boost 的is_detected用于检查给定类型是否具有星号运算符或 get ...

由于 if constexpr,内联模板化 function 具有不同的行为是否违反 ODR? - Is it an ODR violation to have an inline templated function have different behavior due to if constexpr?

可以检测类型是否完整https://devblogs.microsoft.com/oldnewthing/20190710-00/?p=102678 如果一个类型是完整的,我有理由想要提供一个不同的(可内联的)实现。 模板化的 function 在基于 function 中的if constexp ...

我如何 static 断言在非模板成员中禁止“混合字节顺序” function - How can I static assert to disallow "mixed endianness" in a non-templated member function

我在包含std::array<std::byte, 20>的结构中的operator<=>的高性能实现中使用 2 x std::uint64_t和 1 x std::uint32_t 。 我正在尝试使其与交叉编译器和体系结构兼容。 作为其中的一部分,我试图彻底拒绝任何std ...

是否有一个 constexpr 可以让我确定是否有一个特定类型的 output 运算符 (<<)? - Is there a constexpr which lets me determine if there is an output operator (<<) for a particular type?

为了防止编译器将std::vector&lt;T&gt;应用于std::cout &lt;&lt; u之类的语句,我想做这样的事情: 有什么办法可以做到这一点? 编辑(澄清)我正在研究类似 printf 的 function,它也可以打印 POD 的字符串和向量以及字符串(及其向量)。 我想将此功 ...

生成 constexpr 数组(错误:'sum' 的值在常量表达式中不可用) - Generate constexpr array (error: the value of 'sum' is not usable in a constant expression)

问题我需要将 integer m的所有可能分区生成到j个元素a_k的总和中,其中每个a_k可以是-1 、 0或1 。 这是一种确定性算法,因此它应该能够在编译时实现它。 我想返回一个std::array所有可能的组合作为constexpr 。 我的算法简单明了,一共有3^j种组合。 所以我们遍历所 ...

C++ if constexpr vs 模板专业化 - C++ if constexpr vs template specialization

考虑这两个例子示例 1 示例 2 我知道这两个示例在概念上是相同的,但考虑到这些功能位于SomethingFactory.hpp文件中,而我的main.cpp包含它。 在main.cpp中,我可能只创建了Something1类型,而不知道存在其他Something类型。 我真的很关心我的可执行文件的 ...

如果没有 if-constexpr 成功,触发编译时错误的最佳方法? - Best way to trigger a compile-time error if no if-constexpr's succeed?

我有一长串if constexpr语句,如果它们都不成功,我想触发一个编译时错误。 具体来说,我有一个抽象语法树,我想将其结果转换为我可能需要的一组特定类型。 我有 AsInt()、AsDouble() 等在工作,但我需要能够根据提供的类型更动态地执行此操作。 目前,我已经编写了一个模板化的 As ...


 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM