📄 functionals.hpp
字号:
public:
/// Default constructor
selector2nd()
: m_f()
{}
/// Constructs from the given function class, which it will then apply
/// via operator ()()
ss_explicit_k selector2nd(F f)
: m_f(f)
{}
/// Function call operator, which applies the parameterising function class
/// to the \c second part of the pair \c t
///
/// \param t An instance of a \c pair like type, to whose \c second member will be applied the function F
// Regrettably, the current implementation only provides an instantiation
// returning void
#ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
template <ss_typename_param_k T>
#endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
result_type operator ()(T &t) const
{
return m_f(t.second);
}
// Members
private:
F m_f;
};
#endif /* 0 */
// struct select_1st
/** \brief Selects the <b><code>first</code></b> member of an instance and applies the
* parameterising functional to it. This functional selects the \c first member
* of an instance (obviously this is usually the \c std::pair type), and
* applies the parameterising functional to it.
*
* \ingroup group__library__functional
*
* \param F The parameterising functional
*
* For example, if you have a std::map and wish to write out the keys
* with a dump_key functional, you could achieve this with the following:
*
* <code>std::for_each(m.begin(), m.end(), stlsoft::select_1st<dump_key>());</code>
*
* \deprecated
*/
template< ss_typename_param_k F
#ifndef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
, ss_typename_param_k T
#endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
>
// [[synesis:class:unary-functor: select_1st]]
struct select_1st
: public stlsoft_ns_qual_std(unary_function)< ss_typename_type_k F::argument_type
, ss_typename_type_k F::result_type>
{
public:
/// Default constructor
select_1st()
: m_f()
{}
/// Constructs from the given function class, which it will then apply
/// via operator ()()
ss_explicit_k select_1st(F f)
: m_f(f)
{}
/// Function call operator, which applies the parameterising function class
/// to the \c first part of the pair \c t
///
/// \param t An instance of a \c pair like type, to whose \c first member will be applied the function F
///
/// \note Regrettably, the current implementation only provides an instantiation
/// returning void
#ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
template <ss_typename_param_k T>
#endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
void operator ()(T &t)
{
m_f(t.first);
}
// Members
private:
F m_f;
};
#ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
template< ss_typename_param_k F
>
inline select_1st<F> make_1st_selector(F f)
{
return select_1st<F>(f);
}
#else /* ? STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
#endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
// struct select_2nd
//
/** \brief Selects the <b><code>second</code></b> member of an instance and
* applies the parameterising functional to it.
*
* \ingroup group__library__functional
*
* \param F The parameterising functional
*
* This functional selects the "second" member of an instance (obviously
* this is usually the std::pair type), and applies the parameterising
* functional to it.
*
* For example, if you have a std::map and wish to write out the values
* with a dump_value functional, you could achieve this with the following:
*
* <code>std::for_each(m.begin(), m.end(), stlsoft::select_2nd<dump_value>());</code>
*
* \deprecated
*/
template< ss_typename_param_k F
#ifndef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
, ss_typename_param_k T
#endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
>
// [[synesis:class:unary-functor: select_2nd]]
struct select_2nd
: public stlsoft_ns_qual_std(unary_function)<ss_typename_type_k F::argument_type, ss_typename_type_k F::result_type>
{
public:
/// Default constructor
select_2nd()
: m_f()
{}
/// Constructs from the given function class, which it will then apply
/// via operator ()()
ss_explicit_k select_2nd(F f)
: m_f(f)
{}
/// Function call operator, which applies the parameterising function class
/// to the \c second part of the pair \c t
///
/// \param t An instance of a \c pair like type, to whose \c second member will be applied the function F
// Regrettably, the current implementation only provides an instantiation
// returning void
#ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
template <ss_typename_param_k T>
#endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
void operator ()(T &t)
{
m_f(t.second);
}
// Members
private:
F m_f;
};
// struct select_both
//
/** \brief This functional selects both the \c first and \c second members of an instance
* (obviously this is usually the std::pair type), and applies the respective
* parameterising functionals to them.
*
* \ingroup group__library__functional
*
* \param F1 The functional to apply to the <b><code>first</code></b> part of the elements
* \param F2 The functional to apply to the <b><code>second</code></b> part of the elements
*
* For example, if you have a std::map and wish to write out the keys with the
* dump_key functional and the values with the dump_value functional, you could
* achieve this with the following:
*
* <code>std::for_each(m.begin(), m.end(), stlsoft::select_both<dump_key, dump_value>());</code>
*
* \deprecated
*/
template< ss_typename_param_k F1
, ss_typename_param_k F2
#ifndef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
, ss_typename_param_k T
#endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
>
// [[synesis:class:unary-functor: select_both]]
struct select_both
#ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
: public stlsoft_ns_qual_std(unary_function)<void, void>
#else
: public stlsoft_ns_qual_std(unary_function)<T &, void>
#endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
{
public:
/// Default constructor
select_both()
: m_f1()
, m_f2()
{}
/// Constructs from the given function classes, which it will then apply
/// via operator ()()
ss_explicit_k select_both(F1 f1, F2 f2)
: m_f1(f1)
, m_f2(f2)
{}
/// Function call operator, which applies the parameterising function classes
/// to the \c first and \c second parts of the pair \c t
///
/// \param t An instance of a \c pair like type, to whose \c first and \c second members will be applied the functions F1 and F2
// Regrettably, the current implementation only provides an instantiation
// returning void
#ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
template <ss_typename_param_k T>
#endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
void operator ()(T &t)
{
m_f1(t.first);
m_f2(t.second);
}
// Members
private:
F1 m_f1;
F2 m_f2;
};
/* ////////////////////////////////////////////////////////////////////// */
#ifndef _STLSOFT_NO_NAMESPACE
} /* namespace stlsoft */
#endif /* _STLSOFT_NO_NAMESPACE */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* !STLSOFT_INCL_STLSOFT_OBSOLETE_HPP_FUNCTIONALS */
/* ////////////////////////////////////////////////////////////////////// */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -