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_BINARY_FUNCTION_HPP
00008 #define INSTIGATE_STL_BINARY_FUNCTION_HPP
00009
00058
00059 #include "concept.hpp"
00060
00061
00062
00063
00064 #include "cassert"
00065
00066
00067 namespace instigate {
00068 namespace stl {
00079 namespace binary_function {
00080 template <typename BF>
00081 struct interface;
00082 template <typename A1, typename A2, typename R>
00083 struct interface<R (*) (A1, A2)>;
00084 template <typename A1, typename A2, typename R>
00085 struct interface<R (A1::*) (A2)>;
00086 template <typename A1, typename A2, typename R>
00087 struct interface<R (A1::*) (A2) const>;
00088 template <typename T>
00089 struct requirements;
00090 }
00091 }
00092 }
00093
00130 template <typename BF>
00131 struct instigate::stl::binary_function::interface
00132 : instigate::generic::assignable::interface<BF>
00133 {
00135 typedef typename BF::first_argument_type first_argument_type;
00136
00138 typedef typename BF::second_argument_type second_argument_type;
00139
00141 typedef typename BF::result_type result_type;
00142
00155 static result_type invoke(const BF& f, first_argument_type a1,
00156 second_argument_type a2)
00157 {
00158 return f(a1, a2);
00159 }
00160 };
00161
00167 template <typename A1, typename A2, typename R>
00168 struct instigate::stl::binary_function::interface<R (*) (A1, A2)>
00169 : instigate::generic::assignable::interface<R (*) (A1, A2)>
00170 {
00172 typedef A1 first_argument_type;
00173
00175 typedef A2 second_argument_type;
00176
00178 typedef R result_type;
00179
00188 static result_type invoke(result_type (*f)(
00189 first_argument_type,
00190 second_argument_type),
00191 first_argument_type a1,
00192 second_argument_type a2)
00193 {
00194 return f(a1, a2);
00195 }
00196 };
00197
00202 template <typename A1, typename A2, typename R>
00203 struct instigate::stl::binary_function::interface<R (A1::*) (A2)>
00204 : instigate::generic::assignable::interface<R (A1::*) (A2)>
00205 {
00207 typedef A1* first_argument_type;
00208
00210 typedef A2 second_argument_type;
00211
00213 typedef R result_type;
00214
00223 static result_type invoke(R (A1::*f)(A2), A1* a1, A2 a2)
00224 {
00225 assert(0 != a1);
00226 return (a1->*f)(a2);
00227 }
00228 };
00229
00234 template <typename A1, typename A2, typename R>
00235 struct instigate::stl::binary_function::interface <R (A1::*) (A2) const>:
00236 instigate::generic::assignable::interface<R (A1::*) (A2) const>
00237 {
00239 typedef const A1* first_argument_type;
00240
00242 typedef A2 second_argument_type;
00243
00245 typedef R result_type;
00246
00255 static result_type invoke(R (A1::*f)(A2) const, const A1* a1, A2 a2)
00256 {
00257 assert(0 != a1);
00258 return (a1->*f)(a2);
00259 }
00260 };
00261
00269 template <typename T>
00270 struct instigate::stl::binary_function::requirements:
00271 instigate::generic::assignable::requirements<T>
00272 {
00279 static void require_first_argument_type()
00280 {
00281 typedef typename instigate::stl::binary_function
00282 ::interface<T>::first_argument_type f;
00283 }
00284
00291 static void require_second_argument_type()
00292 {
00293 typedef typename instigate::stl::binary_function
00294 ::interface<T>::second_argument_type S;
00295 }
00296
00303 static void require_result_type()
00304 {
00305 typedef typename instigate::stl::binary_function::
00306 interface<T>::result_type R;
00307 }
00308
00314 static void require_method_invoke()
00315 {
00316 (void)instigate::stl::binary_function::interface<T>::invoke;
00317 }
00318
00324 static typename instigate::stl::binary_function::interface<T>::
00325 result_type helper(const T& f,
00326 typename instigate::stl::binary_function::
00327 interface<T>::first_argument_type a,
00328 typename instigate::stl::binary_function::
00329 interface<T>::second_argument_type b)
00330 {
00331 return instigate::stl::binary_function::interface<T>::
00332 invoke(f, a, b);
00333 }
00334
00339 static void check_signature_of_the_invoke()
00340 {
00341 (void)&helper;
00342 }
00343
00351 requirements()
00352 {
00353 (void)require_first_argument_type;
00354 (void)require_second_argument_type;
00355 (void)require_result_type;
00356 (void)require_method_invoke;
00357 (void)check_signature_of_the_invoke;
00358 }
00359 };
00360
00361
00362
00363 #endif // INSTIGATE_STL_BINARY_FUNCTION_HPP