I need to check if std:array was initialized (or some default common value).
The array is optional , so i need to check if it has value or not.
I dont use boost.
i tried this:
array<unsigned char, 2> testArr;
testArr.fill(0);
if(testArr.empty()){
cout << "testArr is empty" <<endl ;
}
i am lookin for a simple way to init to default value and check if default value without iterate (by myself) , is there something?
There are no ways to do this without optional or something else, since
std::array::empty()Checks if the container has no elements, i.e. whether begin() == end().
So, checks, that there is no elements in container (i.e.
std::array<T, 0>) and nothing else. You should use any optional class, or iterate over array and check values. If you don’t want useboost::optional– write your own optional likeboost::optional. It’s very simple.