【发布时间】:2018-07-08 01:27:20
【问题描述】:
我的内部完整性检查失败,所以我在 Stackoverflow 上重新运行它。
以下代码:
#include <iostream>
#include <typeinfo>
#include <utility>
int main()
{
constexpr auto pair_of_ints = std::make_pair(1, 2);
std::cerr << typeid(pair_of_ints).name();
//static_assert(std::is_same<decltype(pair_of_ints), std::pair<int, int>>::value, "WTF");
}
在我的系统 (XCode Clang 8.x) 上为 std::__1::pair<int, int> 生成损坏的符号名称。
如果我随后启用static_assert,它会失败。我不知道为什么。
我怎样才能使这项工作?我有一个函数根据传递给它的参数返回一对或元组,并想验证它是否在正确的情况下实际返回一对或元组。
【问题讨论】:
-
提示:
pair_of_ints是const。 -
你可以使用
template <typename> struct DebugType;,然后DebugType<decltype(pair_of_ints)> d;来获得带有真实类型的错误信息。
标签: c++ c++11 std-pair static-assert