fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template <typename T, typename U, int size1, int size2>
  5. bool equal(T (&arr1)[size1], U (&arr2)[size2] ){
  6. return false;
  7. }
  8.  
  9.  
  10. template <typename T, int size1, int size2>
  11. bool equal(T (&arr1)[size1], T (&arr2)[size2] ){
  12. if(size1 == size2) {
  13. for(int i = 0 ; i < size1; ++i){
  14. if(arr1[i] != arr2[i]) return false;
  15. }
  16. return true;
  17. }
  18. return false;
  19. }
  20.  
  21. int main() {
  22. int a1[]{1, 2, 3, 4};
  23. int a2[]{1, 2, 3, 4};
  24. int a3[]{1, 2, 3, 4, 5};
  25. float a4[]{1, 2, 3, 4};
  26. cout << "a1, a2 are "<< (equal(a1, a2) ? "same" : "different") <<endl ;
  27. cout << "a1, a3 are "<< (equal(a1, a3) ? "same" : "different") <<endl ;
  28. cout << "a1, a4 are "<< (equal(a1, a4) ? "same" : "different") <<endl ;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
a1, a2 are same
a1, a3 are different
a1, a4 are different