Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/133.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::make_数组<;尺寸&u t>;从有符号整数_C++_Arrays_Language Lawyer_C++17 - Fatal编程技术网

C++ std::make_数组<;尺寸&u t>;从有符号整数

C++ std::make_数组<;尺寸&u t>;从有符号整数,c++,arrays,language-lawyer,c++17,C++,Arrays,Language Lawyer,C++17,给定一个代码: constexpr auto a = std::make_array<size_t>(1, 2, 3); 并且std::make_array应该与此构造相同 这是一个理论问题,而不是实际问题 额外问题:如何在GCC的实现中更正std::make_array以接受上面给出的代码 GCC的实现: template <typename _Dest = void, typename... _Types> constexpr auto make_array

给定一个代码:

constexpr auto a = std::make_array<size_t>(1, 2, 3);
并且
std::make_array
应该与此构造相同

这是一个理论问题,而不是实际问题

额外问题:如何在GCC的实现中更正
std::make_array
以接受上面给出的代码

GCC的实现:

template <typename _Dest = void, typename... _Types>
  constexpr auto
  make_array(_Types&&... __t)
    -> array<conditional_t<is_void_v<_Dest>,
                           common_type_t<_Types...>,
                           _Dest>,
             sizeof...(_Types)>
  {
    static_assert(__or_<
                  __not_<is_void<_Dest>>,
                  __and_<__not_<__is_reference_wrapper<decay_t<_Types>>>...>>
                  ::value,
                  "make_array cannot be used without an explicit target type "
                  "if any of the types given is a reference_wrapper");
    return {{forward<_Types>(__t)...}};
  }
模板
康斯特普汽车公司
生成数组(_类型&&…u)
->排列
{
静态断言(或_<
__不是,,
__以及
::价值,
“如果没有显式目标类型,则无法使用make_数组”
“如果给定的任何类型是引用包装”);
返回{forward({uu t)…};
}

否,
std::make_数组
不应与该构造相同

std::make_array
采用
类型&&…
,这需要根据参数确定类型,并且在您的情况下生成类型为
int
的参数。在
make_array
内部,不再有常量值,因此可以在
{}
内部转换范围内常量整数值的例外情况不再适用


另一个例子是
std::array{0}
std::make_array(0)
。前者有效,因为
0
可转换为任何指针类型。后者是无效的,因为恰好具有值
0
的整数参数不能隐式转换为任何指针类型。

它是标准规定的,还是实现的结果?@vladon它是必需的,但我不确定这是否是最新的描述。如果有帮助,当前的措辞来自§9.2.2和。@ildjarn显示了一个例子,它特别指出了OP在此询问的问题,因此感谢链接:)
constexpr std::array<size_t, 3> a{1, 2, 3};
template <typename _Dest = void, typename... _Types>
  constexpr auto
  make_array(_Types&&... __t)
    -> array<conditional_t<is_void_v<_Dest>,
                           common_type_t<_Types...>,
                           _Dest>,
             sizeof...(_Types)>
  {
    static_assert(__or_<
                  __not_<is_void<_Dest>>,
                  __and_<__not_<__is_reference_wrapper<decay_t<_Types>>>...>>
                  ::value,
                  "make_array cannot be used without an explicit target type "
                  "if any of the types given is a reference_wrapper");
    return {{forward<_Types>(__t)...}};
  }