00001 /* 00002 * See the dyninst/COPYRIGHT file for copyright information. 00003 * 00004 * We provide the Paradyn Tools (below described as "Paradyn") 00005 * on an AS IS basis, and do not warrant its validity or performance. 00006 * We reserve the right to update, modify, or discontinue this 00007 * software at any time. We shall have no obligation to supply such 00008 * updates or modifications or any other form of support to you. 00009 * 00010 * By your use of Paradyn, you understand and agree that we (or any 00011 * other person or entity with proprietary rights in Paradyn) are 00012 * under no obligation to provide either maintenance services, 00013 * update services, notices of latent defects, or correction of 00014 * defects for Paradyn. 00015 * 00016 * This library is free software; you can redistribute it and/or 00017 * modify it under the terms of the GNU Lesser General Public 00018 * License as published by the Free Software Foundation; either 00019 * version 2.1 of the License, or (at your option) any later version. 00020 * 00021 * This library is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00024 * Lesser General Public License for more details. 00025 * 00026 * You should have received a copy of the GNU Lesser General Public 00027 * License along with this library; if not, write to the Free Software 00028 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00029 */ 00030 #ifndef STL_UTILS 00031 #define STL_UTILS 00032 #include <utility> 00033 00034 /// 00035 /// This file contains some utility functions for dealing with the STL. 00036 /// In particular, this mostly contains functors and adaptors for dealing 00037 /// with std::pair inside STL algorithms. 00038 /// 00039 00040 namespace Dyninst { 00041 00042 /// Functor to get the first element of a pair. Use with STL functions like transform(). 00043 struct get_first { 00044 template <typename P> 00045 typename P::first_type operator()(const P& pair) { 00046 return pair.first; 00047 } 00048 }; 00049 00050 /// Functor to get the second element of a pair. Use with STL functions like transform(). 00051 struct get_second { 00052 template <typename P> 00053 typename P::second_type operator()(const P& pair) { 00054 return pair.second; 00055 } 00056 }; 00057 00058 /// Applies a ftor to the first element of a pair 00059 template <typename Functor> 00060 struct do_to_first_ftor { 00061 Functor ftor; 00062 do_to_first_ftor(const Functor& f) : ftor(f) { } 00063 template <typename P> 00064 void operator()(const P& pair) { 00065 ftor(pair.first); 00066 } 00067 }; 00068 00069 /// Type-inferring adapter function for do_to_first_ftor 00070 template <typename Functor> 00071 inline do_to_first_ftor<Functor> do_to_first(const Functor& f) { 00072 return do_to_first_ftor<Functor>(f); 00073 } 00074 00075 /// Applies a ftor to the second element of a pair 00076 template <typename Functor> 00077 struct do_to_second_ftor { 00078 Functor ftor; 00079 do_to_second_ftor(const Functor& f) : ftor(f) { } 00080 template <typename P> 00081 void operator()(const P& pair) { 00082 ftor(pair.second); 00083 } 00084 }; 00085 00086 /// Type-inferring adapter function for do_to_second_ftor 00087 template <typename Functor> 00088 inline do_to_second_ftor<Functor> do_to_second(const Functor& f) { 00089 return do_to_second_ftor<Functor>(f); 00090 } 00091 00092 } // namespace Dyninst 00093 00094 #endif // STL_UTILS
1.6.1