E.g.,
--------------------------------------------------------------------------------------------------
using Size = ptrdiff_t;
using Index = ptrdiff_t;
template< class T > using P_ = T*;
template< class T > using Type_ = T;
namespace my
{
using std::vector;
struct Pod { char e[80]; };
class Class
{
vector<Pod> m_data;
template< class Self, class Func >
friend void enumerate_on( Self& self, const Func f )
{
for( auto& item: self.m_data )
{
if( !!item.e[0] ) { f( &item ); }
}
}
public:
// void enumerate( void (*const pFunc)(MyPOD const*) ) const
void enumerate( const Type_<void( const Pod* )> f ) const
{
enumerate_on( *this, f );
}
// void MyClass::Enumerate( void (*const pFunc)(MyPOD*) ) /*
Not const because pointer is not to const */
void enumerate( const Type_<void( Pod* )> f )
{
enumerate_on( *this, f );
}
};
};
--------------------------------------------------------------------------------------------------
With that basic technique understood, consider letting the function type
be just a template parameter also in the public interface.
Unless these functions are meant to be called from C.
Cheers & hth.,
- Alf