10得票1回答
boost::variant是否有类似于std::visit的boost::visit?

在C++14中,我使用boost::variant作为编译时多态的一种方式: using MyType = boost::variant<A, B>; 两个类都有一个方法sayHello()。我想调用: MyType obj = ...; // either A() or ...

10得票2回答
Clang 3.4 支持 C++14

我正在使用 travis.ci 对我的git仓库进行自动化测试构建。 对于Linux,它们使用:Ubuntu 12.04 以及clang 3.4。 根据clang页面,Clang 3.4支持所有C ++ 14语言特性(只要您使用-std=c++1y标志)。 目前为止都很好: 我还需要使用...

7得票1回答
MSVC无法在enable_if中评估constexpr函数

考虑一个简单的用于计算逻辑“与”的实用函数,以及使用此实用函数来确保 std::tuple 中的类型都相等。 #include <type_traits> #include <tuple> constexpr auto all() noexcept -> bo...

21得票1回答
为什么 0 == ("abcde"+1) 不是一个常量表达式?

为什么以下代码无法编译?// source.cpp int main() { constexpr bool result = (0 == ("abcde"+1)); } 编译命令是:The compile command:$ g++ -std=c++14 -c source.cpp 输...

30得票2回答
自C++14起,是否总是更喜欢使用set<T, less<>> 而不是 set<T>?

#include &lt;set&gt; #include &lt;string&gt; #include &lt;string_view&gt; using namespace std; int main() { string_view key = "hello"; s...

7得票1回答
虚析构函数如何影响decltype的行为

我创建了一个可选懒惰参数的标题(也可以在GitHub存储库中看到)。 (这不是基于标题的第一个问题。) 我有一个基类模板和两个派生类模板。 基类模板具有带有static_assert的protected构造函数。 此构造函数仅由特定派生类调用。 在static_assert内部,我正在使用d...

12得票3回答
为什么std::array的operator[]不是临时constexpr?

我将一些值填入一个constexpr std::array,并继续将编译时静态优化延伸到更多的constexpr值时,发现在C++11中无法使用元素作为constexpr初始化器。这是因为std::array::operator[]直到C++14才被标记为constexpr:https://d...

11得票4回答
如何比较模板和模板实例?

首先,让我向您介绍一个部分解决方案: template &lt;template &lt;class...&gt; class, typename ...&gt; struct is_tbase_of: std::false_type { }; template &lt...

21得票2回答
为什么不允许使用“constexpr”参数?

希望在IT技术中能够有“constexpr”参数,以区分编译器已知值,并能够在编译时检测错误。以下是一些例子: int do_something(constexpr int x) { static_assert(x &gt; 0, "x must be &gt; 0"); retur...

28得票2回答
`decltype(auto)` 变量有哪些实际应用场景?

从我的个人经验和咨询类似于“decltype(auto)的用途有哪些?”这样的问题的答案中,我可以找到足够多的有价值的应用场景,其中decltype(auto)作为一个函数返回类型占位符。 然而,我很难想出任何合法的(即有用、现实、有价值)用例来使用decltype(auto)变量。唯一想到...