fork download
  1. namespace Array
  2. {
  3. template<typename T> class _ischararray_;
  4.  
  5. template<typename T, int N>
  6. class _ischararray_<T[N]> { public: static bool _ischararray(){return true;}};
  7.  
  8. template<typename T>
  9. class _ischararray_<T*> { public: static bool _ischararray(){return false;}};
  10.  
  11. template<class T>
  12. bool isCharArray(const T& x) { return _ischararray_<T>::_ischararray();}
  13. }
  14.  
  15. using namespace Array;
  16. #include <iostream>
  17.  
  18. int main ()
  19. {
  20. const char s1[] = "hello-1";
  21. const char *s2 = "hello-2";
  22. if(isCharArray("hello-3")) std::cout<<"hello-3 char array"<<std::endl;
  23. if(isCharArray(s1)) std::cout<<"s1 char array"<<std::endl;
  24. if(isCharArray(s2)) std::cout<<"s2 char array"<<std::endl;
  25.  
  26. }
Success #stdin #stdout 0.02s 2724KB
stdin
Standard input is empty
stdout
hello-3 char array
s1 char array