summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/tr1/functional_iterate.h
diff options
context:
space:
mode:
authorDoug Gregor <dgregor@gcc.gnu.org>2005-04-01 03:35:59 +0000
committerDoug Gregor <dgregor@gcc.gnu.org>2005-04-01 03:35:59 +0000
commit59cffcf69a5026fc54a38479c93f8ea961db8ecd (patch)
tree6989839fac1800a14041743cde970c5877a70995 /libstdc++-v3/include/tr1/functional_iterate.h
parentc423ee0d3582e8bd7dc16da63365f5954e6afe6e (diff)
downloadgcc-59cffcf69a5026fc54a38479c93f8ea961db8ecd.tar.gz
[multiple changes]
2005-03-31 Chris Jefferson <chris@bubblescope.net> * include/tr1/tuple: Support iteration via tuple_iterate.h. * include/tr1/tuple_iterate.h: Iteration file for tuple. 2005-03-31 Douglas Gregor <doug.gregor@gmail.com> * include/Makefile.am (tr1_headers): Add bind and mu repetition headers and reference_wrapper<> forwarding header. * include/Makefile.in: Regenerate. * include/tr1/bind_iterate.h: Implementation of function call operators for the function object returned from tr1::bind(). * include/tr1/bind_repeat.h: Bind-specific repetition header, akin to include/tr1/repeat.h. * include/tr1/functional (_Mem_fn): Bug fix: declare result member template for use with result_of. (is_bind_expression): New. (is_placeholder): New. (_Placeholder): New. Placeholder type for bind. (_Mu): New. Implementation detail of bind. (_Bind, _Bind_result): New. Function objects returned by bind. (_GLIBCXX_JOIN): New. Required to create bind placeholders. * include/tr1/functional_iterate.h (_Bind, _Bind_result, bind): New. Implementation of tr1::bind. * include/tr1/mu_iterate.h (_Mu): result template and operator() for the _Mu helper to bind. * include/tr1/ref_fwd.h (reference_wrapper): Forward declaration used by tuple header. (ref): Ditto. (cref): Ditto. * include/tr1/repeat.h: Add bind-specific repetition macros. * include/tr1/tuple: Use reference_wrapper forwarding header for initial definitions, then include <tr1/functional> at the end, to make the circular dependencies work. (tie): Support zero-argument tie() function. * testsuite/tr1/3_function_objects/bind/all_bound.cc: New test of bind() functionality with parameters bound. * testsuite/tr1/3_function_objects/bind/nested.cc: New test of nested bind() expressions. * testsuite/tr1/3_function_objects/bind/placeholders.cc: New test of bind() placeholders. * testsuite/tr1/3_function_objects/bind/ref.cc: New test of bind() with arguments bound via reference_wrapper<>. * scripts/gen_includers.pl: Generate the repetitive part of include/tr1/repeat.h. * scripts/gen_bind_includers.pl: Generate the repetitive part of include/tr1/bind_repeat.h. From-SVN: r97361
Diffstat (limited to 'libstdc++-v3/include/tr1/functional_iterate.h')
-rw-r--r--libstdc++-v3/include/tr1/functional_iterate.h98
1 files changed, 96 insertions, 2 deletions
diff --git a/libstdc++-v3/include/tr1/functional_iterate.h b/libstdc++-v3/include/tr1/functional_iterate.h
index 97f4d248794..0a1ccee94e8 100644
--- a/libstdc++-v3/include/tr1/functional_iterate.h
+++ b/libstdc++-v3/include/tr1/functional_iterate.h
@@ -28,7 +28,7 @@
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
-/** @file function_iterate.h
+/** @file functional_iterate.h
* This is an internal header file, included by other library headers.
* You should not attempt to use it directly.
*/
@@ -390,7 +390,101 @@ template<typename _Res, typename _Class _GLIBCXX_COMMA_SHIFTED
};
#endif
-template<typename _Signature, typename _Functor> class _Function_handler;
+#if _GLIBCXX_NUM_ARGS > 0
+namespace placeholders
+{
+namespace
+{
+ _Placeholder<_GLIBCXX_NUM_ARGS> _GLIBCXX_JOIN(_,_GLIBCXX_NUM_ARGS);
+}
+}
+#endif
+
+template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
+class _Bind<_Functor(_GLIBCXX_TEMPLATE_ARGS)>
+ : public _Weak_result_type<_Functor>
+{
+ typedef _Bind __self_type;
+
+ _Functor _M_f;
+ _GLIBCXX_BIND_MEMBERS
+
+ public:
+#if _GLIBCXX_NUM_ARGS == 0
+ explicit
+#endif
+ _Bind(_Functor __f _GLIBCXX_COMMA _GLIBCXX_PARAMS)
+ : _M_f(__f) _GLIBCXX_COMMA _GLIBCXX_BIND_MEMBERS_INIT { }
+
+#define _GLIBCXX_BIND_REPEAT_HEADER <tr1/bind_iterate.h>
+#include <tr1/bind_repeat.h>
+#undef _GLIBCXX_BIND_REPEAT_HEADER
+};
+
+template<typename _Result, typename _Functor
+ _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
+class _Bind_result<_Result, _Functor(_GLIBCXX_TEMPLATE_ARGS)>
+{
+ _Functor _M_f;
+ _GLIBCXX_BIND_MEMBERS
+
+ public:
+ typedef _Result result_type;
+
+#if _GLIBCXX_NUM_ARGS == 0
+ explicit
+#endif
+ _Bind_result(_Functor __f _GLIBCXX_COMMA _GLIBCXX_PARAMS)
+ : _M_f(__f) _GLIBCXX_COMMA _GLIBCXX_BIND_MEMBERS_INIT { }
+
+#define _GLIBCXX_BIND_REPEAT_HEADER <tr1/bind_iterate.h>
+#define _GLIBCXX_BIND_HAS_RESULT_TYPE
+#include <tr1/bind_repeat.h>
+#undef _GLIBCXX_BIND_HAS_RESULT_TYPE
+#undef _GLIBCXX_BIND_REPEAT_HEADER
+};
+
+// Handle member pointers
+template<typename _Tp, typename _Class _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
+inline _Bind<_Mem_fn<_Tp _Class::*>(_GLIBCXX_TEMPLATE_ARGS)>
+bind(_Tp _Class::* __pm _GLIBCXX_COMMA _GLIBCXX_PARAMS)
+{
+ typedef _Bind<_Mem_fn<_Tp _Class::*>(_GLIBCXX_TEMPLATE_ARGS)> __result_type;
+ return __result_type(_Mem_fn<_Tp _Class::*>(__pm)
+ _GLIBCXX_COMMA _GLIBCXX_ARGS);
+}
+
+template<typename _Result, typename _Tp, typename _Class
+ _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
+inline _Bind_result<_Result, _Mem_fn<_Tp _Class::*>(_GLIBCXX_TEMPLATE_ARGS)>
+bind(_Tp _Class::* __pm _GLIBCXX_COMMA _GLIBCXX_PARAMS)
+{
+ typedef _Bind_result<_Result, _Mem_fn<_Tp _Class::*>(_GLIBCXX_TEMPLATE_ARGS)>
+ __result_type;
+ return __result_type(_Mem_fn<_Tp _Class::*>(__pm)
+ _GLIBCXX_COMMA _GLIBCXX_ARGS);
+}
+
+// Handle arbitrary function objects
+template<typename _Functor _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
+inline _Bind<_Functor(_GLIBCXX_TEMPLATE_ARGS)>
+bind(_Functor __f _GLIBCXX_COMMA _GLIBCXX_PARAMS)
+{
+ typedef _Bind<_Functor(_GLIBCXX_TEMPLATE_ARGS)> __result_type;
+ return __result_type(__f _GLIBCXX_COMMA _GLIBCXX_ARGS);
+}
+
+template<typename _Result, typename _Functor
+ _GLIBCXX_COMMA _GLIBCXX_TEMPLATE_PARAMS>
+inline
+typename __enable_if<_Bind_result<_Result, _Functor(_GLIBCXX_TEMPLATE_ARGS)>,
+ !is_member_pointer<_Functor>::value>::__type
+bind(_Functor __f _GLIBCXX_COMMA _GLIBCXX_PARAMS)
+{
+ typedef _Bind_result<_Result, _Functor(_GLIBCXX_TEMPLATE_ARGS)>
+ __result_type;
+ return __result_type(__f _GLIBCXX_COMMA _GLIBCXX_ARGS);
+}
template<typename _Res, typename _Functor _GLIBCXX_COMMA
_GLIBCXX_TEMPLATE_PARAMS>