STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - Template Software for the Active Template Library COMSTL - The Standard Template Library meets the Component Object Model .netSTL - Standard Template Library meets the Microsoft.NET Common Language Runtime InetSTL - The Standard Template Library meets WinInet MFCSTL - Template Software for the Microsoft Foundation Classes UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

stlsoft_functionals.h

Go to the documentation of this file.
00001 /* 
00002  * File:        stlsoft_functionals.h (originally MLCpp.h, ::SynesisStd)
00003  *
00004  * Purpose:     Basic functionals.
00005  *
00006  * Created:     19th January 2002
00007  * Updated:     11th September 2004
00008  *
00009  * Home:        http://stlsoft.org/
00010  *
00011  * Copyright (c) 2002-2004, Matthew Wilson and Synesis Software
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without
00015  * modification, are permitted provided that the following conditions are met:
00016  *
00017  * - Redistributions of source code must retain the above copyright notice, this
00018  *   list of conditions and the following disclaimer.
00019  * - Redistributions in binary form must reproduce the above copyright notice,
00020  *   this list of conditions and the following disclaimer in the documentation
00021  *   and/or other materials provided with the distribution.
00022  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00023  *   any contributors may be used to endorse or promote products derived from
00024  *   this software without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * 
00039 
00040 
00044 
00045 #ifndef STLSOFT_INCL_H_STLSOFT_FUNCTIONALS
00046 #define STLSOFT_INCL_H_STLSOFT_FUNCTIONALS
00047 
00048 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00049 # define STLSOFT_VER_H_STLSOFT_FUNCTIONALS_MAJOR    2
00050 # define STLSOFT_VER_H_STLSOFT_FUNCTIONALS_MINOR    0
00051 # define STLSOFT_VER_H_STLSOFT_FUNCTIONALS_REVISION 1
00052 # define STLSOFT_VER_H_STLSOFT_FUNCTIONALS_EDIT     27
00053 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00054 
00055 /* 
00056  * Includes
00057  */
00058 
00059 #ifndef STLSOFT_INCL_H_STLSOFT
00060 # include "stlsoft.h"   // Include the STLSoft root header
00061 #endif /* !STLSOFT_INCL_H_STLSOFT */
00062 #include <functional>   // std::unary_function
00063 
00064 /* 
00065  * Namespace
00066  */
00067 
00068 #ifndef _STLSOFT_NO_NAMESPACE
00069 namespace stlsoft
00070 {
00071 #endif /* _STLSOFT_NO_NAMESPACE */
00072 
00073 /* 
00074  * Classes
00075  */
00076 
00077 // struct noop_function
00078 //
00080 
00081 template <ss_typename_param_k T>
00082 struct noop_function
00083     : public stlsoft_ns_qual_std(unary_function)<T const &, void>
00084 {
00085 public:
00087     void operator ()(T const &/* t */) stlsoft_throw_0()
00088     {}
00089 };
00090 
00091 
00092 // struct delete_instance
00093 //
00095 
00096 template <ss_typename_param_k T>
00097 struct delete_instance
00098     : public stlsoft_ns_qual_std(unary_function)<T *, void>
00099 {
00100 public:
00104     void operator ()(T *pt) stlsoft_throw_0()
00105     {
00106         delete pt;
00107     }
00108 };
00109 
00110 
00111 // struct delete_array
00112 //
00114 
00115 template <ss_typename_param_k T>
00116 struct delete_array
00117     : public stlsoft_ns_qual_std(unary_function)<T [], void>
00118 {
00119 public:
00123     void operator ()(T t[]) stlsoft_throw_0()
00124     {
00125         delete [] t;
00126     }
00127 };
00128 
00129 
00130 // struct select_1st
00131 
00143 template<   ss_typename_param_k F
00144 #ifndef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00145         ,   ss_typename_param_k T
00146 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00147         >
00148 struct select_1st
00149     : public stlsoft_ns_qual_std(unary_function)<   ss_typename_type_k F::argument_type
00150                                                 ,   ss_typename_type_k F::result_type>
00151 {
00152 public:
00154     select_1st()
00155         : m_f()
00156     {}
00157 
00160     ss_explicit_k select_1st(F f)
00161         : m_f(f)
00162     {}
00163 
00168     // Regrettably, the current implementation only provides an instantiation
00169     // returning void
00170 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00171     template <ss_typename_param_k T>
00172 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00173     void operator ()(T &t)
00174     {
00175         m_f(t.first);
00176     }
00177 
00178 // Members
00179 private:
00180     F   m_f;
00181 };
00182 
00183 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00184 template<   ss_typename_param_k F
00185         >
00186 inline select_1st<F> make_1st_selector(F f)
00187 {
00188     return select_1st<F>(f);
00189 }
00190 #else /* ? __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT */
00191 
00192 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00193 
00194 // struct select_2nd
00195 //
00209 
00210 template<   ss_typename_param_k F
00211 #ifndef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00212         ,   ss_typename_param_k T
00213 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00214         >
00215 struct select_2nd
00216     : public stlsoft_ns_qual_std(unary_function)<ss_typename_type_k F::argument_type, ss_typename_type_k F::result_type>
00217 {
00218 public:
00220     select_2nd()
00221         : m_f()
00222     {}
00223 
00226     ss_explicit_k select_2nd(F f)
00227         : m_f(f)
00228     {}
00229 
00234     // Regrettably, the current implementation only provides an instantiation
00235     // returning void
00236 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00237     template <ss_typename_param_k T>
00238 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00239     void operator ()(T &t)
00240     {
00241         m_f(t.second);
00242     }
00243 
00244 // Members
00245 private:
00246     F   m_f;
00247 };
00248 
00249 
00250 // struct select_both
00251 //
00264 
00265 template<   ss_typename_param_k F1
00266         ,   ss_typename_param_k F2
00267 #ifndef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00268         ,   ss_typename_param_k T
00269 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00270         >
00271 struct select_both
00272 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00273     : public stlsoft_ns_qual_std(unary_function)<void, void>
00274 #else
00275     : public stlsoft_ns_qual_std(unary_function)<T &, void>
00276 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00277 {
00278 public:
00280     select_both()
00281         : m_f1()
00282         , m_f2()
00283     {}
00284 
00287     ss_explicit_k select_both(F1 f1, F2 f2)
00288         : m_f1(f1)
00289         , m_f2(f2)
00290     {}
00291 
00296     // Regrettably, the current implementation only provides an instantiation
00297     // returning void
00298 #ifdef __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00299     template <ss_typename_param_k T>
00300 #endif // __STLSOFT_CF_MEMBER_TEMPLATE_FUNCTION_SUPPORT
00301     void operator ()(T &t)
00302     {
00303         m_f1(t.first);
00304         m_f2(t.second);
00305     }
00306 
00307 // Members
00308 private:
00309     F1  m_f1;
00310     F2  m_f2;
00311 };
00312 
00313 
00314 /* 
00315 
00316 #ifndef _STLSOFT_NO_NAMESPACE
00317 } // namespace stlsoft
00318 #endif /* _STLSOFT_NO_NAMESPACE */
00319 
00320 /* 
00321 
00322 #endif /* !STLSOFT_INCL_H_STLSOFT_FUNCTIONALS */
00323 
00324 /* 

STLSoft Libraries documentation © Synesis Software Pty Ltd, 2001-2004