• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Directories
  • File List
  • File Members

functional.hpp

Go to the documentation of this file.
00001 /*
00002   CLAW - a C++ Library Absolutely Wonderful
00003 
00004   CLAW is a free library without any particular aim but being useful to 
00005   anyone.
00006 
00007   Copyright (C) 2005-2008 Julien Jorge
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023   contact: julien_jorge@yahoo.fr
00024 */
00030 #ifndef __CLAW_FUNCTIONAL_HPP__
00031 #define __CLAW_FUNCTIONAL_HPP__
00032 
00033 #include <utility>
00034 #include <functional>
00035 
00036 namespace claw
00037 {
00038   /*-------------------------------------------------------------------------*/
00043   template <class T1, class T2>
00044   class first : public std::unary_function< std::pair<T1, T2>, T1& >  
00045   {
00046   public:
00047     T1& operator()( std::pair<T1, T2>& p ) const 
00048     {
00049       return p.first;
00050     } // operator() const
00051   }; // class first
00052 
00053   /*-------------------------------------------------------------------------*/
00058   template <class T1, class T2>
00059   class const_first:
00060     public std::unary_function<const std::pair<T1, T2>, const T1&>
00061   {
00062   public:
00063     const T1& operator()( const std::pair<T1, T2>& p ) const 
00064     {
00065       return p.first;
00066     } // operator()
00067 
00068   }; // class const_first
00069 
00070   /*-------------------------------------------------------------------------*/
00077   template<class Pair>
00078   class pair_first:
00079     public first<typename Pair::first_type, typename Pair::second_type>
00080   {
00081     // nothing
00082   }; // class pair_first
00083 
00084   /*-------------------------------------------------------------------------*/
00091   template<class Pair>
00092   class const_pair_first:
00093     public const_first<typename Pair::first_type, typename Pair::second_type>
00094   {
00095     // nothing
00096   }; // class const_pair_first
00097 
00098   /*-------------------------------------------------------------------------*/
00103   template <class T1, class T2>
00104   class second : public std::unary_function< std::pair<T1, T2>, T2& >  
00105   {
00106   public:
00107     T2& operator()( std::pair<T1, T2>& p ) const 
00108     {
00109       return p.second;
00110     } // operator() const
00111   }; // class second
00112 
00113   /*-------------------------------------------------------------------------*/
00118   template <class T1, class T2>
00119   class const_second:
00120     public std::unary_function< const std::pair<T1, T2>, const T2& >  
00121   {
00122   public:
00123     const T2& operator()( const std::pair<T1, T2>& p ) const 
00124     {
00125       return p.second;
00126     } // operator()
00127 
00128   }; // class const_second
00129 
00130   /*-------------------------------------------------------------------------*/
00137   template< class Pair >
00138   class pair_second : public second< typename Pair::first_type,
00139                                      typename Pair::second_type >
00140   {
00141     // nothing
00142   }; // class pair_second
00143 
00144   /*-------------------------------------------------------------------------*/
00151   template< class Pair >
00152   class const_pair_second:
00153     public const_second<typename Pair::first_type, typename Pair::second_type>
00154   {
00155     // nothing
00156   }; // class const_pair_second
00157 
00158   /*-------------------------------------------------------------------------*/
00169   template<class T>
00170   class unary_true : public std::unary_function<T, bool>
00171   {
00172   public:
00173     bool operator()( const T& t ) const { return true; }
00174   }; // class unary_true
00175 
00176   /*-------------------------------------------------------------------------*/
00188   template<class T, class U>
00189   class binary_true : public std::binary_function<T, U, bool>
00190   {
00191   public:
00192     bool operator()( const T& t, const U& u ) const
00193     {
00194       return true;
00195     } // operator()
00196   }; // class binary_true
00197 
00198   /*-------------------------------------------------------------------------*/
00210   template<typename F1, typename F2>
00211   class unary_compose
00212     : public std::unary_function< typename F2::argument_type,
00213                                   typename F1::result_type >
00214   {
00215   public:
00219     typename F1::result_type
00220     operator()( typename F2::argument_type& a ) const
00221     {
00222       return F1()( F2()(a) );
00223     }
00224 
00225   }; // class unary_compose
00226 
00227   /*-------------------------------------------------------------------------*/
00237   template<typename T>
00238   class delete_function : public std::unary_function<T, void>
00239   {
00240   public:
00241     void operator()( const T& a ) const
00242     {
00243       delete a;
00244     }
00245   }; // class delete_function
00246 
00247   /*-------------------------------------------------------------------------*/
00257   template<typename T>
00258   class clone : public std::unary_function<T*, T*>
00259   {
00260   public:
00261     T* operator()( const T* a ) const
00262     {
00263       return new T(*a);
00264     }
00265   }; // class clone
00266 
00267   /*-------------------------------------------------------------------------*/
00276   template<typename T>
00277   class dereference : public std::unary_function<T*, T&>
00278   {
00279   public:
00280     T& operator()( T* a ) const
00281     {
00282       return *a;
00283     }
00284 
00285   }; // class dereference
00286 
00287   /*-------------------------------------------------------------------------*/
00296   template<typename T>
00297   class const_dereference : public std::unary_function<const T*, const T&>
00298   {
00299   public:
00300     const T& operator()( const T* a ) const
00301     {
00302       return *a;
00303     }
00304 
00305   }; // class const_dereference
00306 } // namespace claw
00307 
00308 #endif // __CLAW_FUNCTIONAL_HPP__

Generated on Thu Aug 11 2011 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.7.1