00001
00002 #ifndef _INSTIGATE_OPEN_SOURCE_INTERNAL_HEADER_IN_CONCEPT
00003 #error This is an internal header file used to implement Instigate STL.\
00004 It should never be included directly by a program.
00005 #endif
00006
00007 #ifndef INSTIGATE_STL_UNARY_FUNCTION_HPP
00008 #define INSTIGATE_STL_UNARY_FUNCTION_HPP
00009
00058
00059 #include "functor.hpp"
00060
00061
00062
00063
00064
00065
00066 namespace instigate {
00067 namespace stl {
00101 namespace unary_function {
00102 struct tag;
00103 template <typename UF>
00104 struct interface;
00105 template <typename A, typename R>
00106 struct interface<R (*) (A)>;
00107 template <typename A, typename R>
00108 struct interface<R (A::*) ()>;
00109 template <typename A, typename R>
00110 struct interface<R (A::*) () const>;
00111 template <typename UF>
00112 struct requirements;
00113 }
00114 }
00115 }
00116
00123 struct instigate::stl::unary_function::tag
00124 {
00125 };
00126
00130 template <typename UF>
00131 struct instigate::stl::unary_function::interface
00132 : instigate::generic::assignable::interface<UF>
00133 {
00135 typedef typename instigate::stl::functor::interface<UF>::argument_type
00136 argument_type;
00137
00139 typedef typename instigate::stl::functor::interface<UF>::result_type
00140 result_type;
00141
00149 static result_type invoke(const UF& f, argument_type a)
00150 {
00151 return f(a);
00152 }
00153
00154 };
00155
00161 template <typename A, typename R>
00162 struct instigate::stl::unary_function::interface<R (*) (A)>
00163 : instigate::generic::assignable::interface<R (*) (A)>
00164 {
00166 typedef A argument_type;
00167
00169 typedef R result_type;
00170
00178 static result_type invoke(R (*f)(A), A a)
00179 {
00180 return f(a);
00181 }
00182 };
00183
00188 template <typename A, typename R>
00189 struct instigate::stl::unary_function::interface <R (A::*) ()>
00190 : instigate::generic::assignable::interface<R (A::*) ()>
00191 {
00193 typedef A* argument_type;
00194
00196 typedef R result_type;
00197
00205 static result_type invoke(R (A::*f)(), A* a)
00206 {
00207 assert(a != 0);
00208 return (a->*f)();
00209 }
00210 };
00211
00216 template <typename A, typename R>
00217 struct instigate::stl::unary_function::interface <R (A::*) () const>
00218 : instigate::generic::assignable::interface<R (A::*) () const>
00219 {
00221 typedef const A* argument_type;
00222
00224 typedef R result_type;
00225
00233 static result_type invoke(R (A::*f)() const, const A* a)
00234 {
00235 assert(a != 0);
00236 return (a->*f)();
00237 }
00238 };
00239
00247 template <typename T>
00248 struct instigate::stl::unary_function::requirements
00249 : instigate::generic::assignable::interface<T>
00250 {
00255 static void require_nested_typename_argument_type()
00256 {
00257 typedef instigate::stl::unary_function::interface<T> I;
00258 typedef typename I::argument_type A;
00259 }
00260
00265 static void require_nested_typename_result_type()
00266 {
00267 typedef instigate::stl::unary_function::interface<T> I;
00268 typedef typename I::result_type R;
00269 }
00270
00275 static void require_method_invoke()
00276 {
00277 typedef instigate::stl::unary_function::interface<T> I;
00278 (void)&I::invoke;
00279 }
00280
00285 typename instigate::stl::unary_function::interface<T>::
00286 result_type static
00287 check_signature_of_the_invoke(T& f,
00288 typename instigate::stl::
00289 unary_function::interface<T>::argument_type a)
00290 {
00291 namespace UF = instigate::stl::unary_function;
00292 return UF::interface<T>::invoke(f, a);
00293 }
00294
00299 requirements()
00300 {
00301 (void)&require_nested_typename_argument_type;
00302 (void)&require_nested_typename_result_type;
00303 (void)&require_method_invoke;
00304 (void)&check_signature_of_the_invoke;
00305 }
00306
00307 };
00308
00309
00310
00311 #endif // INSTIGATE_STL_UNARY_FUNCTION_HPP