In the case that
N == 0
,begin() == end()
== unique value. The return value ofdata()
is unspecified.
这个独特的值(value)是什么意思?这是否意味着表达式 begin() == end()
的结果是唯一值?我不明白这有什么意义,因为 bool 只能是 true 或 false,这不是很独特。我运行了以下测试:
#include <array>
#include <iostream>
#include <iomanip>
#include <type_traits>
int main()
{
std::array<int, 0> test;
auto b = test.begin();
auto e = test.end();
std::cout << std::boolalpha
<< (test.begin() == test.end())
<< std::is_same<bool, decltype(test.begin() == test.end())>::value
<< std::is_same<bool, decltype(b == e)>::value;
}
它都按预期输出 true
。然后我想知道对于非零大小的数组可能会有所不同:
int main()
{
std::array<int, 0> test;
std::array<int, 1> test2;
std::cout << std::boolalpha
<< std::is_same<
decltype(test.begin() == test.end()),
decltype(test2.begin() == test2.end())
>::value
<< std::is_same<
decltype(test.begin()),
decltype(test2.begin())
>::value;
}
一切都是真的。那么什么是“独特值(value)”呢?什么具有独特的值(value)?
最佳答案
begin() == end() == unique value
与其说是实际的 C++,不如说是一种逻辑描述。它表明 begin() 与 end() 相同,并且它们都等于某个唯一值。
基本上是逻辑表达式 'a=b=c',除了使用 C++ ==
。
关于c++ - 什么是开始()==结束()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37505804/