gcc/libstdc++-v3/include/backward/binders.h

174 lines
6.8 KiB
C
Raw Normal View History

// Functor implementations -*- C++ -*-
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING. If not, write to the Free
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
// USA.
// As a special exception, you may use this file as part of a free software
// library without restriction. Specifically, if other files instantiate
// templates or use macros or inline functions from this file, or you compile
// this file and link it with other files to produce an executable, this
// file does not by itself cause the resulting executable to be covered by
// the GNU General Public License. This exception does not however
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996-1998
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/
/** @file backward/binders.h
* This is an internal header file, included by other library headers.
* You should not attempt to use it directly.
*/
#ifndef _GLIBCXX_BINDERS_H
#define _GLIBCXX_BINDERS_H 1
_GLIBCXX_BEGIN_NAMESPACE(std)
// 20.3.6 binders
/** @defgroup binder Binder Classes
* @ingroup functors
*
* Binders turn functions/functors with two arguments into functors with
* a single argument, storing an argument to be applied later. For
* example, a variable @c B of type @c binder1st is constructed from a
* functor @c f and an argument @c x. Later, B's @c operator() is called
* with a single argument @c y. The return value is the value of @c f(x,y).
* @c B can be "called" with various arguments (y1, y2, ...) and will in
* turn call @c f(x,y1), @c f(x,y2), ...
*
* The function @c bind1st is provided to save some typing. It takes the
* function and an argument as parameters, and returns an instance of
* @c binder1st.
*
* The type @c binder2nd and its creator function @c bind2nd do the same
* thing, but the stored argument is passed as the second parameter instead
* of the first, e.g., @c bind2nd(std::minus<float>,1.3) will create a
* functor whose @c operator() accepts a floating-point number, subtracts
* 1.3 from it, and returns the result. (If @c bind1st had been used,
* the functor would perform "1.3 - x" instead.
*
* Creator-wrapper functions like @c bind1st are intended to be used in
* calling algorithms. Their return values will be temporary objects.
* (The goal is to not require you to type names like
* @c std::binder1st<std::plus<int>> for declaring a variable to hold the
* return value from @c bind1st(std::plus<int>,5).
*
* These become more useful when combined with the composition functions.
*
* @{
*/
/// One of the @link binder binder functors@endlink.
template<typename _Operation>
class binder1st
: public unary_function<typename _Operation::second_argument_type,
typename _Operation::result_type>
{
protected:
_Operation op;
typename _Operation::first_argument_type value;
public:
binder1st(const _Operation& __x,
const typename _Operation::first_argument_type& __y)
: op(__x), value(__y) { }
typename _Operation::result_type
operator()(const typename _Operation::second_argument_type& __x) const
{ return op(value, __x); }
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 109. Missing binders for non-const sequence elements
typename _Operation::result_type
operator()(typename _Operation::second_argument_type& __x) const
{ return op(value, __x); }
documentation.html: First pass at unified table of contents. 2007-11-13 Benjamin Kosnik <bkoz@redhat.com> * docs/html/documentation.html: First pass at unified table of contents. * docs/html/abi.html: Move... * docs/html/17_intro/abi.html: ...here. * docs/html/17_intro/porting-howto.html: Update, edit, put resulting pieces into... * docs/html/17_intro/api.html: New. * docs/html/17_intro/c++0x_status.html: New. * docs/html/17_intro/CHECKLIST: Move to... * docs/html/17_intro/c++1998_status.html: ...here. * docs/html/ext/tr1.html: Move ... * docs/html/17_intro/tr1_status.html: ...here. * docs/html/debug_mode.html: Move... * docs/html/ext/debug_mode.html: ...here. * docs/html/parallel_mode.html: Move... * docs/html/ext/parallel_mode.html: ...here * docs/html/17_intro/BUGS: Remove. * docs/html/17_intro/concept_check.diff: Remove. * docs/html/17_intro/HEADER_POLICY: Remove. * docs/html/17_intro/headers_cc.txt: Remove. * docs/html/17_intro/PROBLEMS: Remove. * docs/html/17_intro/RELEASE-NOTES: Remove. * docs/html/explanations.html: Remove. * docs/html/makedoc.awk: Remove. * docs/html/faq/index.txt: Remove. HTML only. * /docs/html/Makefile: Remove. * docs/html/17_intro/configury.html: Editing, updating, consistency check with doxygen conventions. Change libstdc++-v3 to libstdc++. * docs/html/17_intro/howto.html: Same. * docs/html/17_intro/license.html: Same. * docs/html/17_intro/porting.html: Same. * docs/html/18_support/howto.html: Same. * docs/html/19_diagnostics/howto.html: Same. * docs/html/20_util/allocator.html: Same. * docs/html/20_util/howto.html: Same. * docs/html/21_strings/howto.html: Same. * docs/html/22_locale/codecvt.html: Same. * docs/html/22_locale/ctype.html: Same. * docs/html/22_locale/howto.html: Same. * docs/html/22_locale/messages.html: Same. * docs/html/23_containers/howto.html: Same. * docs/html/24_iterators/howto.html: Same. * docs/html/25_algorithms/howto.html: Same. * docs/html/26_numerics/howto.html: Same. * docs/html/27_io/howto.html: Same. * docs/html/configopts.html: Same. * docs/html/debug.html: Same. * docs/html/ext/ballocator_doc.html: Same. * docs/html/ext/howto.html: Same. * docs/html/ext/mt_allocator.html: Same. * docs/html/ext/sgiexts.html: Same. * docs/html/faq/index.html: Same. * docs/html/install.html: Same. * docs/html/test.html: Same. * include/bits/c++config: Change _GLIBCXX_DEPRECATED to _GLIBCXX_DEPRECATED_ATTR, _GLIBCXX_VISIBILITY to _GLIBCXX_VISIBILITY_ATTR. * include/backward/auto_ptr.h: Same. * include/backward/binders.h: Same. * include/bits/stl_function.h: Same. * include/std/memory: Same. * include/std/streambuf: Same. * include/tr1_impl/boost_shared_ptr.h: Same. * src/globals_io.cc: Same. * src/ios_init.cc: Same. From-SVN: r130150
2007-11-13 18:43:57 +01:00
} _GLIBCXX_DEPRECATED_ATTR;
/// One of the @link binder binder functors@endlink.
template<typename _Operation, typename _Tp>
inline binder1st<_Operation>
bind1st(const _Operation& __fn, const _Tp& __x)
{
typedef typename _Operation::first_argument_type _Arg1_type;
return binder1st<_Operation>(__fn, _Arg1_type(__x));
}
/// One of the @link binder binder functors@endlink.
template<typename _Operation>
class binder2nd
: public unary_function<typename _Operation::first_argument_type,
typename _Operation::result_type>
{
protected:
_Operation op;
typename _Operation::second_argument_type value;
public:
binder2nd(const _Operation& __x,
const typename _Operation::second_argument_type& __y)
: op(__x), value(__y) { }
typename _Operation::result_type
operator()(const typename _Operation::first_argument_type& __x) const
{ return op(__x, value); }
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 109. Missing binders for non-const sequence elements
typename _Operation::result_type
operator()(typename _Operation::first_argument_type& __x) const
{ return op(__x, value); }
documentation.html: First pass at unified table of contents. 2007-11-13 Benjamin Kosnik <bkoz@redhat.com> * docs/html/documentation.html: First pass at unified table of contents. * docs/html/abi.html: Move... * docs/html/17_intro/abi.html: ...here. * docs/html/17_intro/porting-howto.html: Update, edit, put resulting pieces into... * docs/html/17_intro/api.html: New. * docs/html/17_intro/c++0x_status.html: New. * docs/html/17_intro/CHECKLIST: Move to... * docs/html/17_intro/c++1998_status.html: ...here. * docs/html/ext/tr1.html: Move ... * docs/html/17_intro/tr1_status.html: ...here. * docs/html/debug_mode.html: Move... * docs/html/ext/debug_mode.html: ...here. * docs/html/parallel_mode.html: Move... * docs/html/ext/parallel_mode.html: ...here * docs/html/17_intro/BUGS: Remove. * docs/html/17_intro/concept_check.diff: Remove. * docs/html/17_intro/HEADER_POLICY: Remove. * docs/html/17_intro/headers_cc.txt: Remove. * docs/html/17_intro/PROBLEMS: Remove. * docs/html/17_intro/RELEASE-NOTES: Remove. * docs/html/explanations.html: Remove. * docs/html/makedoc.awk: Remove. * docs/html/faq/index.txt: Remove. HTML only. * /docs/html/Makefile: Remove. * docs/html/17_intro/configury.html: Editing, updating, consistency check with doxygen conventions. Change libstdc++-v3 to libstdc++. * docs/html/17_intro/howto.html: Same. * docs/html/17_intro/license.html: Same. * docs/html/17_intro/porting.html: Same. * docs/html/18_support/howto.html: Same. * docs/html/19_diagnostics/howto.html: Same. * docs/html/20_util/allocator.html: Same. * docs/html/20_util/howto.html: Same. * docs/html/21_strings/howto.html: Same. * docs/html/22_locale/codecvt.html: Same. * docs/html/22_locale/ctype.html: Same. * docs/html/22_locale/howto.html: Same. * docs/html/22_locale/messages.html: Same. * docs/html/23_containers/howto.html: Same. * docs/html/24_iterators/howto.html: Same. * docs/html/25_algorithms/howto.html: Same. * docs/html/26_numerics/howto.html: Same. * docs/html/27_io/howto.html: Same. * docs/html/configopts.html: Same. * docs/html/debug.html: Same. * docs/html/ext/ballocator_doc.html: Same. * docs/html/ext/howto.html: Same. * docs/html/ext/mt_allocator.html: Same. * docs/html/ext/sgiexts.html: Same. * docs/html/faq/index.html: Same. * docs/html/install.html: Same. * docs/html/test.html: Same. * include/bits/c++config: Change _GLIBCXX_DEPRECATED to _GLIBCXX_DEPRECATED_ATTR, _GLIBCXX_VISIBILITY to _GLIBCXX_VISIBILITY_ATTR. * include/backward/auto_ptr.h: Same. * include/backward/binders.h: Same. * include/bits/stl_function.h: Same. * include/std/memory: Same. * include/std/streambuf: Same. * include/tr1_impl/boost_shared_ptr.h: Same. * src/globals_io.cc: Same. * src/ios_init.cc: Same. From-SVN: r130150
2007-11-13 18:43:57 +01:00
} _GLIBCXX_DEPRECATED_ATTR;
/// One of the @link binder binder functors@endlink.
template<typename _Operation, typename _Tp>
inline binder2nd<_Operation>
bind2nd(const _Operation& __fn, const _Tp& __x)
{
typedef typename _Operation::second_argument_type _Arg2_type;
return binder2nd<_Operation>(__fn, _Arg2_type(__x));
}
/** @} */
_GLIBCXX_END_NAMESPACE
#endif /* _GLIBCXX_BINDERS_H */