I just tried to initialised a container, which happened to be empty and came across the following phenomenon:
#include <iostream>
#include <array>
#include <algorithm>
int main(int argc, char *argv[])
{
std::array<int,NULL> foo = {};
if ( std::all_of(foo.begin(), foo.end(), [](int i){return i==0;}) )
std::cout << "All the elements are zero.\n";
return 0;
}
compiling with:
clang++ -std=c++11 -stdlib=libc++ -o test test.cpp
resulted in:
bash-3.2$ ./test
All the elements are zero.
I am trying to figure out why an empty container returns true for this operation. This problem might be related to: Behaviour of std::list:begin() when list is empty
However I could not find a proper answer to this particular question.
Thank you for your time.
NULLas an integer constant.NULLis intended to be used as a pointer constant. If you collaborate on software projects with other people, and you useNULLfor things other than what it was intended, you will waste your collaborators' time as they try to understand why there is aNULLthere.NULLto benullptrinstead. So it's not even portable.