#include <iostream>
#include <type_traits>
struct A
{
template < typename T >
typename std:: enable_if < std:: is_pointer < T> :: 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 < T> :: 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
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHlwZV90cmFpdHM+CgpzdHJ1Y3QgQQp7CiAgICB0ZW1wbGF0ZSA8IHR5cGVuYW1lIFQgPgogICAgdHlwZW5hbWUgc3RkOjplbmFibGVfaWY8IHN0ZDo6aXNfcG9pbnRlcjxUPjo6dmFsdWUsIHZvaWQgPjo6dHlwZQogICAgZm9vKCBjb25zdCBUJiB2ICkKICAgIHsgc3RkOjpjb3V0IDw8ICJBOjpmb28oIGNvbnN0IFQmIHAgKSAtIFQgaXMgYSBwb2ludGVyLCAqcCA9PSAiIDw8ICp2IDw8ICdcbicgO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