X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=libs%2Fgeneric%2Ffunctional.h;h=940d4e7fd0af09b448faa099f07ebd8c8e6a904b;hp=ca1d86307f549d388913fbbd7bc358a132b0cfa5;hb=9d606a0b3be053550486b8f1a00255e340ccf8a8;hpb=6ee91d153ea09f2dafa62ed2f022f4183c090168 diff --git a/libs/generic/functional.h b/libs/generic/functional.h index ca1d8630..940d4e7f 100644 --- a/libs/generic/functional.h +++ b/libs/generic/functional.h @@ -1,318 +1,288 @@ -#if !defined(INCLUDED_FUNCTIONAL_H) +#if !defined( INCLUDED_FUNCTIONAL_H ) #define INCLUDED_FUNCTIONAL_H -template +template class Member { public: - typedef Object& first_argument_type; - typedef R result_type; - static result_type call(first_argument_type object) - { - return (object.*member)(); - } +typedef Object& first_argument_type; +typedef R result_type; +static result_type call( first_argument_type object ){ + return ( object.*member )(); +} }; -template +template class ConstMember { public: - typedef const Object& first_argument_type; - typedef R result_type; - static result_type call(first_argument_type object) - { - return (object.*member)(); - } +typedef const Object& first_argument_type; +typedef R result_type; +static result_type call( first_argument_type object ){ + return ( object.*member )(); +} }; -template +template class Member1 { public: - typedef Object& first_argument_type; - typedef A1 second_argument_type; - typedef R result_type; - static result_type call(first_argument_type object, second_argument_type a1) - { - return (object.*member)(a1); - } +typedef Object& first_argument_type; +typedef A1 second_argument_type; +typedef R result_type; +static result_type call( first_argument_type object, second_argument_type a1 ){ + return ( object.*member )( a1 ); +} }; -template +template class ConstMember1 { public: - typedef const Object& first_argument_type; - typedef A1 second_argument_type; - typedef R result_type; - static result_type call(first_argument_type object, second_argument_type a1) - { - return (object.*member)(a1); - } +typedef const Object& first_argument_type; +typedef A1 second_argument_type; +typedef R result_type; +static result_type call( first_argument_type object, second_argument_type a1 ){ + return ( object.*member )( a1 ); +} }; -template +template class Member2 { public: - typedef Object& first_argument_type; - typedef A2 second_argument_type; - typedef A3 third_argument_type; - typedef R result_type; - static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3) - { - return (object.*member)(a2, a3); - } +typedef Object& first_argument_type; +typedef A2 second_argument_type; +typedef A3 third_argument_type; +typedef R result_type; +static result_type call( first_argument_type object, second_argument_type a2, third_argument_type a3 ){ + return ( object.*member )( a2, a3 ); +} }; -template +template class ConstMember2 { public: - typedef const Object& first_argument_type; - typedef A2 second_argument_type; - typedef A3 third_argument_type; - typedef R result_type; - static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3) - { - return (object.*member)(a2, a3); - } +typedef const Object& first_argument_type; +typedef A2 second_argument_type; +typedef A3 third_argument_type; +typedef R result_type; +static result_type call( first_argument_type object, second_argument_type a2, third_argument_type a3 ){ + return ( object.*member )( a2, a3 ); +} }; -template +template class Member3 { public: - typedef Object& first_argument_type; - typedef A2 second_argument_type; - typedef A3 third_argument_type; - typedef A4 fourth_argument_type; - typedef R result_type; - static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) - { - return (object.*member)(a2, a3, a4); - } +typedef Object& first_argument_type; +typedef A2 second_argument_type; +typedef A3 third_argument_type; +typedef A4 fourth_argument_type; +typedef R result_type; +static result_type call( first_argument_type object, second_argument_type a2, third_argument_type a3, fourth_argument_type a4 ){ + return ( object.*member )( a2, a3, a4 ); +} }; -template +template class ConstMember3 { public: - typedef const Object& first_argument_type; - typedef A2 second_argument_type; - typedef A3 third_argument_type; - typedef A4 fourth_argument_type; - typedef R result_type; - static result_type call(first_argument_type object, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) - { - return (object.*member)(a2, a3, a4); - } +typedef const Object& first_argument_type; +typedef A2 second_argument_type; +typedef A3 third_argument_type; +typedef A4 fourth_argument_type; +typedef R result_type; +static result_type call( first_argument_type object, second_argument_type a2, third_argument_type a3, fourth_argument_type a4 ){ + return ( object.*member )( a2, a3, a4 ); +} }; -template +template class Function0 { public: - typedef R result_type; - static result_type call() - { - return (func)(); - } +typedef R result_type; +static result_type call(){ + return (func)( ); +} }; -template +template class Function1 { public: - typedef A1 first_argument_type; - typedef R result_type; - static result_type call(first_argument_type a1) - { - return (func)(a1); - } +typedef A1 first_argument_type; +typedef R result_type; +static result_type call( first_argument_type a1 ){ + return (func)( a1 ); +} }; -template +template class Function2 { public: - typedef A1 first_argument_type; - typedef A2 second_argument_type; - typedef R result_type; - static result_type call(first_argument_type a1, second_argument_type a2) - { - return (func)(a1, a2); - } +typedef A1 first_argument_type; +typedef A2 second_argument_type; +typedef R result_type; +static result_type call( first_argument_type a1, second_argument_type a2 ){ + return (func)( a1, a2 ); +} }; -template +template class Function3 { public: - typedef A1 first_argument_type; - typedef A2 second_argument_type; - typedef A3 third_argument_type; - typedef R result_type; - static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3) - { - return (func)(a1, a2, a3); - } +typedef A1 first_argument_type; +typedef A2 second_argument_type; +typedef A3 third_argument_type; +typedef R result_type; +static result_type call( first_argument_type a1, second_argument_type a2, third_argument_type a3 ){ + return (func)( a1, a2, a3 ); +} }; -template +template class Function4 { public: - typedef A1 first_argument_type; - typedef A2 second_argument_type; - typedef A3 third_argument_type; - typedef A4 fourth_argument_type; - typedef R result_type; - static result_type call(first_argument_type a1, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) - { - return (func)(a1, a2, a3, a4); - } +typedef A1 first_argument_type; +typedef A2 second_argument_type; +typedef A3 third_argument_type; +typedef A4 fourth_argument_type; +typedef R result_type; +static result_type call( first_argument_type a1, second_argument_type a2, third_argument_type a3, fourth_argument_type a4 ){ + return (func)( a1, a2, a3, a4 ); +} }; -template +template class Caller0To1 { public: - typedef FirstArgument first_argument_type; - typedef typename Caller::result_type result_type; - static result_type call(first_argument_type) - { - return Caller::call(); - } +typedef FirstArgument first_argument_type; +typedef typename Caller::result_type result_type; +static result_type call( first_argument_type ){ + return Caller::call(); +} }; -template +template class Caller1To2 { public: - typedef FirstArgument first_argument_type; - typedef typename Caller::first_argument_type second_argument_type; - typedef typename Caller::result_type result_type; - static result_type call(first_argument_type, second_argument_type a2) - { - return Caller::call(a2); - } +typedef FirstArgument first_argument_type; +typedef typename Caller::first_argument_type second_argument_type; +typedef typename Caller::result_type result_type; +static result_type call( first_argument_type, second_argument_type a2 ){ + return Caller::call( a2 ); +} }; -template +template class Caller2To3 { public: - typedef FirstArgument first_argument_type; - typedef typename Caller::first_argument_type second_argument_type; - typedef typename Caller::second_argument_type third_argument_type; - typedef typename Caller::result_type result_type; - static result_type call(first_argument_type, second_argument_type a2, third_argument_type a3) - { - return Caller::call(a2, a3); - } +typedef FirstArgument first_argument_type; +typedef typename Caller::first_argument_type second_argument_type; +typedef typename Caller::second_argument_type third_argument_type; +typedef typename Caller::result_type result_type; +static result_type call( first_argument_type, second_argument_type a2, third_argument_type a3 ){ + return Caller::call( a2, a3 ); +} }; -template +template class Caller3To4 { public: - typedef FirstArgument first_argument_type; - typedef typename Caller::first_argument_type second_argument_type; - typedef typename Caller::second_argument_type third_argument_type; - typedef typename Caller::third_argument_type fourth_argument_type; - typedef typename Caller::result_type result_type; - static result_type call(first_argument_type, second_argument_type a2, third_argument_type a3, fourth_argument_type a4) - { - return Caller::call(a2, a3, a4); - } +typedef FirstArgument first_argument_type; +typedef typename Caller::first_argument_type second_argument_type; +typedef typename Caller::second_argument_type third_argument_type; +typedef typename Caller::third_argument_type fourth_argument_type; +typedef typename Caller::result_type result_type; +static result_type call( first_argument_type, second_argument_type a2, third_argument_type a3, fourth_argument_type a4 ){ + return Caller::call( a2, a3, a4 ); +} }; template class FunctorInvoke { public: - typedef typename Functor::result_type result_type; - inline result_type operator()(Functor functor) - { - return functor(); - } +typedef typename Functor::result_type result_type; +inline result_type operator()( Functor functor ){ + return functor(); +} }; template class Functor1Invoke { - typename Functor::first_argument_type a1; +typename Functor::first_argument_type a1; public: - typedef typename Functor::first_argument_type first_argument_type; - typedef typename Functor::result_type result_type; - Functor1Invoke(first_argument_type a1) : a1(a1) - { - } - inline result_type operator()(Functor functor) - { - return functor(a1); - } +typedef typename Functor::first_argument_type first_argument_type; +typedef typename Functor::result_type result_type; +Functor1Invoke( first_argument_type a1 ) : a1( a1 ){ +} +inline result_type operator()( Functor functor ){ + return functor( a1 ); +} }; template class Functor2Invoke { - typename Functor::first_argument_type a1; - typename Functor::second_argument_type a2; +typename Functor::first_argument_type a1; +typename Functor::second_argument_type a2; public: - typedef typename Functor::first_argument_type first_argument_type; - typedef typename Functor::second_argument_type second_argument_type; - typedef typename Functor::result_type result_type; - Functor2Invoke(first_argument_type a1, second_argument_type a2) - : a1(a1), a2(a2) - { - } - inline result_type operator()(Functor functor) - { - return functor(a1, a2); - } +typedef typename Functor::first_argument_type first_argument_type; +typedef typename Functor::second_argument_type second_argument_type; +typedef typename Functor::result_type result_type; +Functor2Invoke( first_argument_type a1, second_argument_type a2 ) + : a1( a1 ), a2( a2 ){ +} +inline result_type operator()( Functor functor ){ + return functor( a1, a2 ); +} }; template class Functor3Invoke { - typename Functor::first_argument_type a1; - typename Functor::second_argument_type a2; - typename Functor::third_argument_type a3; +typename Functor::first_argument_type a1; +typename Functor::second_argument_type a2; +typename Functor::third_argument_type a3; public: - typedef typename Functor::first_argument_type first_argument_type; - typedef typename Functor::second_argument_type second_argument_type; - typedef typename Functor::third_argument_type third_argument_type; - typedef typename Functor::result_type result_type; - Functor3Invoke(first_argument_type a1, second_argument_type a2, third_argument_type a3) - : a1(a1), a2(a2), a3(a3) - { - } - inline result_type operator()(Functor functor) - { - return functor(a1, a2, a3); - } +typedef typename Functor::first_argument_type first_argument_type; +typedef typename Functor::second_argument_type second_argument_type; +typedef typename Functor::third_argument_type third_argument_type; +typedef typename Functor::result_type result_type; +Functor3Invoke( first_argument_type a1, second_argument_type a2, third_argument_type a3 ) + : a1( a1 ), a2( a2 ), a3( a3 ){ +} +inline result_type operator()( Functor functor ){ + return functor( a1, a2, a3 ); +} }; -template +template class TypeEqual { - template - class Match - { - public: - typedef False type; - }; - template<> - class Match - { - public: - typedef True type; - }; public: - typedef typename Match::type type; +typedef False type; +}; +template +class TypeEqual +{ +public: +typedef True type; };