Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 奇怪的std::是可构造的吗_C++_Templates_Typetraits - Fatal编程技术网

C++ 奇怪的std::是可构造的吗

C++ 奇怪的std::是可构造的吗,c++,templates,typetraits,C++,Templates,Typetraits,让我们看看这个: #include <vector> #include <type_traits> // somewhere in main using V = std::vector<int&>; 来自gcc的错误消息如下所示: 包含在[各种标准包括]中的文件中 在“class\u gnu\u cxx::new\u allocator”的实例化中: [编译器创建的类链]中需要 错误:正在形成指向引用类型“int&”的指针 分配(大小\u类型\u

让我们看看这个:

#include <vector>
#include <type_traits>

// somewhere in main
using V = std::vector<int&>;
来自gcc的错误消息如下所示:

包含在[各种标准包括]中的文件中
在“class\u gnu\u cxx::new\u allocator”的实例化中:
[编译器创建的类链]中需要
错误:正在形成指向引用类型“int&”的指针
分配(大小\u类型\u n,常量无效*=静态\u转换(0))
^~~~~~~~
错误:正在形成指向引用类型“int&”的指针
解除分配(\u Tp*\u p,大小\u类型\u t)
^~~~~~~~~~

还有一些类似的消息指向标准库头文件的其他部分。后面是一个错误,说明
push\u-back(const-value\u-type&\u-x)
不能用
push\u-back(value\u-type&&u-x)
重载您使用的编译器是什么?你看到了什么错误?请添加最小复制示例。@IgorR。gcc,铿锵,没关系——他们都说了一些关于
int&*
;换句话说,它们实例化默认构造函数
std::vector
,并获取编译器错误,而不是使用SFINAE。因此,错误很可能不会发生在参数替换的直接上下文中。但我们需要更多的细节来做出准确的诊断。
std::vector
是一种未定义的行为。容器是存储其他对象的对象([container.requirements.general])。引用不是对象。
std::vector
未定义。C++对包含这样的构造的程序一无所知。它可以编译,它可以炸毁你的电脑,然后和你的女朋友私奔。我无法用
std::span
复制任何这些内容。如果您的代码在
std::span
中表现异常,请发布它。
bool value = std::is_constructible_v<V>;
namespace std {
namespace detail {
template <class, class T, class... Args>
struct is_constructible_helper : false_type {};

template <class T, class... Args>
struct is_constructible_helper<void_t<decltype(T{declval<Args>()...})>, T, Args...> : true_type {};
} // namespace detail

template <class T, class... Args>
using is_constructible = detail::is_constructible_helper<void, T, Args...>;
} // namespace std
In file included from [various standard includes]
In instantiation of 'class __gnu_cxx::new_allocator<int&>':
required from [chain of compiler-created classes]
error: forming pointer to reference type 'int&'
    allocate(size_type __n, const void* = static_cast<const void*>(0))
    ^~~~~~~~
error: forming pointer to reference type 'int&'
    deallocate(_Tp* __p, size_type __t)
    ^~~~~~~~~~