Issues with templates

Artyom Shalkhakov artyom.shalkhakov at gmail.com
Fri Aug 3 11:35:37 PDT 2007


I'm trying to do byte-order conversions in compile-time rather than run-time, since the latter case is rarely needed (if needed at all).

/// byte-order conventions (for uint conversion)
enum BYTEORDER {
	ARGB8,
	ABGR8,
	RGBA8,
	BGRA8
}

/// color, represented as RGB triple
struct Col3 {
	static Col3 opCall( float r, float g, float b ) {
		...
	}

        // byte-order is mostly static, so I tried to do this using templates
	static Col3 opCall( BYTEORDER order )( uint rgb ) {
		Col3	dst;

		// unpack according to byte-order
		static if ( order == ARGB8 ) {
			...
		}
		else static if ( order == ABGR8 ) {
			...
		}
		....
	}

	float	r, g, b;
}

compiler says:
template Col3.opCall( BYTEORDER order ) conflicts with function Col3.opCall at ...

Why can't I do this? I had to make a parameter for opCall to be able to compile it.
I'm using Tango 0.99 RC3 / DMD 1.18 on Windows.


More information about the Digitalmars-d-learn mailing list