LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/o3tl - compat_functional.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 4 14 28.6 %
Date: 2012-12-27 Functions: 2 148 1.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  *
       4             :  * Copyright (c) 1994
       5             :  * Hewlett-Packard Company
       6             :  *
       7             :  * Copyright (c) 1996-1998
       8             :  * Silicon Graphics Computer Systems, Inc.
       9             :  *
      10             :  * Copyright (c) 1997
      11             :  * Moscow Center for SPARC Technology
      12             :  *
      13             :  * Copyright (c) 1999
      14             :  * Boris Fomitchev
      15             :  *
      16             :  * This material is provided "as is", with absolutely no warranty expressed
      17             :  * or implied. Any use is at your own risk.
      18             :  *
      19             :  * Permission to use or copy this software for any purpose is hereby granted
      20             :  * without fee, provided the above notices are retained on all copies.
      21             :  * Permission to modify the code and to distribute modified code is granted,
      22             :  * provided the above notices are retained, and a notice that the code was
      23             :  * modified is included with the above copyright notice.
      24             :  *
      25             :  */
      26             : 
      27             : /*
      28             :  * Lifted and paraphrased from STLport - with additions from Fridrich
      29             :  * Strba and Thorsten Behrens
      30             :  */
      31             : 
      32             : #ifndef INCLUDED_O3TL_COMPAT_FUNCTIONAL_HXX
      33             : #define INCLUDED_O3TL_COMPAT_FUNCTIONAL_HXX
      34             : 
      35             : #include <functional>
      36             : 
      37             : namespace o3tl
      38             : {
      39             : 
      40             : /// Identity functor - return the input value
      41             : template<class T>
      42             : struct identity : public std::unary_function<T, T>
      43             : {
      44             :      T operator()(const T& y) const
      45             :      {
      46             :           return (y);
      47             :      }
      48             : };
      49             : 
      50             : /// Functor, given two parameters, return the first
      51             : template<class T1,class T2>
      52             : struct project1st : public std::binary_function<T1, T2, T1>
      53             : {
      54             :     T1 operator()(const T1& y, const T2&) const
      55             :     {
      56             :         return (y);
      57             :     }
      58             : };
      59             : 
      60             : /// Functor, given two parameters, return the second
      61             : template<class T1,class T2>
      62             : struct project2nd : public std::binary_function<T1, T2, T2>
      63             : {
      64             :     T2 operator()(const T1&, const T2& x) const
      65             :     {
      66             :         return (x);
      67             :     }
      68             : };
      69             : 
      70             : /// Select first value of a pair
      71             : template<class P>
      72             : struct select1st : public std::unary_function<P, typename P::first_type>
      73             : {
      74          10 :     const typename P::first_type& operator()(const P& y) const
      75             :     {
      76          10 :         return (y.first);
      77             :     }
      78             : };
      79             : 
      80             : /// Select second value of a pair
      81             : template<class P>
      82             : struct select2nd : public std::unary_function<P, typename P::second_type>
      83             : {
      84          74 :     const typename P::second_type& operator()(const P& y) const
      85             :     {
      86          74 :         return (y.second);
      87             :     }
      88             : };
      89             : 
      90             : /// Call F1 with the result of F2 applied to the one input parameter
      91             : template<class F1, class F2>
      92           0 : class unary_compose : public std::unary_function<typename F2::argument_type, typename F1::result_type>
      93             : {
      94             :     public:
      95           0 :         unary_compose(const F1& fnction1, const F2& fnction2) : ftor1(fnction1), ftor2(fnction2) {}
      96             : 
      97           0 :         typename F1::result_type operator()(const typename F2::argument_type& y) const
      98             :         {
      99           0 :             return (ftor1(ftor2(y)));
     100             :         }
     101             : 
     102             :     protected:
     103             :         F1 ftor1;
     104             :         F2 ftor2;
     105             : };
     106             : 
     107             : /// Create functor that calls F1 with the result of F2 applied to the one input parameter
     108             : template<class F1, class F2>
     109           0 : inline unary_compose<F1, F2> compose1(const F1& fnction1, const F2& fnction2)
     110             : {
     111           0 :     return (unary_compose<F1, F2>(fnction1, fnction2));
     112             : }
     113             : 
     114             : /// Calls F2 and F3 for the two args of F1, respectively
     115             : template<class F1, class F2, class F3>
     116             : class binary_compose : public std::unary_function<typename F2::argument_type,typename F1::result_type>
     117             : {
     118             :     public:
     119             :         binary_compose(const F1& fnction1, const F2& fnction2, const F3& fnction3) : ftor1(fnction1), ftor2(fnction2), ftor3(fnction3) {}
     120             : 
     121             :         typename F1::result_type operator()(const typename F2::argument_type& y) const
     122             :         {
     123             :             return (ftor1(ftor2(y), ftor3(y)));
     124             :         }
     125             : 
     126             :     protected:
     127             :         F1 ftor1;
     128             :         F2 ftor2;
     129             :         F3 ftor3;
     130             : };
     131             : 
     132             : /// Creates functor that calls F2 and F3 for the two args of F1, respectively
     133             : template<class F1, class F2, class F3>
     134             : inline binary_compose<F1, F2, F3> compose2(const F1& fnction1, const F2& fnction2, const F3& fnction3)
     135             : {
     136             :     return (binary_compose<F1, F2, F3>(fnction1, fnction2, fnction3));
     137             : }
     138             : 
     139             : /// Algo that assigns val, val+1, ... to the given range
     140             : template<typename FwdIter, typename ValueType>
     141           0 : inline void iota(FwdIter first, FwdIter last, ValueType val)
     142             : {
     143           0 :     while(first != last)
     144           0 :         *first++ = val++;
     145           0 : }
     146             : 
     147             : }   // namespace o3tl
     148             : 
     149             : #endif
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10