Re: Trying to apply SFINAE
Kai-Uwe Bux wrote:
Francesco wrote:
[...]
That idea can work a little simpler:
[code snipped]
In my case it's even simpler, since I don't need the meta-function.
Here's what I came up with while commuting this morning:
struct yes_type { char dummy; };
struct no_type { char dummy1; char dummy2; };
template < typename T >
yes_type is_iterator(const T&, typename T::iterator_category* = 0)
{return yes_type();}
template < typename T >
yes_type is_iterator(const T* const)
{return yes_type();}
no_type is_iterator(const void* const)
{return no_type();}
no_type is_iterator(...)
{return no_type();}
#include <iostream>
#include <vector>
template < typename T >
inline void show( const T&, yes_type /*is_iterator*/)
{std::cout << "iterator: ";}
template < typename T >
inline void show( const T&, no_type /*is_iterator*/)
{std::cout << "no iterator: ";}
template < typename T >
inline void show(const char* str) {
show( T(), typename is_iterator(T()) );
std::cout << str << '\n';
}
#define SHOW(T) show<T>(#T)
int main() {
SHOW( int* );
SHOW( int** );
SHOW( int* const* );
SHOW( const int* );
SHOW( const int** );
SHOW( const int* const* );
SHOW( std::vector<int>::const_iterator );
std::cout << '\n';
SHOW( void* );
SHOW( std::vector<int> );
SHOW( int );
}
However, this still needs a forwarding function... <sighs>
Kai-Uwe Bux
Schobi