F
Frederick Gotham
It seems there's quite a few compilers out there that don't follow the C++
Standard when it comes to default-initialisation. Here's some quick test
code if anyone would like to try it out. So far, it seems to identify g++
and VC++ as K++ compilers.
#include <cstddef>
template <class T,std::size_t len>
bool IsAnyElementTrue(T const (&arr)[len])
{
T const *p = arr;
T const *const pover = arr + len;
do if (*p++) return true;
while (pover != p);
return false;
}
#include <iostream>
#include <ostream>
using std::cout;
using std::endl;
int main()
{
int arr1[32] = {};
double arr2[32] = {};
char *arr3[32] = {};
int (&arr4)[32] = *new int[1][32]();
double (&arr5)[32] = *new double[1][32]();
char *(&arr6)[32] = *new char*[1][32]();
if (IsAnyElementTrue(arr1)) cout << "Problem with arr1." << endl;
if (IsAnyElementTrue(arr2)) cout << "Problem with arr2." << endl;
if (IsAnyElementTrue(arr3)) cout << "Problem with arr3." << endl;
if (IsAnyElementTrue(arr4)) cout << "Problem with arr4." << endl;
if (IsAnyElementTrue(arr5)) cout << "Problem with arr5." << endl;
if (IsAnyElementTrue(arr6)) cout << "Problem with arr6." << endl;
delete [] &arr4;
delete [] &arr5;
delete [] &arr6;
}
Standard when it comes to default-initialisation. Here's some quick test
code if anyone would like to try it out. So far, it seems to identify g++
and VC++ as K++ compilers.
#include <cstddef>
template <class T,std::size_t len>
bool IsAnyElementTrue(T const (&arr)[len])
{
T const *p = arr;
T const *const pover = arr + len;
do if (*p++) return true;
while (pover != p);
return false;
}
#include <iostream>
#include <ostream>
using std::cout;
using std::endl;
int main()
{
int arr1[32] = {};
double arr2[32] = {};
char *arr3[32] = {};
int (&arr4)[32] = *new int[1][32]();
double (&arr5)[32] = *new double[1][32]();
char *(&arr6)[32] = *new char*[1][32]();
if (IsAnyElementTrue(arr1)) cout << "Problem with arr1." << endl;
if (IsAnyElementTrue(arr2)) cout << "Problem with arr2." << endl;
if (IsAnyElementTrue(arr3)) cout << "Problem with arr3." << endl;
if (IsAnyElementTrue(arr4)) cout << "Problem with arr4." << endl;
if (IsAnyElementTrue(arr5)) cout << "Problem with arr5." << endl;
if (IsAnyElementTrue(arr6)) cout << "Problem with arr6." << endl;
delete [] &arr4;
delete [] &arr5;
delete [] &arr6;
}