vendredi 22 juillet 2016

c++ template programming for detecting symmetric array at compile time

For example, I have the following c++ code in the header file

struct Data {
    static const int N = 4;
    static const int A[N];
};

And the following content in its cpp file to defined the array A content.

const int Data::A[Data::N] = {1,2,2,1};

Is there any way to write a template to detect the array A content is symmetric at compile time? (probably c++11 feature supports that, but I'm not familiar with its features...)

For example, the DetectSymmetric<Data>::is_sym will be true if the content of A is {1,2,2,1} and false , say if it equals {1,2,3,4}

Aucun commentaire:

Enregistrer un commentaire