Is it possible to overload a function that can tell a fixed array from a pointer?

前端 未结 6 1839
感动是毒
感动是毒 2020-12-05 14:06

Motivation:

Almost for fun, I am trying to write a function overload that can tell apart whether the argument is a fixed-size array or a pointer.

6条回答
  •  囚心锁ツ
    2020-12-05 14:33

    You may use the following:

    namespace detail
    {
        template  struct helper;
    
        template  struct helper { void operator() () const {std::cout << "pointer\n";} };
        template  struct helper { void operator() ()const {std::cout << "array\n";} };
    }
    
    
    template 
    void f(const T& )
    {
        detail::helper{}();
    }
    

    Live example

提交回复
热议问题