⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stlsoft_functionals.h

📁 用STL的方式封装了WindowsAPI、COM调用、ACE、ATL、MFC、WTL等多种组件
💻 H
📖 第 1 页 / 共 2 页
字号:
/* /////////////////////////////////////////////////////////////////////////
 * File:        stlsoft_functionals.h (originally MLCpp.h, ::SynesisStd)
 *
 * Purpose:     Basic functionals.
 *
 * Created:     19th January 2002
 * Updated:     18th June 2006
 *
 * Home:        http://stlsoft.org/
 *
 * Copyright (c) 2002-2006, Matthew Wilson and Synesis Software
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
 *   any contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * ////////////////////////////////////////////////////////////////////// */


/// \file stlsoft_functionals.h
///
/// Basic functionals.

#ifndef STLSOFT_INCL_H_STLSOFT_FUNCTIONALS
#define STLSOFT_INCL_H_STLSOFT_FUNCTIONALS

#ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
# define STLSOFT_VER_H_STLSOFT_FUNCTIONALS_MAJOR    2
# define STLSOFT_VER_H_STLSOFT_FUNCTIONALS_MINOR    2
# define STLSOFT_VER_H_STLSOFT_FUNCTIONALS_REVISION 1
# define STLSOFT_VER_H_STLSOFT_FUNCTIONALS_EDIT     39
#endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */

/* /////////////////////////////////////////////////////////////////////////
 * Compatibility
 */

/*
[Incompatibilies-start]
STLSOFT_COMPILER_IS_WATCOM:
[Incompatibilies-end]
 */

/* /////////////////////////////////////////////////////////////////////////
 * Includes
 */

#ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
# include <stlsoft/stlsoft.h>
#endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
#include <functional>           // for std::unary_function

/* /////////////////////////////////////////////////////////////////////////
 * Namespace
 */

#ifndef _STLSOFT_NO_NAMESPACE
namespace stlsoft
{
#endif /* _STLSOFT_NO_NAMESPACE */

/* /////////////////////////////////////////////////////////////////////////
 * Classes
 */

// struct noop_function
//
/// This functional performs no operation at all, and is simply a place-holder

template <ss_typename_param_k T>
// [[synesis:class:unary-functor: noop_function]]
struct noop_function
    : public stlsoft_ns_qual_std(unary_function)<T const &, void>
{
public:
    /// The function call operator, which does nothing
    void operator ()(T const &/* t */) stlsoft_throw_0()
    {}
};


// struct delete_instance
//
/// This functional deletes an object instance, via scalar delete

template <ss_typename_param_k T>
// [[synesis:class:unary-functor: delete_instance]]
struct delete_instance
    : public stlsoft_ns_qual_std(unary_function)<T *, void>
{
public:
    /// The function call operator, which deletes the given instance
    ///
    /// \param pt A pointer to an instance of type T to be deleted
    void operator ()(T *pt) stlsoft_throw_0()
    {
        delete pt;
    }
};


// struct delete_array
//
/// This functional deletes an array of objects, via vector delete

template <ss_typename_param_k T>
// [[synesis:class:unary-functor: delete_array]]
struct delete_array
    : public stlsoft_ns_qual_std(unary_function)<T [], void>
{
public:
    /// The function call operator, which deletes the given array
    ///
    /// \param t A pointer to an array of type T to be deleted
    void operator ()(T t[]) stlsoft_throw_0()
    {
        delete [] t;
    }
};


#if 0
// struct selector1st

/// 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.
///
/// 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:
///
/// &nbsp;&nbsp;<code>std::for_each(m.begin(), m.end(), stlsoft::selector1st<dump_key>());</code>
///
/// \param F The parameterising functional
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: selector1st]]
struct selector1st
    : public stlsoft_ns_qual_std(unary_function)<   ss_typename_type_k F::argument_type
                                                ,   ss_typename_type_k F::result_type
                                                >
{
public:
    typedef ss_typename_type_k F::argument_type argument_type;
    typedef ss_typename_type_k F::result_type   result_type;

public:
    /// Default constructor
    selector1st()
        : m_f()
    {}

    /// Constructs from the given function object, which it will then apply
    /// via operator ()()
    ss_explicit_k selector1st(F f)
        : m_f(f)
    {}

    /// Function call operator, which applies the parameterising function object
    /// 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
    // 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 const &t) const
    {
        return m_f(t.first);
    }

// Members
private:
    F   m_f;
};

#ifdef STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
template<   ss_typename_param_k F
        >
inline selector1st<F> select1st(F f)
{
    return selector1st<F>(f);
}
#else /* ? STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */

#endif // STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT

// struct selector2nd
//
/// \brief Selects the <b><code>second</code></b> member of an instance and
/// applies the parameterising functional to it.
///
/// 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:
///
/// &nbsp;&nbsp;<code>std::for_each(m.begin(), m.end(), stlsoft::selector2nd<dump_value>());</code>
///
/// \param F The parameterising functional

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: selector2nd]]
struct selector2nd
    : public stlsoft_ns_qual_std(unary_function)<   ss_typename_type_k F::argument_type
                                                ,   ss_typename_type_k F::result_type
                                                >

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -