functional.hpp
Go to the documentation of this file.
/*
CLAW - a C++ Library Absolutely Wonderful
CLAW is a free library without any particular aim but being useful to
anyone.
Copyright (C) 2005-2011 Julien Jorge
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
contact: julien.jorge@gamned.org
*/
#ifndef __CLAW_FUNCTIONAL_HPP__
#define __CLAW_FUNCTIONAL_HPP__
#include <utility>
#include <functional>
namespace claw
{
/*-------------------------------------------------------------------------*/
template <class T1, class T2>
class first: public std::unary_function< std::pair<T1, T2>, T1& >
{
public:
T1& operator()( std::pair<T1, T2>& p ) const
{
return p.first;
} // operator() const
}; // class first
/*-------------------------------------------------------------------------*/
template <class T1, class T2>
class const_first:
public std::unary_function<const std::pair<T1, T2>, const T1&>
{
public:
const T1& operator()( const std::pair<T1, T2>& p ) const
{
return p.first;
} // operator()
}; // class const_first
/*-------------------------------------------------------------------------*/
template<class Pair>
class pair_first:
public first<typename Pair::first_type, typename Pair::second_type>
{
// nothing
}; // class pair_first
/*-------------------------------------------------------------------------*/
template<class Pair>
class const_pair_first:
public const_first<typename Pair::first_type, typename Pair::second_type>
{
// nothing
}; // class const_pair_first
/*-------------------------------------------------------------------------*/
template <class T1, class T2>
class second: public std::unary_function< std::pair<T1, T2>, T2& >
{
public:
T2& operator()( std::pair<T1, T2>& p ) const
{
return p.second;
} // operator() const
}; // class second
/*-------------------------------------------------------------------------*/
template <class T1, class T2>
class const_second:
public std::unary_function< const std::pair<T1, T2>, const T2& >
{
public:
const T2& operator()( const std::pair<T1, T2>& p ) const
{
return p.second;
} // operator()
}; // class const_second
/*-------------------------------------------------------------------------*/
template< class Pair >
class pair_second: public second< typename Pair::first_type,
typename Pair::second_type >
{
// nothing
}; // class pair_second
/*-------------------------------------------------------------------------*/
template<class Pair>
class const_pair_second:
public const_second<typename Pair::first_type, typename Pair::second_type>
{
public:
const_pair_second() {}
template<typename F, typename S>
const_pair_second( const second<F, S>& )
{}
}; // class const_pair_second
/*-------------------------------------------------------------------------*/
template<class T>
class unary_true: public std::unary_function<T, bool>
{
public:
bool operator()( const T& t ) const { return true; }
}; // class unary_true
/*-------------------------------------------------------------------------*/
template<class T, class U>
class binary_true: public std::binary_function<T, U, bool>
{
public:
bool operator()( const T& t, const U& u ) const
{
return true;
} // operator()
}; // class binary_true
/*-------------------------------------------------------------------------*/
template<typename F1, typename F2>
class unary_compose
: public std::unary_function< typename F2::argument_type,
typename F1::result_type >
{
public:
unary_compose() {}
template<typename G1, typename G2>
unary_compose( const unary_compose<G1, G2>& that ) { }
typename F1::result_type
operator()( typename F2::argument_type& a ) const
{
return F1()( F2()(a) );
}
}; // class unary_compose
/*-------------------------------------------------------------------------*/
template<typename T>
class delete_function: public std::unary_function<T, void>
{
public:
void operator()( const T& a ) const
{
delete a;
}
}; // class delete_function
/*-------------------------------------------------------------------------*/
template<typename T>
class clone: public std::unary_function<T*, T*>
{
public:
T* operator()( const T* a ) const
{
return new T(*a);
}
}; // class clone
/*-------------------------------------------------------------------------*/
template<typename T>
class dereference:
public std::unary_function<T*, T&>
{
public:
T& operator()( T* a ) const
{
return *a;
}
}; // class dereference
/*-------------------------------------------------------------------------*/
template<typename T>
class const_dereference:
public std::unary_function<const T*, const T&>
{
public:
const_dereference() { }
const_dereference( const dereference<T>& ) { }
const_dereference( const const_dereference<T>& ) { }
const T& operator()( const T* a ) const
{
return *a;
}
}; // class const_dereference
} // namespace claw
#endif // __CLAW_FUNCTIONAL_HPP__
claw::delete_function
Function object that deletes a pointer.
Definition: functional.hpp:255
claw::unary_true
Always true unary predicate.
Definition: functional.hpp:176
claw::second
Fuction object to get the second element of a std::pair.
Definition: functional.hpp:104
claw::clone
Function object that clones a pointer.
Definition: functional.hpp:275
claw::unary_compose::unary_compose
unary_compose(const unary_compose< G1, G2 > &that)
Copy constructor.
Definition: functional.hpp:232
claw::pair_first
Fuction object to get the first element of a std::pair.
Definition: functional.hpp:78
claw::pair_second
Fuction object to get the second element of a std::pair.
Definition: functional.hpp:138
claw::binary_true
Always true binary predicate.
Definition: functional.hpp:195
claw::first
Fuction object to get the first element of a std::pair.
Definition: functional.hpp:44
claw::const_pair_second
Fuction object to get the second element of a std::pair.
Definition: functional.hpp:152
claw::const_pair_first
Fuction object to get the first element of a std::pair.
Definition: functional.hpp:92
claw::dereference
Function object that dereferences a pointer.
Definition: functional.hpp:294
claw::const_dereference
Function object that dereferences a constant pointer.
Definition: functional.hpp:315
claw::unary_compose::operator()
F1::result_type operator()(typename F2::argument_type &a) const
Return (F1 o F2)(a).
Definition: functional.hpp:238
claw::unary_compose
Function object that compose two function objects.
Definition: functional.hpp:217
claw::const_second
Fuction object to get the second element of a std::pair.
Definition: functional.hpp:119
claw::const_first
Fuction object to get the first element of a std::pair.
Definition: functional.hpp:59
claw
This is the main namespace.
Definition: algorithm.hpp:33