Index: src/libcfa/iostream
===================================================================
--- src/libcfa/iostream	(revision adb6a4f131728a0c59ebb11aef3189b149895233)
+++ src/libcfa/iostream	(revision 7d690958d55beb54cebdf7015660d074ebc40966)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Apr 28 13:08:24 2018
-// Update Count     : 152
+// Last Modified On : Sat Jun  2 08:07:55 2018
+// Update Count     : 153
 //
 
@@ -56,48 +56,50 @@
 // implement writable for intrinsic types
 
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, _Bool );
+forall( dtype ostype | ostream( ostype ) ) {
+	ostype & ?|?( ostype &, _Bool );
 
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, char );
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, signed char );
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, unsigned char );
+	ostype & ?|?( ostype &, char );
+	ostype & ?|?( ostype &, signed char );
+	ostype & ?|?( ostype &, unsigned char );
 
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, short int );
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, unsigned short int );
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, int );
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, unsigned int );
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, long int );
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, long long int );
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, unsigned long int );
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, unsigned long long int );
+	ostype & ?|?( ostype &, short int );
+	ostype & ?|?( ostype &, unsigned short int );
+	ostype & ?|?( ostype &, int );
+	ostype & ?|?( ostype &, unsigned int );
+	ostype & ?|?( ostype &, long int );
+	ostype & ?|?( ostype &, long long int );
+	ostype & ?|?( ostype &, unsigned long int );
+	ostype & ?|?( ostype &, unsigned long long int );
 
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, float ); // FIX ME: should not be required
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, double );
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, long double );
+	ostype & ?|?( ostype &, float ); // FIX ME: should not be required
+	ostype & ?|?( ostype &, double );
+	ostype & ?|?( ostype &, long double );
 
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, float _Complex );
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, double _Complex );
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, long double _Complex );
+	ostype & ?|?( ostype &, float _Complex );
+	ostype & ?|?( ostype &, double _Complex );
+	ostype & ?|?( ostype &, long double _Complex );
 
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, const char * );
-//forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, const char16_t * );
+	ostype & ?|?( ostype &, const char * );
+	// ostype & ?|?( ostype &, const char16_t * );
 #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
-//forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, const char32_t * );
+	// ostype & ?|?( ostype &, const char32_t * );
 #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
-//forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, const wchar_t * );
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, const void * );
+	// ostype & ?|?( ostype &, const wchar_t * );
+	ostype & ?|?( ostype &, const void * );
+
+	// manipulators
+	ostype & ?|?( ostype &, ostype & (*)( ostype & ) );
+	ostype & endl( ostype & );
+	ostype & sep( ostype & );
+	ostype & sepTuple( ostype & );
+	ostype & sepOn( ostype & );
+	ostype & sepOff( ostype & );
+	ostype & sepDisable( ostype & );
+	ostype & sepEnable( ostype & );
+} // distribution
 
 // tuples
 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } )
 ostype & ?|?( ostype & os, T arg, Params rest );
-
-// manipulators
-forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype &, ostype & (*)( ostype & ) );
-forall( dtype ostype | ostream( ostype ) ) ostype & endl( ostype & );
-forall( dtype ostype | ostream( ostype ) ) ostype & sep( ostype & );
-forall( dtype ostype | ostream( ostype ) ) ostype & sepTuple( ostype & );
-forall( dtype ostype | ostream( ostype ) ) ostype & sepOn( ostype & );
-forall( dtype ostype | ostream( ostype ) ) ostype & sepOff( ostype & );
-forall( dtype ostype | ostream( ostype ) ) ostype & sepDisable( ostype & );
-forall( dtype ostype | ostream( ostype ) ) ostype & sepEnable( ostype & );
 
 // writes the range [begin, end) to the given stream
@@ -124,30 +126,32 @@
 }; // readable
 
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Bool & );
+forall( dtype istype | istream( istype ) ) {
+	istype & ?|?( istype &, _Bool & );
 
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, char & );
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, signed char & );
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, unsigned char & );
+	istype & ?|?( istype &, char & );
+	istype & ?|?( istype &, signed char & );
+	istype & ?|?( istype &, unsigned char & );
 
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, short int & );
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, unsigned short int & );
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, int & );
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, unsigned int & );
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, long int & );
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, long long int & );
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, unsigned long int & );
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, unsigned long long int & );
+	istype & ?|?( istype &, short int & );
+	istype & ?|?( istype &, unsigned short int & );
+	istype & ?|?( istype &, int & );
+	istype & ?|?( istype &, unsigned int & );
+	istype & ?|?( istype &, long int & );
+	istype & ?|?( istype &, long long int & );
+	istype & ?|?( istype &, unsigned long int & );
+	istype & ?|?( istype &, unsigned long long int & );
 
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, float & );
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, double & );
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, long double & );
+	istype & ?|?( istype &, float & );
+	istype & ?|?( istype &, double & );
+	istype & ?|?( istype &, long double & );
 
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, float _Complex & );
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, double _Complex & );
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, long double _Complex & );
+	istype & ?|?( istype &, float _Complex & );
+	istype & ?|?( istype &, double _Complex & );
+	istype & ?|?( istype &, long double _Complex & );
 
-// manipulators
-forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, istype & (*)( istype & ) );
-forall( dtype istype | istream( istype ) ) istype & endl( istype & is );
+	// manipulators
+	istype & ?|?( istype &, istype & (*)( istype & ) );
+	istype & endl( istype & is );
+} // distribution
 
 struct _Istream_cstrUC { char * s; };
Index: src/libcfa/iostream.c
===================================================================
--- src/libcfa/iostream.c	(revision adb6a4f131728a0c59ebb11aef3189b149895233)
+++ src/libcfa/iostream.c	(revision 7d690958d55beb54cebdf7015660d074ebc40966)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Apr 28 13:08:25 2018
-// Update Count     : 469
+// Last Modified On : Sat Jun  2 08:24:56 2018
+// Update Count     : 471
 //
 
@@ -26,200 +26,223 @@
 }
 
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, _Bool b ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%s", b ? "true" : "false" );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, char ch ) {
-	fmt( os, "%c", ch );
-	if ( ch == '\n' ) setNL( os, true );
-	sepOff( os );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, signed char c ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%hhd", c );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, unsigned char c ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%hhu", c );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, short int si ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%hd", si );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, unsigned short int usi ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%hu", usi );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, int i ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%d", i );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, unsigned int ui ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%u", ui );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, long int li ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%ld", li );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, unsigned long int uli ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%lu", uli );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, long long int lli ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%lld", lli );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, unsigned long long int ulli ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%llu", ulli );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, float f ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%g", f );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, double d ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%.*lg", DBL_DIG, d );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, long double ld ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%.*Lg", LDBL_DIG, ld );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, float _Complex fc ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%g%+gi", crealf( fc ), cimagf( fc ) );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, double _Complex dc ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%.*lg%+.*lgi", DBL_DIG, creal( dc ), DBL_DIG, cimag( dc ) );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, long double _Complex ldc ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%.*Lg%+.*Lgi", LDBL_DIG, creall( ldc ), LDBL_DIG, cimagl( ldc ) );
-	return os;
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, const char * str ) {
-	enum { Open = 1, Close, OpenClose };
-	static const unsigned char mask[256] @= {
-		// opening delimiters, no space after
-		['('] : Open, ['['] : Open, ['{'] : Open,
-		['='] : Open, ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open,
-		[(unsigned char)'¡'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open,
-		// closing delimiters, no space before
-		[','] : Close, ['.'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close,
-		['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,
-		[')'] : Close, [']'] : Close, ['}'] : Close,
-		// opening-closing delimiters, no space before or after
-		['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose, [':'] : OpenClose,
-		[' '] : OpenClose, ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace
-	}; // mask
-
-  if ( str[0] == '\0' ) { sepOff( os ); return os; }		// null string => no separator
-
-	// first character IS NOT spacing or closing punctuation => add left separator
-	unsigned char ch = str[0];							// must make unsigned
-	if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {
-		fmt( os, "%s", sepGetCur( os ) );
-	} // if
-
-	// if string starts line, must reset to determine open state because separator is off
-	sepReset( os );										// reset separator
-
-	// last character IS spacing or opening punctuation => turn off separator for next item
-	size_t len = strlen( str );
-	ch = str[len - 1];									// must make unsigned
-	if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) {
+forall( dtype ostype | ostream( ostype ) ) {
+	ostype & ?|?( ostype & os, _Bool b ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%s", b ? "true" : "false" );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, char ch ) {
+		fmt( os, "%c", ch );
+		if ( ch == '\n' ) setNL( os, true );
+		sepOff( os );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, signed char c ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%hhd", c );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, unsigned char c ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%hhu", c );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, short int si ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%hd", si );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, unsigned short int usi ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%hu", usi );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, int i ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%d", i );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, unsigned int ui ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%u", ui );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, long int li ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%ld", li );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, unsigned long int uli ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%lu", uli );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, long long int lli ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%lld", lli );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, unsigned long long int ulli ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%llu", ulli );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, float f ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%g", f );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, double d ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%.*lg", DBL_DIG, d );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, long double ld ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%.*Lg", LDBL_DIG, ld );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, float _Complex fc ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%g%+gi", crealf( fc ), cimagf( fc ) );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, double _Complex dc ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%.*lg%+.*lgi", DBL_DIG, creal( dc ), DBL_DIG, cimag( dc ) );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, long double _Complex ldc ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%.*Lg%+.*Lgi", LDBL_DIG, creall( ldc ), LDBL_DIG, cimagl( ldc ) );
+		return os;
+	} // ?|?
+
+	ostype & ?|?( ostype & os, const char * str ) {
+		enum { Open = 1, Close, OpenClose };
+		static const unsigned char mask[256] @= {
+			// opening delimiters, no space after
+			['('] : Open, ['['] : Open, ['{'] : Open,
+			['='] : Open, ['$'] : Open, [(unsigned char)'£'] : Open, [(unsigned char)'¥'] : Open,
+			[(unsigned char)'¡'] : Open, [(unsigned char)'¿'] : Open, [(unsigned char)'«'] : Open,
+			// closing delimiters, no space before
+			[','] : Close, ['.'] : Close, [';'] : Close, ['!'] : Close, ['?'] : Close,
+			['%'] : Close, [(unsigned char)'¢'] : Close, [(unsigned char)'»'] : Close,
+			[')'] : Close, [']'] : Close, ['}'] : Close,
+			// opening-closing delimiters, no space before or after
+			['\''] : OpenClose, ['`'] : OpenClose, ['"'] : OpenClose, [':'] : OpenClose,
+			[' '] : OpenClose, ['\f'] : OpenClose, ['\n'] : OpenClose, ['\r'] : OpenClose, ['\t'] : OpenClose, ['\v'] : OpenClose, // isspace
+		}; // mask
+
+	  if ( str[0] == '\0' ) { sepOff( os ); return os; } // null string => no separator
+
+		// first character IS NOT spacing or closing punctuation => add left separator
+		unsigned char ch = str[0];						// must make unsigned
+		if ( sepPrt( os ) && mask[ ch ] != Close && mask[ ch ] != OpenClose ) {
+			fmt( os, "%s", sepGetCur( os ) );
+		} // if
+
+		// if string starts line, must reset to determine open state because separator is off
+		sepReset( os );									// reset separator
+
+		// last character IS spacing or opening punctuation => turn off separator for next item
+		size_t len = strlen( str );
+		ch = str[len - 1];								// must make unsigned
+		if ( sepPrt( os ) && mask[ ch ] != Open && mask[ ch ] != OpenClose ) {
+			sepOn( os );
+		} else {
+			sepOff( os );
+		} // if
+		if ( ch == '\n' ) setNL( os, true );			// check *AFTER* sepPrt call above as it resets NL flag
+		return write( os, str, len );
+	} // ?|?
+
+// 	ostype & ?|?( ostype & os, const char16_t * str ) {
+// 		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+// 		fmt( os, "%ls", str );
+// 		return os;
+// 	} // ?|?
+
+// #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
+// 	ostype & ?|?( ostype & os, const char32_t * str ) {
+// 		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+// 		fmt( os, "%ls", str );
+// 		return os;
+// 	} // ?|?
+// #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
+
+// 	ostype & ?|?( ostype & os, const wchar_t * str ) {
+// 		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+// 		fmt( os, "%ls", str );
+// 		return os;
+// 	} // ?|?
+
+	ostype & ?|?( ostype & os, const void * p ) {
+		if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
+		fmt( os, "%p", p );
+		return os;
+	} // ?|?
+
+
+	// manipulators
+	ostype & ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
+		return manip( os );
+	} // ?|?
+
+	ostype & sep( ostype & os ) {
+		os | sepGet( os );
+		return os;
+	} // sep
+
+	ostype & sepTuple( ostype & os ) {
+		os | sepGetTuple( os );
+		return os;
+	} // sepTuple
+
+	ostype & endl( ostype & os ) {
+		os | '\n';
+		setNL( os, true );
+		flush( os );
+		sepOff( os );									// prepare for next line
+		return os;
+	} // endl
+
+	ostype & sepOn( ostype & os ) {
 		sepOn( os );
-	} else {
+		return os;
+	} // sepOn
+
+	ostype & sepOff( ostype & os ) {
 		sepOff( os );
-	} // if
-	if ( ch == '\n' ) setNL( os, true );				// check *AFTER* sepPrt call above as it resets NL flag
-	return write( os, str, len );
-} // ?|?
-
-// forall( dtype ostype | ostream( ostype ) )
-// ostype & ?|?( ostype & os, const char16_t * str ) {
-// 	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-// 	fmt( os, "%ls", str );
-// 	return os;
-// } // ?|?
-
-// #if ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 ) // char32_t == wchar_t => ambiguous
-// forall( dtype ostype | ostream( ostype ) )
-// ostype & ?|?( ostype & os, const char32_t * str ) {
-// 	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-// 	fmt( os, "%ls", str );
-// 	return os;
-// } // ?|?
-// #endif // ! ( __ARM_ARCH_ISA_ARM == 1 && __ARM_32BIT_STATE == 1 )
-
-// forall( dtype ostype | ostream( ostype ) )
-// ostype & ?|?( ostype & os, const wchar_t * str ) {
-// 	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-// 	fmt( os, "%ls", str );
-// 	return os;
-// } // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, const void * p ) {
-	if ( sepPrt( os ) ) fmt( os, "%s", sepGetCur( os ) );
-	fmt( os, "%p", p );
-	return os;
-} // ?|?
+		return os;
+	} // sepOff
+
+	ostype & sepEnable( ostype & os ) {
+		sepEnable( os );
+		return os;
+	} // sepEnable
+
+	ostype & sepDisable( ostype & os ) {
+		sepDisable( os );
+		return os;
+	} // sepDisable
+} // distribution
 
 
@@ -234,58 +257,7 @@
 } // ?|?
 
-
-// manipulators
-forall( dtype ostype | ostream( ostype ) )
-ostype & ?|?( ostype & os, ostype & (* manip)( ostype & ) ) {
-	return manip( os );
-} // ?|?
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & sep( ostype & os ) {
-	os | sepGet( os );
-	return os;
-} // sep
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & sepTuple( ostype & os ) {
-	os | sepGetTuple( os );
-	return os;
-} // sepTuple
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & endl( ostype & os ) {
-	os | '\n';
-	setNL( os, true );
-	flush( os );
-	sepOff( os );										// prepare for next line
-	return os;
-} // endl
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & sepOn( ostype & os ) {
-	sepOn( os );
-	return os;
-} // sepOn
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & sepOff( ostype & os ) {
-	sepOff( os );
-	return os;
-} // sepOff
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & sepEnable( ostype & os ) {
-	sepEnable( os );
-	return os;
-} // sepEnable
-
-forall( dtype ostype | ostream( ostype ) )
-ostype & sepDisable( ostype & os ) {
-	sepDisable( os );
-	return os;
-} // sepDisable
-
 //---------------------------------------
 
+// writes the range [begin, end) to the given stream
 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
 void write( iterator_type begin, iterator_type end, ostype & os ) {
@@ -302,137 +274,121 @@
 //---------------------------------------
 
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, _Bool & b ) {
-	char val[6];
-	fmt( is, "%5s", val );
-	if ( strcmp( val, "true" ) == 0 ) b = true;
-	else if ( strcmp( val, "false" ) == 0 ) b = false;
-	else {
-		fprintf( stderr, "invalid _Bool constant\n" );
-		abort();
-	} // if
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, char & c ) {
-	fmt( is, "%c", &c );								// must pass pointer through varg to fmt
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, signed char & sc ) {
-	fmt( is, "%hhd", &sc );
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, unsigned char & usc ) {
-	fmt( is, "%hhu", &usc );
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, short int & si ) {
-	fmt( is, "%hd", &si );
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, unsigned short int & usi ) {
-	fmt( is, "%hu", &usi );
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, int & i ) {
-	fmt( is, "%d", &i );
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, unsigned int & ui ) {
-	fmt( is, "%u", &ui );
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, long int & li ) {
-	fmt( is, "%ld", &li );
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, unsigned long int & ulli ) {
-	fmt( is, "%lu", &ulli );
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, long long int & lli ) {
-	fmt( is, "%lld", &lli );
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, unsigned long long int & ulli ) {
-	fmt( is, "%llu", &ulli );
-	return is;
-} // ?|?
-
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, float & f ) {
-	fmt( is, "%f", &f );
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, double & d ) {
-	fmt( is, "%lf", &d );
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, long double & ld ) {
-	fmt( is, "%Lf", &ld );
-	return is;
-} // ?|?
-
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, float _Complex & fc ) {
-	float re, im;
-	fmt( is, "%g%gi", &re, &im );
-	fc = re + im * _Complex_I;
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, double _Complex & dc ) {
-	double re, im;
-	fmt( is, "%lf%lfi", &re, &im );
-	dc = re + im * _Complex_I;
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, long double _Complex & ldc ) {
-	long double re, im;
-	fmt( is, "%Lf%Lfi", &re, &im );
-	ldc = re + im * _Complex_I;
-	return is;
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & ?|?( istype & is, istype & (* manip)( istype & ) ) {
-	return manip( is );
-} // ?|?
-
-forall( dtype istype | istream( istype ) )
-istype & endl( istype & is ) {
-	fmt( is, "%*[ \t\f\n\r\v]" );						// ignore whitespace
-	return is;
-} // endl
+forall( dtype istype | istream( istype ) ) {
+	istype & ?|?( istype & is, _Bool & b ) {
+		char val[6];
+		fmt( is, "%5s", val );
+		if ( strcmp( val, "true" ) == 0 ) b = true;
+		else if ( strcmp( val, "false" ) == 0 ) b = false;
+		else {
+			fprintf( stderr, "invalid _Bool constant\n" );
+			abort();
+		} // if
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, char & c ) {
+		fmt( is, "%c", &c );							// must pass pointer through varg to fmt
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, signed char & sc ) {
+		fmt( is, "%hhd", &sc );
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, unsigned char & usc ) {
+		fmt( is, "%hhu", &usc );
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, short int & si ) {
+		fmt( is, "%hd", &si );
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, unsigned short int & usi ) {
+		fmt( is, "%hu", &usi );
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, int & i ) {
+		fmt( is, "%d", &i );
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, unsigned int & ui ) {
+		fmt( is, "%u", &ui );
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, long int & li ) {
+		fmt( is, "%ld", &li );
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, unsigned long int & ulli ) {
+		fmt( is, "%lu", &ulli );
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, long long int & lli ) {
+		fmt( is, "%lld", &lli );
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, unsigned long long int & ulli ) {
+		fmt( is, "%llu", &ulli );
+		return is;
+	} // ?|?
+
+
+	istype & ?|?( istype & is, float & f ) {
+		fmt( is, "%f", &f );
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, double & d ) {
+		fmt( is, "%lf", &d );
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, long double & ld ) {
+		fmt( is, "%Lf", &ld );
+		return is;
+	} // ?|?
+
+
+	istype & ?|?( istype & is, float _Complex & fc ) {
+		float re, im;
+		fmt( is, "%g%gi", &re, &im );
+		fc = re + im * _Complex_I;
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, double _Complex & dc ) {
+		double re, im;
+		fmt( is, "%lf%lfi", &re, &im );
+		dc = re + im * _Complex_I;
+		return is;
+	} // ?|?
+
+	istype & ?|?( istype & is, long double _Complex & ldc ) {
+		long double re, im;
+		fmt( is, "%Lf%Lfi", &re, &im );
+		ldc = re + im * _Complex_I;
+		return is;
+	} // ?|?
+
+
+	// manipulators
+	istype & ?|?( istype & is, istype & (* manip)( istype & ) ) {
+		return manip( is );
+	} // ?|?
+
+	istype & endl( istype & is ) {
+		fmt( is, "%*[ \t\f\n\r\v]" );					// ignore whitespace
+		return is;
+	} // endl
+} // distribution
 
 _Istream_cstrUC cstr( char * str ) { return (_Istream_cstrUC){ str }; }
Index: src/libcfa/rational
===================================================================
--- src/libcfa/rational	(revision adb6a4f131728a0c59ebb11aef3189b149895233)
+++ src/libcfa/rational	(revision 7d690958d55beb54cebdf7015660d074ebc40966)
@@ -12,6 +12,6 @@
 // Created On       : Wed Apr  6 17:56:25 2016
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Dec  6 23:12:53 2017
-// Update Count     : 97
+// Last Modified On : Sat Jun  2 09:10:01 2018
+// Update Count     : 105
 //
 
@@ -46,84 +46,53 @@
 // implementation
 
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-struct Rational {
-	RationalImpl numerator, denominator;				// invariant: denominator > 0
-}; // Rational
+forall( otype RationalImpl | arithmetic( RationalImpl ) ) {
+	struct Rational {
+		RationalImpl numerator, denominator;			// invariant: denominator > 0
+	}; // Rational
 
-// constructors
+	// constructors
 
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-void ?{}( Rational(RationalImpl) & r );
+	void ?{}( Rational(RationalImpl) & r );
+	void ?{}( Rational(RationalImpl) & r, RationalImpl n );
+	void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d );
+	void ?{}( Rational(RationalImpl) & r, zero_t );
+	void ?{}( Rational(RationalImpl) & r, one_t );
 
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-void ?{}( Rational(RationalImpl) & r, RationalImpl n );
+	// numerator/denominator getter
 
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d );
+	RationalImpl numerator( Rational(RationalImpl) r );
+	RationalImpl denominator( Rational(RationalImpl) r );
+	[ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src );
 
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-void ?{}( Rational(RationalImpl) & r, zero_t );
+	// numerator/denominator setter
 
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-void ?{}( Rational(RationalImpl) & r, one_t );
+	RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n );
+	RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d );
 
-// numerator/denominator getter
+	// comparison
 
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-RationalImpl numerator( Rational(RationalImpl) r );
+	int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+	int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+	int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+	int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+	int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+	int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
 
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-RationalImpl denominator( Rational(RationalImpl) r );
+	// arithmetic
 
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-[ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src );
+	Rational(RationalImpl) +?( Rational(RationalImpl) r );
+	Rational(RationalImpl) -?( Rational(RationalImpl) r );
+	Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+	Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+	Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+	Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r );
 
-// numerator/denominator setter
+	// I/O
+	forall( dtype istype | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
+	istype & ?|?( istype &, Rational(RationalImpl) & );
 
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n );
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d );
-
-// comparison
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-
-// arithmetic
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) +?( Rational(RationalImpl) r );
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) -?( Rational(RationalImpl) r );
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+	forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } )
+	ostype & ?|?( ostype &, Rational(RationalImpl ) );
+} // distribution
 
 // conversion
@@ -133,13 +102,4 @@
 Rational(RationalImpl) narrow( double f, RationalImpl md );
 
-// I/O
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-forall( dtype istype | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
-istype & ?|?( istype &, Rational(RationalImpl) & );
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } )
-ostype & ?|?( ostype &, Rational(RationalImpl ) );
-
 // Local Variables: //
 // mode: c //
Index: src/libcfa/rational.c
===================================================================
--- src/libcfa/rational.c	(revision adb6a4f131728a0c59ebb11aef3189b149895233)
+++ src/libcfa/rational.c	(revision 7d690958d55beb54cebdf7015660d074ebc40966)
@@ -10,6 +10,6 @@
 // Created On       : Wed Apr  6 17:54:28 2016
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Dec  6 23:13:58 2017
-// Update Count     : 156
+// Last Modified On : Sat Jun  2 09:24:33 2018
+// Update Count     : 162
 //
 
@@ -18,173 +18,166 @@
 #include "stdlib"
 
-// helper routines
-
-// Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce rationals.
-// alternative: https://en.wikipedia.org/wiki/Binary_GCD_algorithm
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-static RationalImpl gcd( RationalImpl a, RationalImpl b ) {
-	for ( ;; ) {										// Euclid's algorithm
-		RationalImpl r = a % b;
-	  if ( r == (RationalImpl){0} ) break;
-		a = b;
-		b = r;
-	} // for
-	return b;
-} // gcd
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-static RationalImpl simplify( RationalImpl & n, RationalImpl & d ) {
-	if ( d == (RationalImpl){0} ) {
-		serr | "Invalid rational number construction: denominator cannot be equal to 0." | endl;
-		exit( EXIT_FAILURE );
-	} // exit
-	if ( d < (RationalImpl){0} ) { d = -d; n = -n; }	// move sign to numerator
-	return gcd( abs( n ), d );							// simplify
-} // Rationalnumber::simplify
-
-
-// constructors
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-void ?{}( Rational(RationalImpl) & r ) {
-	r{ (RationalImpl){0}, (RationalImpl){1} };
-} // rational
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-void ?{}( Rational(RationalImpl) & r, RationalImpl n ) {
-	r{ n, (RationalImpl){1} };
-} // rational
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d ) {
-	RationalImpl t = simplify( n, d );					// simplify
-	r.numerator = n / t;
-	r.denominator = d / t;
-} // rational
-
-
-// getter for numerator/denominator
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-RationalImpl numerator( Rational(RationalImpl) r ) {
-	return r.numerator;
-} // numerator
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-RationalImpl denominator( Rational(RationalImpl) r ) {
-	return r.denominator;
-} // denominator
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-[ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ) {
-	return dest = src.[ numerator, denominator ];
-}
-
-// setter for numerator/denominator
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ) {
-	RationalImpl prev = r.numerator;
-	RationalImpl t = gcd( abs( n ), r.denominator );		// simplify
-	r.numerator = n / t;
-	r.denominator = r.denominator / t;
-	return prev;
-} // numerator
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) {
-	RationalImpl prev = r.denominator;
-	RationalImpl t = simplify( r.numerator, d );			// simplify
-	r.numerator = r.numerator / t;
-	r.denominator = d / t;
-	return prev;
-} // denominator
-
-
-// comparison
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	return l.numerator * r.denominator == l.denominator * r.numerator;
-} // ?==?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	return ! ( l == r );
-} // ?!=?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	return l.numerator * r.denominator < l.denominator * r.numerator;
-} // ?<?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	return l.numerator * r.denominator <= l.denominator * r.numerator;
-} // ?<=?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	return ! ( l <= r );
-} // ?>?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	return ! ( l < r );
-} // ?>=?
-
-
-// arithmetic
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) +?( Rational(RationalImpl) r ) {
-	Rational(RationalImpl) t = { r.numerator, r.denominator };
-	return t;
-} // +?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) -?( Rational(RationalImpl) r ) {
-	Rational(RationalImpl) t = { -r.numerator, r.denominator };
-	return t;
-} // -?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	if ( l.denominator == r.denominator ) {				// special case
-		Rational(RationalImpl) t = { l.numerator + r.numerator, l.denominator };
-		return t;
-	} else {
-		Rational(RationalImpl) t = { l.numerator * r.denominator + l.denominator * r.numerator, l.denominator * r.denominator };
-		return t;
-	} // if
-} // ?+?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	if ( l.denominator == r.denominator ) {				// special case
-		Rational(RationalImpl) t = { l.numerator - r.numerator, l.denominator };
-		return t;
-	} else {
-		Rational(RationalImpl) t = { l.numerator * r.denominator - l.denominator * r.numerator, l.denominator * r.denominator };
-		return t;
-	} // if
-} // ?-?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	Rational(RationalImpl) t = { l.numerator * r.numerator, l.denominator * r.denominator };
-	return t;
-} // ?*?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-	if ( r.numerator < (RationalImpl){0} ) {
-		r.numerator = -r.numerator;
-		r.denominator = -r.denominator;
-	} // if
-	Rational(RationalImpl) t = { l.numerator * r.denominator, l.denominator * r.numerator };
-	return t;
-} // ?/?
-
+forall( otype RationalImpl | arithmetic( RationalImpl ) ) {
+	// helper routines
+
+	// Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce
+	// rationals.  alternative: https://en.wikipedia.org/wiki/Binary_GCD_algorithm
+	static RationalImpl gcd( RationalImpl a, RationalImpl b ) {
+		for ( ;; ) {									// Euclid's algorithm
+			RationalImpl r = a % b;
+		  if ( r == (RationalImpl){0} ) break;
+			a = b;
+			b = r;
+		} // for
+		return b;
+	} // gcd
+
+	static RationalImpl simplify( RationalImpl & n, RationalImpl & d ) {
+		if ( d == (RationalImpl){0} ) {
+			serr | "Invalid rational number construction: denominator cannot be equal to 0." | endl;
+			exit( EXIT_FAILURE );
+		} // exit
+		if ( d < (RationalImpl){0} ) { d = -d; n = -n; } // move sign to numerator
+		return gcd( abs( n ), d );						// simplify
+	} // Rationalnumber::simplify
+
+	// constructors
+
+	void ?{}( Rational(RationalImpl) & r ) {
+		r{ (RationalImpl){0}, (RationalImpl){1} };
+	} // rational
+
+	void ?{}( Rational(RationalImpl) & r, RationalImpl n ) {
+		r{ n, (RationalImpl){1} };
+	} // rational
+
+	void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d ) {
+		RationalImpl t = simplify( n, d );				// simplify
+		r.numerator = n / t;
+		r.denominator = d / t;
+	} // rational
+
+
+	// getter for numerator/denominator
+
+	RationalImpl numerator( Rational(RationalImpl) r ) {
+		return r.numerator;
+	} // numerator
+
+	RationalImpl denominator( Rational(RationalImpl) r ) {
+		return r.denominator;
+	} // denominator
+
+	[ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ) {
+		return dest = src.[ numerator, denominator ];
+	} // ?=?
+
+	// setter for numerator/denominator
+
+	RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ) {
+		RationalImpl prev = r.numerator;
+		RationalImpl t = gcd( abs( n ), r.denominator ); // simplify
+		r.numerator = n / t;
+		r.denominator = r.denominator / t;
+		return prev;
+	} // numerator
+
+	RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) {
+		RationalImpl prev = r.denominator;
+		RationalImpl t = simplify( r.numerator, d );	// simplify
+		r.numerator = r.numerator / t;
+		r.denominator = d / t;
+		return prev;
+	} // denominator
+
+	// comparison
+
+	int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		return l.numerator * r.denominator == l.denominator * r.numerator;
+	} // ?==?
+
+	int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		return ! ( l == r );
+	} // ?!=?
+
+	int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		return l.numerator * r.denominator < l.denominator * r.numerator;
+	} // ?<?
+
+	int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		return l.numerator * r.denominator <= l.denominator * r.numerator;
+	} // ?<=?
+
+	int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		return ! ( l <= r );
+	} // ?>?
+
+	int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		return ! ( l < r );
+	} // ?>=?
+
+	// arithmetic
+
+	Rational(RationalImpl) +?( Rational(RationalImpl) r ) {
+		Rational(RationalImpl) t = { r.numerator, r.denominator };
+		return t;
+	} // +?
+
+	Rational(RationalImpl) -?( Rational(RationalImpl) r ) {
+		Rational(RationalImpl) t = { -r.numerator, r.denominator };
+		return t;
+	} // -?
+
+	Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		if ( l.denominator == r.denominator ) {			// special case
+			Rational(RationalImpl) t = { l.numerator + r.numerator, l.denominator };
+			return t;
+		} else {
+			Rational(RationalImpl) t = { l.numerator * r.denominator + l.denominator * r.numerator, l.denominator * r.denominator };
+			return t;
+		} // if
+	} // ?+?
+
+	Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		if ( l.denominator == r.denominator ) {			// special case
+			Rational(RationalImpl) t = { l.numerator - r.numerator, l.denominator };
+			return t;
+		} else {
+			Rational(RationalImpl) t = { l.numerator * r.denominator - l.denominator * r.numerator, l.denominator * r.denominator };
+			return t;
+		} // if
+	} // ?-?
+
+	Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		Rational(RationalImpl) t = { l.numerator * r.numerator, l.denominator * r.denominator };
+		return t;
+	} // ?*?
+
+	Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+		if ( r.numerator < (RationalImpl){0} ) {
+			r.numerator = -r.numerator;
+			r.denominator = -r.denominator;
+		} // if
+		Rational(RationalImpl) t = { l.numerator * r.denominator, l.denominator * r.numerator };
+		return t;
+	} // ?/?
+
+	// I/O
+
+	forall( dtype istype | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
+	istype & ?|?( istype & is, Rational(RationalImpl) & r ) {
+		RationalImpl t;
+		is | r.numerator | r.denominator;
+		t = simplify( r.numerator, r.denominator );
+		r.numerator /= t;
+		r.denominator /= t;
+		return is;
+	} // ?|?
+
+	forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } )
+	ostype & ?|?( ostype & os, Rational(RationalImpl ) r ) {
+		return os | r.numerator | '/' | r.denominator;
+	} // ?|?
+} // distribution
 
 // conversion
@@ -195,7 +188,7 @@
 } // widen
 
-// http://www.ics.uci.edu/~eppstein/numth/frap.c
 forall( otype RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } )
 Rational(RationalImpl) narrow( double f, RationalImpl md ) {
+	// http://www.ics.uci.edu/~eppstein/numth/frap.c
 	if ( md <= (RationalImpl){1} ) {					// maximum fractional digits too small?
 		return (Rational(RationalImpl)){ convert( f ), (RationalImpl){1}}; // truncate fraction
@@ -224,24 +217,4 @@
 } // narrow
 
-
-// I/O
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-forall( dtype istype | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
-istype & ?|?( istype & is, Rational(RationalImpl) & r ) {
-	RationalImpl t;
-	is | r.numerator | r.denominator;
-	t = simplify( r.numerator, r.denominator );
-	r.numerator /= t;
-	r.denominator /= t;
-	return is;
-} // ?|?
-
-forall( otype RationalImpl | arithmetic( RationalImpl ) )
-forall( dtype ostype | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } )
-ostype & ?|?( ostype & os, Rational(RationalImpl ) r ) {
-	return os | r.numerator | '/' | r.denominator;
-} // ?|?
-
 // Local Variables: //
 // tab-width: 4 //
Index: src/libcfa/stdlib
===================================================================
--- src/libcfa/stdlib	(revision adb6a4f131728a0c59ebb11aef3189b149895233)
+++ src/libcfa/stdlib	(revision 7d690958d55beb54cebdf7015660d074ebc40966)
@@ -10,11 +10,16 @@
 // Created On       : Thu Jan 28 17:12:35 2016
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Fri Jun  1 19:52:52 2018
-// Update Count     : 302
+// Last Modified On : Sat Jun  2 08:46:35 2018
+// Update Count     : 306
 //
 
 #pragma once
 
-#include <stdlib.h>										// strto*, *abs
+#include <stdlib.h>										// allocation, strto*, *abs
+extern "C" {
+	void * memalign( size_t align, size_t size );
+	void * aligned_alloc( size_t align, size_t size );
+	void * memset( void * dest, int c, size_t size );
+} // extern "C"
 
 //---------------------------------------
@@ -27,6 +32,7 @@
 //---------------------------------------
 
-// C dynamic allocation
 static inline forall( dtype T | sized(T) ) {
+	// C dynamic allocation
+
 	T * malloc( void ) {
 		// printf( "* malloc\n" );
@@ -51,5 +57,4 @@
 	} // realloc
 
-	extern "C" { void * memalign( size_t align, size_t size ); } // use default C routine for void *
 	T * memalign( size_t align ) {
 		//printf( "X4\n" );
@@ -57,5 +62,4 @@
 	} // memalign
 
-	extern "C" { void * aligned_alloc( size_t align, size_t size ); } // use default C routine for void *
 	T * aligned_alloc( size_t align ) {
 		//printf( "X5\n" );
@@ -67,9 +71,7 @@
 		return posix_memalign( (void **)ptr, align, sizeof(T) ); // C posix_memalign
 	} // posix_memalign
-} // distribution
-
-// Cforall dynamic allocation
-static inline forall( dtype T | sized(T) ) {
-	extern "C" { void * memset( void * dest, int c, size_t size ); } // use default C routine for void *
+
+
+	// Cforall dynamic allocation
 
 	T * alloc( void ) {
@@ -104,45 +106,59 @@
 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
 
-static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align ) {
-	//printf( "X13\n" );
-	return (T *)memalign( align, sizeof(T) );
-} // align_alloc
-static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, char fill ) {
-	//printf( "X14\n" );
-    T * ptr = (T *)memalign( align, sizeof(T) );
-    return (T *)memset( ptr, (int)fill, sizeof(T) );
-} // align_alloc
-
-static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim ) {
-	//printf( "X15\n" );
-	return (T *)memalign( align, dim * sizeof(T) );
-} // align_alloc
-static inline forall( dtype T | sized(T) ) T * align_alloc( size_t align, size_t dim, char fill ) {
-	//printf( "X16\n" );
-    T * ptr = (T *)memalign( align, dim * sizeof(T) );
-    return (T *)memset( ptr, (int)fill, dim * sizeof(T) );
-} // align_alloc
-
-
-// data, non-array types
-static inline forall( dtype T | sized(T) ) T * memset( T * dest, char c ) {
-	//printf( "X17\n" );
-	return (T *)memset( dest, c, sizeof(T) );
-} // memset
-extern "C" { void * memcpy( void * dest, const void * src, size_t size ); } // use default C routine for void *
-static inline forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src ) {
-	//printf( "X18\n" );
-	return (T *)memcpy( dest, src, sizeof(T) );
-} // memcpy
-
-// data, array types
-static inline forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c ) {
-	//printf( "X19\n" );
-	return (T *)(void *)memset( dest, c, dim * sizeof(T) );	// C memset
-} // memset
-static inline forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim ) {
-	//printf( "X20\n" );
-	return (T *)(void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy
-} // memcpy
+
+static inline forall( dtype T | sized(T) ) {
+	T * align_alloc( size_t align ) {
+		//printf( "X13\n" );
+		return (T *)memalign( align, sizeof(T) );
+	} // align_alloc
+
+	T * align_alloc( size_t align, char fill ) {
+		//printf( "X14\n" );
+		T * ptr = (T *)memalign( align, sizeof(T) );
+		return (T *)memset( ptr, (int)fill, sizeof(T) );
+	} // align_alloc
+
+	T * align_alloc( size_t align, size_t dim ) {
+		//printf( "X15\n" );
+		return (T *)memalign( align, dim * sizeof(T) );
+	} // align_alloc
+
+	T * align_alloc( size_t align, size_t dim, char fill ) {
+		//printf( "X16\n" );
+		T * ptr = (T *)memalign( align, dim * sizeof(T) );
+		return (T *)memset( ptr, (int)fill, dim * sizeof(T) );
+	} // align_alloc
+} // distribution
+
+
+static inline forall( dtype T | sized(T) ) {
+	// data, non-array types
+
+	T * memset( T * dest, char c ) {
+		//printf( "X17\n" );
+		return (T *)memset( dest, c, sizeof(T) );
+	} // memset
+
+	extern "C" { void * memcpy( void * dest, const void * src, size_t size ); } // use default C routine for void *
+
+	T * memcpy( T * dest, const T * src ) {
+		//printf( "X18\n" );
+		return (T *)memcpy( dest, src, sizeof(T) );
+	} // memcpy
+} // distribution
+
+static inline forall( dtype T | sized(T) ) {
+	// data, array types
+
+	T * memset( T dest[], size_t dim, char c ) {
+		//printf( "X19\n" );
+		return (T *)(void *)memset( dest, c, dim * sizeof(T) );	// C memset
+	} // memset
+
+	T * memcpy( T dest[], const T src[], size_t dim ) {
+		//printf( "X20\n" );
+		return (T *)(void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy
+	} // memcpy
+} // distribution
 
 // allocation/deallocation and constructor/destructor, non-array types
@@ -190,45 +206,23 @@
 //---------------------------------------
 
-forall( otype E | { int ?<?( E, E ); } )
-E * bsearch( E key, const E * vals, size_t dim );
-
-forall( otype E | { int ?<?( E, E ); } )
-size_t bsearch( E key, const E * vals, size_t dim );
-
-forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
-E * bsearch( K key, const E * vals, size_t dim );
-
-forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
-size_t bsearch( K key, const E * vals, size_t dim );
-
-
-forall( otype E | { int ?<?( E, E ); } )
-E * bsearchl( E key, const E * vals, size_t dim );
-
-forall( otype E | { int ?<?( E, E ); } )
-size_t bsearchl( E key, const E * vals, size_t dim );
-
-forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
-E * bsearchl( K key, const E * vals, size_t dim );
-
-forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
-size_t bsearchl( K key, const E * vals, size_t dim );
-
-
-forall( otype E | { int ?<?( E, E ); } )
-E * bsearchu( E key, const E * vals, size_t dim );
-
-forall( otype E | { int ?<?( E, E ); } )
-size_t bsearchu( E key, const E * vals, size_t dim );
-
-forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
-E * bsearchu( K key, const E * vals, size_t dim );
-
-forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
-size_t bsearchu( K key, const E * vals, size_t dim );
-
-
-forall( otype E | { int ?<?( E, E ); } )
-void qsort( E * vals, size_t dim );
+forall( otype E | { int ?<?( E, E ); } ) {
+	E * bsearch( E key, const E * vals, size_t dim );
+	size_t bsearch( E key, const E * vals, size_t dim );
+	E * bsearchl( E key, const E * vals, size_t dim );
+	size_t bsearchl( E key, const E * vals, size_t dim );
+	E * bsearchu( E key, const E * vals, size_t dim );
+	size_t bsearchu( E key, const E * vals, size_t dim );
+
+	void qsort( E * vals, size_t dim );
+} // distribution
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } ) {
+	E * bsearch( K key, const E * vals, size_t dim );
+	size_t bsearch( K key, const E * vals, size_t dim );
+	E * bsearchl( K key, const E * vals, size_t dim );
+	size_t bsearchl( K key, const E * vals, size_t dim );
+	E * bsearchu( K key, const E * vals, size_t dim );
+	size_t bsearchu( K key, const E * vals, size_t dim );
+} // distribution
 
 //---------------------------------------
Index: src/libcfa/stdlib.c
===================================================================
--- src/libcfa/stdlib.c	(revision adb6a4f131728a0c59ebb11aef3189b149895233)
+++ src/libcfa/stdlib.c	(revision 7d690958d55beb54cebdf7015660d074ebc40966)
@@ -10,6 +10,6 @@
 // Created On       : Thu Jan 28 17:10:29 2016
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Jan  3 08:29:29 2018
-// Update Count     : 444
+// Last Modified On : Sat Jun  2 06:15:05 2018
+// Update Count     : 448
 //
 
@@ -130,122 +130,112 @@
 //---------------------------------------
 
-forall( otype E | { int ?<?( E, E ); } )
-E * bsearch( E key, const E * vals, size_t dim ) {
-	int cmp( const void * t1, const void * t2 ) {
-		return *(E *)t1 < *(E *)t2 ? -1 : *(E *)t2 < *(E *)t1 ? 1 : 0;
-	} // cmp
-	return (E *)bsearch( &key, vals, dim, sizeof(E), cmp );
-} // bsearch
-
-forall( otype E | { int ?<?( E, E ); } )
-size_t bsearch( E key, const E * vals, size_t dim ) {
-	E * result = bsearch( key, vals, dim );
-	return result ? result - vals : dim;				// pointer subtraction includes sizeof(E)
-} // bsearch
-
-forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
-E * bsearch( K key, const E * vals, size_t dim ) {
-	int cmp( const void * t1, const void * t2 ) {
-		return *(K *)t1 < getKey( *(E *)t2 ) ? -1 : getKey( *(E *)t2 ) < *(K *)t1 ? 1 : 0;
-	} // cmp
-	return (E *)bsearch( &key, vals, dim, sizeof(E), cmp );
-} // bsearch
-
-forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
-size_t bsearch( K key, const E * vals, size_t dim ) {
-	E * result = bsearch( key, vals, dim );
-	return result ? result - vals : dim;				// pointer subtraction includes sizeof(E)
-} // bsearch
-
-
-forall( otype E | { int ?<?( E, E ); } )
-size_t bsearchl( E key, const E * vals, size_t dim ) {
-	size_t l = 0, m, h = dim;
-	while ( l < h ) {
-		m = (l + h) / 2;
-		if ( (E &)(vals[m]) < key ) {					// cast away const
-			l = m + 1;
-		} else {
-			h = m;
-		} // if
-	} // while
-	return l;
-} // bsearchl
-
-forall( otype E | { int ?<?( E, E ); } )
-E * bsearchl( E key, const E * vals, size_t dim ) {
-	size_t posn = bsearchl( key, vals, dim );
-	return (E *)(&vals[posn]);							// cast away const
-} // bsearchl
-
-forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
-size_t bsearchl( K key, const E * vals, size_t dim ) {
-	size_t l = 0, m, h = dim;
-	while ( l < h ) {
-		m = (l + h) / 2;
-		if ( getKey( vals[m] ) < key ) {
-			l = m + 1;
-		} else {
-			h = m;
-		} // if
-	} // while
-	return l;
-} // bsearchl
-
-forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
-E * bsearchl( K key, const E * vals, size_t dim ) {
-	size_t posn = bsearchl( key, vals, dim );
-	return (E *)(&vals[posn]);							// cast away const
-} // bsearchl
-
-
-forall( otype E | { int ?<?( E, E ); } )
-size_t bsearchu( E key, const E * vals, size_t dim ) {
-	size_t l = 0, m, h = dim;
-	while ( l < h ) {
-		m = (l + h) / 2;
-		if ( ! ( key < (E &)(vals[m]) ) ) {				// cast away const
-			l = m + 1;
-		} else {
-			h = m;
-		} // if
-	} // while
-	return l;
-} // bsearchu
-
-forall( otype E | { int ?<?( E, E ); } )
-E * bsearchu( E key, const E * vals, size_t dim ) {
-	size_t posn = bsearchu( key, vals, dim );
-	return (E *)(&vals[posn]);
-} // bsearchu
-
-forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
-size_t bsearchu( K key, const E * vals, size_t dim ) {
-	size_t l = 0, m, h = dim;
-	while ( l < h ) {
-		m = (l + h) / 2;
-		if ( ! ( key < getKey( vals[m] ) ) ) {
-			l = m + 1;
-		} else {
-			h = m;
-		} // if
-	} // while
-	return l;
-} // bsearchu
-
-forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } )
-E * bsearchu( K key, const E * vals, size_t dim ) {
-	size_t posn = bsearchu( key, vals, dim );
-	return (E *)(&vals[posn]);
-} // bsearchu
-
-
-forall( otype E | { int ?<?( E, E ); } )
-void qsort( E * vals, size_t dim ) {
-	int cmp( const void * t1, const void * t2 ) {
-		return *(E *)t1 < *(E *)t2 ? -1 : *(E *)t2 < *(E *)t1 ? 1 : 0;
-	} // cmp
-	qsort( vals, dim, sizeof(E), cmp );
-} // qsort
+forall( otype E | { int ?<?( E, E ); } ) {
+	E * bsearch( E key, const E * vals, size_t dim ) {
+		int cmp( const void * t1, const void * t2 ) {
+			return *(E *)t1 < *(E *)t2 ? -1 : *(E *)t2 < *(E *)t1 ? 1 : 0;
+		} // cmp
+		return (E *)bsearch( &key, vals, dim, sizeof(E), cmp );
+	} // bsearch
+
+	size_t bsearch( E key, const E * vals, size_t dim ) {
+		E * result = bsearch( key, vals, dim );
+		return result ? result - vals : dim;			// pointer subtraction includes sizeof(E)
+	} // bsearch
+
+	size_t bsearchl( E key, const E * vals, size_t dim ) {
+		size_t l = 0, m, h = dim;
+		while ( l < h ) {
+			m = (l + h) / 2;
+			if ( (E &)(vals[m]) < key ) {				// cast away const
+				l = m + 1;
+			} else {
+				h = m;
+			} // if
+		} // while
+		return l;
+	} // bsearchl
+
+	E * bsearchl( E key, const E * vals, size_t dim ) {
+		size_t posn = bsearchl( key, vals, dim );
+		return (E *)(&vals[posn]);						// cast away const
+	} // bsearchl
+
+	size_t bsearchu( E key, const E * vals, size_t dim ) {
+		size_t l = 0, m, h = dim;
+		while ( l < h ) {
+			m = (l + h) / 2;
+			if ( ! ( key < (E &)(vals[m]) ) ) {			// cast away const
+				l = m + 1;
+			} else {
+				h = m;
+			} // if
+		} // while
+		return l;
+	} // bsearchu
+
+	E * bsearchu( E key, const E * vals, size_t dim ) {
+		size_t posn = bsearchu( key, vals, dim );
+		return (E *)(&vals[posn]);
+	} // bsearchu
+
+
+	void qsort( E * vals, size_t dim ) {
+		int cmp( const void * t1, const void * t2 ) {
+			return *(E *)t1 < *(E *)t2 ? -1 : *(E *)t2 < *(E *)t1 ? 1 : 0;
+		} // cmp
+		qsort( vals, dim, sizeof(E), cmp );
+	} // qsort
+} // distribution
+
+
+forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } ) {
+	E * bsearch( K key, const E * vals, size_t dim ) {
+		int cmp( const void * t1, const void * t2 ) {
+			return *(K *)t1 < getKey( *(E *)t2 ) ? -1 : getKey( *(E *)t2 ) < *(K *)t1 ? 1 : 0;
+		} // cmp
+		return (E *)bsearch( &key, vals, dim, sizeof(E), cmp );
+	} // bsearch
+
+	size_t bsearch( K key, const E * vals, size_t dim ) {
+		E * result = bsearch( key, vals, dim );
+		return result ? result - vals : dim;			// pointer subtraction includes sizeof(E)
+	} // bsearch
+
+	size_t bsearchl( K key, const E * vals, size_t dim ) {
+		size_t l = 0, m, h = dim;
+		while ( l < h ) {
+			m = (l + h) / 2;
+			if ( getKey( vals[m] ) < key ) {
+				l = m + 1;
+			} else {
+				h = m;
+			} // if
+		} // while
+		return l;
+	} // bsearchl
+
+	E * bsearchl( K key, const E * vals, size_t dim ) {
+		size_t posn = bsearchl( key, vals, dim );
+		return (E *)(&vals[posn]);						// cast away const
+	} // bsearchl
+
+	size_t bsearchu( K key, const E * vals, size_t dim ) {
+		size_t l = 0, m, h = dim;
+		while ( l < h ) {
+			m = (l + h) / 2;
+			if ( ! ( key < getKey( vals[m] ) ) ) {
+				l = m + 1;
+			} else {
+				h = m;
+			} // if
+		} // while
+		return l;
+	} // bsearchu
+
+	E * bsearchu( K key, const E * vals, size_t dim ) {
+		size_t posn = bsearchu( key, vals, dim );
+		return (E *)(&vals[posn]);
+	} // bsearchu
+} // distribution
 
 //---------------------------------------
