[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gcc
Subject:    Re: Can't match void parameters for empty parms in ptr-mem-functions.
From:       Benjamin Scherrey <scherrey () switchco ! com>
Date:       2000-02-29 0:10:39
[Download RAW message or body]

Thanx for the pointer, Martin. Meanwhile, with some help from a fellow
programmer, I've come up with what should be a compliant solution to
my problem using traits characteristics and template specialization.
Unfortunately, g++ doesn't seem to cope with it and I'm having trouble
determining if my code is at fault or some feature I'm trying to use
simply isn't implemented or is broken. Attached is the revised code
which fails to compile. This time, however, the error message appears
nonsensical because in its "failure to match..." error, the first
candidate it suggests matches exactly!

	Any ideas?

		Ben Scherrey

"Martin v. Loewis" wrote:
> I believe your code is illformed, the instantiation of the template
> Matcher< Test, bool, void > already fails. 14.8.2, [temp.deduct]/2 says
> 
> # ... Type deduction may fail for the following reasons: ...
> # Attempting to create a function type in which a parameter has a type
> # of void.
["match.cpp" (application/x-unknown-content-type-cpp_auto_file)]

//
//	match.cpp	-	Tests pointer to memberfunction void parm resolution problem.
//

template < class ReturnType, class Parm1 = void, class Parm2 = void >
struct Method;

template < class ReturnType, class Parm1, class Parm2 >
struct Method
{
    typedef ReturnType   result_type;
    typedef Parm1        first_parm_type;
    typedef Parm2        second_parm_type;
    typedef ReturnType   method_type( Parm1, Parm2 );
//  Can't do const for some reason!!!  typedef ReturnType   const_method_type( Parm1, Parm2 ) const;
};

template < class ReturnType, class Parm1 >
struct Method< ReturnType, Parm1, void >
{
    typedef ReturnType   result_type;
    typedef Parm1        first_parm_type;    
    typedef ReturnType   method_type( Parm1 );
//  Can't do const for some reason!!!    typedef ReturnType   const_method_type( Parm1 ) const;
};

template < class ReturnType >
struct Method< ReturnType, void, void >
{
    typedef ReturnType   result_type;
    typedef ReturnType   method_type();
//  Can't do const for some reason!!!    typedef ReturnType   const_method_type() const;
};


template < class To, typename ReturnType, typename ParmType >
class Matcher
{
public:

// Old way...	typedef ReturnType (To::*SendMethod)(ParmType) const;

    typedef typename Method< ReturnType, ParmType >::method_type SendMethodType;
    typedef SendMethodType( To::*SendMethod );

	typedef ReturnType (To::*EmptyMethod)() const;

	// This constructor can't match void parm SendMethods.
// can't do const now...	Matcher( const To& t, const SendMethod sm )
    Matcher( To& t, const SendMethod sm )
	{
		
	}


/*
    COMPLETELY BROKE NOW
    
	// This constructor will work, however!
	Matcher( const To& t, const EmptyMethod em )
	{
	}
*/	
	
};

class Test
{
public:

//	bool testVoid( void ) const { return 0; }
    bool testVoid( void ) { return 0; }

//	bool testInt( int ) const { return 0; }
    bool testInt( int ) { return 0; }

};

int main( void )
{
	Test ATest;

	Matcher< Test, bool, void > M1( ATest, &Test::testVoid );

	Matcher< Test, bool, int > M2( ATest, &Test::testInt );

}

// eof( match.cpp )



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic