gcc 6.1 std :: result_of编译错误
gcc 6.1 std::result_of compilation error
考虑一个小的独立用例
#include <type_traits>
namespace {
struct foo {
template<class T, std::size_t = sizeof(T)>
std::false_type operator()(T&);
std::true_type operator()(...);
};
struct FooIncomplete;
}
int main() {
std::result_of<foo(FooIncomplete&)>::type();
return 0;
}
使用--std=c++11
标志使用gcc 4.9.3
罚款。但是,使用gcc 6.1
和--std=c++11
,它会产生一个汇编错误作为
main.cpp: In function 'int main()':
main.cpp:17:5: error: 'type' is not a member of 'std::result_of<{anonymous}::foo({anonymous}::FooIncomplete&)>'
std::result_of<foo(FooIncomplete&)>::type();
我在这里想念什么?可能有什么可能的工作?
,因为C 14 result_of ::如果T不可呼应,则不存在。
在您的情况下,struct fooincomplete无需致电。
使用C 20的is_detected
:
namespace details {
template<template<class...>class Z, class, class...Ts>
struct can_apply:std::false_type{};
template<class...>struct voider{using type=void;};
template<class...Ts>using void_t = typename voider<Ts...>::type;
template<template<class...>class Z, class...Ts>
struct can_apply<Z, void_t<Z<Ts...>>, Ts...>:std::true_type{};
}
template<template<class...>class Z, class...Ts>
using can_apply=typename details::can_apply<Z,void,Ts...>::type;
template<class T>
using size_of = std::integral_constant<std::size_t, sizeof(T)>;
template<class T>
using is_complete = can_apply< size_of, T >;
我们得到一个特质is_complete
,如果FF,则可以将sizeof
应用于T
。
请小心,因为与大多数功能不同,类型的完整性可以在编译单元之间甚至在同一单元中的不同位置之间发生变化。当类型some_template<some_args...>
在程序中的不同点上更改时,C 不喜欢。
实时示例。
相关文章:
- 二叉排序树无法编译
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- 编译错误:"lvalue required as left operand of assignment" 不确定原因
- 当我编译XG-Bosst时,出现错误"error: 'Split' is not a member of 'xgboost::common' ……"
- 编译代码时"[Warning] extra tokens at end of"
- 使用 thrust::d evice_vector of thrust::complex 编译错误,可能是由于错误的实现
- 编译mbed操作系统程序时"multiple definition of `main'"错误
- 尝试解决"out of scope"编译错误:CodeBlocks,Linux Fedora
- 对简单的帐户检查程序有问题?程序返回编译错误,指出"no match for 'operator||' unsure of how to fix?"
- "multiple definition of value"在 g++ 中编译具有未初始化全局但不是 gcc 的 C 程序时
- 科学实验室编译"cannot allocate this quantity of memory"
- C++简单的类程序无法编译。我搞砸了包含标题吗? 'Error redefinition of a class'
- Cmake错误:项目中使用了以下变量,但它们被设置为NOTFOUND,试图在archlinux中编译Rigs of Ro
- Eclipse抱怨:"Invalid overload of 'endl'" - 但代码确实可以编译
- "control reaches end of non-void function" Eclipse C++ 中的警告,但没有编译或运行时错误
- 编译简单的Hello World时进行多次"multiple definition of ..."
- C++编译错误:"Double array redeclared as different kind of symbol"
- 为什么我会收到编译错误"use of deleted function 'std::unique_ptr ..."
- C++编译错误"redefinition of",需要帮助才能找到
- 使用 MingW64 C++ "declaration of '__RPC__range' with no type"编译 IMAPI2.h 应用程序时出现错误