fork download
#include 
#include 

struct A
{
    template < typename T >
    typename std::enable_if< std::is_pointer::value, void >::type
    foo( const T& v )
    { std::cout << "A::foo( const T& p ) - T is a pointer, *p == " << *v << '\n' ; }

    template < typename T >
    typename std::enable_if< !std::is_pointer::value, void >::type
    foo( const T& v )
    { std::cout << "A::foo( const T& v ) - T is not a pointer, v == " << v << '\n' ; }

    template < typename T, std::size_t N >
    void foo( const T(&array)[N] )
    {
        std::cout << "A::foo( const T(&array)[" << N << "] ): " ;
        for( const auto& v : array ) std::cout << v << ' ' ;
        std::cout << '\n' ;
    }

    template < typename T >
    void foo( const T array[], std::size_t n )
    {
        std::cout << "A::foo( const T array[], n ) - n == " << n << ": " ;
        for( std::size_t i = 0 ; i < n ; ++i ) std::cout << array[i] << ' ' ;
        std::cout << '\n' ;
    }
};

int main()
{
    double d[5] = { 1.1, 2.3, 3.3, 4.4, 5.5 } ;
    A a ;

    a.foo( d[3] ) ; // A::foo( const T& v ) - T is not a pointer, v == 4.4
    a.foo(d) ; // A::foo( const T(&array)[5] ): 1.1 2.3 3.3 4.4 5.5
    a.foo( d, 5 ) ; // A::foo( const T array[], n ) - n == 5: 1.1 2.3 3.3 4.4 5.5
    a.foo( +d ) ; // A::foo( const T& p ) - T is a pointer, *p == 1.1
}
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
A::foo( const T& v ) - T is not a pointer, v == 4.4
A::foo( const T(&array)[5] ): 1.1 2.3 3.3 4.4 5.5 
A::foo( const T array[], n ) - n == 5: 1.1 2.3 3.3 4.4 5.5 
A::foo( const T& p ) - T is a pointer, *p == 1.1