/* The following code example is taken from the book * "The C++ Standard Library - A Tutorial and Reference" * by Nicolai M. Josuttis, Addison-Wesley, 1999 * * (C) Copyright Nicolai M. Josuttis 1999. * Permission to copy, use, modify, sell and distribute this software * is granted provided this copyright notice appears in all copies. * This software is provided "as is" without express or implied * warranty, and with no claim as to its suitability for any purpose. */ /* supplementing compose function objects * Son Dez 26 22:11:12 MET 1999 */ #ifndef BOOST_COMPOSE_HPP #define BOOST_COMPOSE_HPP #include namespace boost { /********************************************************** * type nullary_function * - as supplement to unary_function and binary_function **********************************************************/ template struct nullary_function { typedef Result result_type; }; /********************************************************** * ptr_fun for functions with no argument **********************************************************/ template class pointer_to_nullary_function : public nullary_function { protected: Result (*ptr)(); public: pointer_to_nullary_function() { } explicit pointer_to_nullary_function(Result (*x)()) : ptr(x) { } Result operator()() const { return ptr(); } }; template inline pointer_to_nullary_function ptr_fun(Result (*x)()) { return pointer_to_nullary_function(x); } /*********** compose_f_gx_t and compose_f_gx **********************/ /* class for the compose_f_gx adapter */ template class compose_f_gx_t : public std::unary_function { private: OP1 op1; // process: op1(op2(x)) OP2 op2; public: // constructor compose_f_gx_t(const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x) const { return op1(op2(x)); } }; /* convenience functions for the compose_f_gx adapter */ template inline compose_f_gx_t compose_f_gx (const OP1& o1, const OP2& o2) { return compose_f_gx_t(o1,o2); } /*********** compose_f_gx_hx_t and compose_f_gx_hx **********************/ /* class for the compose_f_gx_hx adapter */ template class compose_f_gx_hx_t : public std::unary_function { private: OP1 op1; // process: op1(op2(x),op3(x)) OP2 op2; OP3 op3; public: // constructor compose_f_gx_hx_t (const OP1& o1, const OP2& o2, const OP3& o3) : op1(o1), op2(o2), op3(o3) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x) const { return op1(op2(x),op3(x)); } }; /* convenience functions for the compose_f_gx_hx adapter */ template inline compose_f_gx_hx_t compose_f_gx_hx (const OP1& o1, const OP2& o2, const OP3& o3) { return compose_f_gx_hx_t(o1,o2,o3); } /*********** compose_f_gxy_t and compose_f_gxy **********************/ /* class for the compose_f_gxy adapter */ template class compose_f_gxy_t : public std::binary_function { private: OP1 op1; // process: op1(op2(x,y)) OP2 op2; public: // constructor compose_f_gxy_t (const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()(const typename OP2::first_argument_type& x, const typename OP2::second_argument_type& y) const { return op1(op2(x,y)); } }; /* convenience function for the compose_f_gxy adapter */ template inline compose_f_gxy_t compose_f_gxy (const OP1& o1, const OP2& o2) { return compose_f_gxy_t(o1,o2); } /*********** compose_f_gx_hy_t and compose_f_gx_hy **********************/ /* class for the compose_f_gx_hy adapter */ template class compose_f_gx_hy_t : public std::binary_function { private: OP1 op1; // process: op1(op2(x),op3(y)) OP2 op2; OP3 op3; public: // constructor compose_f_gx_hy_t (const OP1& o1, const OP2& o2, const OP3& o3) : op1(o1), op2(o2), op3(o3) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x, const typename OP3::argument_type& y) const { return op1(op2(x),op3(y)); } }; /* convenience function for the compose_f_gx_hy adapter */ template inline compose_f_gx_hy_t compose_f_gx_hy (const OP1& o1, const OP2& o2, const OP3& o3) { return compose_f_gx_hy_t(o1,o2,o3); } /*********** compose_f_g_t and compose_f_g **********************/ /* class for the compose_f_g adapter */ template class compose_f_g_t : public boost::nullary_function { private: OP1 op1; // process: op1(op2()) OP2 op2; public: // constructor compose_f_g_t(const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()() const { return op1(op2()); } }; /* convenience functions for the compose_f_g adapter */ template inline compose_f_g_t compose_f_g (const OP1& o1, const OP2& o2) { return compose_f_g_t(o1,o2); } } /* namespace boost */ #endif /*BOOST_COMPOSE_HPP*/ /* supplementing compose function objects * Son Dez 26 22:14:55 MET 1999 */ #ifndef BOOST_COMPOSE_HPP #define BOOST_COMPOSE_HPP #include namespace boost { /********************************************************** * type nullary_function * - as supplement to unary_function and binary_function **********************************************************/ template struct nullary_function { typedef Result result_type; }; /********************************************************** * ptr_fun for functions with no argument **********************************************************/ template class pointer_to_nullary_function : public nullary_function { protected: Result (*ptr)(); public: pointer_to_nullary_function() { } explicit pointer_to_nullary_function(Result (*x)()) : ptr(x) { } Result operator()() const { return ptr(); } }; template inline pointer_to_nullary_function ptr_fun(Result (*x)()) { return pointer_to_nullary_function(x); } /*********** compose_f_gx_t and compose_f_gx **********************/ /* class for the compose_f_gx adapter */ template class compose_f_gx_t : public std::unary_function { private: OP1 op1; // process: op1(op2(x)) OP2 op2; public: // constructor compose_f_gx_t(const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x) const { return op1(op2(x)); } }; /* convenience functions for the compose_f_gx adapter */ template inline compose_f_gx_t compose_f_gx (const OP1& o1, const OP2& o2) { return compose_f_gx_t(o1,o2); } /*********** compose_f_gx_hx_t and compose_f_gx_hx **********************/ /* class for the compose_f_gx_hx adapter */ template class compose_f_gx_hx_t : public std::unary_function { private: OP1 op1; // process: op1(op2(x),op3(x)) OP2 op2; OP3 op3; public: // constructor compose_f_gx_hx_t (const OP1& o1, const OP2& o2, const OP3& o3) : op1(o1), op2(o2), op3(o3) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x) const { return op1(op2(x),op3(x)); } }; /* convenience functions for the compose_f_gx_hx adapter */ template inline compose_f_gx_hx_t compose_f_gx_hx (const OP1& o1, const OP2& o2, const OP3& o3) { return compose_f_gx_hx_t(o1,o2,o3); } /*********** compose_f_gxy_t and compose_f_gxy **********************/ /* class for the compose_f_gxy adapter */ template class compose_f_gxy_t : public std::binary_function { private: OP1 op1; // process: op1(op2(x,y)) OP2 op2; public: // constructor compose_f_gxy_t (const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()(const typename OP2::first_argument_type& x, const typename OP2::second_argument_type& y) const { return op1(op2(x,y)); } }; /* convenience function for the compose_f_gxy adapter */ template inline compose_f_gxy_t compose_f_gxy (const OP1& o1, const OP2& o2) { return compose_f_gxy_t(o1,o2); } /*********** compose_f_gx_hy_t and compose_f_gx_hy **********************/ /* class for the compose_f_gx_hy adapter */ template class compose_f_gx_hy_t : public std::binary_function { private: OP1 op1; // process: op1(op2(x),op3(y)) OP2 op2; OP3 op3; public: // constructor compose_f_gx_hy_t (const OP1& o1, const OP2& o2, const OP3& o3) : op1(o1), op2(o2), op3(o3) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x, const typename OP3::argument_type& y) const { return op1(op2(x),op3(y)); } }; /* convenience function for the compose_f_gx_hy adapter */ template inline compose_f_gx_hy_t compose_f_gx_hy (const OP1& o1, const OP2& o2, const OP3& o3) { return compose_f_gx_hy_t(o1,o2,o3); } /*********** compose_f_g_t and compose_f_g **********************/ /* class for the compose_f_g adapter */ template class compose_f_g_t : public boost::nullary_function { private: OP1 op1; // process: op1(op2()) OP2 op2; public: // constructor compose_f_g_t(const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()() const { return op1(op2()); } }; /* convenience functions for the compose_f_g adapter */ template inline compose_f_g_t compose_f_g (const OP1& o1, const OP2& o2) { return compose_f_g_t(o1,o2); } } /* namespace boost */ #endif /*BOOST_COMPOSE_HPP*/ /* supplementing compose function objects * Fre Dez 31 03:21:48 MET 1999 */ #ifndef BOOST_COMPOSE_HPP #define BOOST_COMPOSE_HPP #include namespace boost { /********************************************************** * type nullary_function * - as supplement to unary_function and binary_function **********************************************************/ template struct nullary_function { typedef Result result_type; }; /********************************************************** * ptr_fun for functions with no argument **********************************************************/ template class pointer_to_nullary_function : public nullary_function { protected: Result (*ptr)(); public: pointer_to_nullary_function() { } explicit pointer_to_nullary_function(Result (*x)()) : ptr(x) { } Result operator()() const { return ptr(); } }; template inline pointer_to_nullary_function ptr_fun(Result (*x)()) { return pointer_to_nullary_function(x); } /*********** compose_f_gx_t and compose_f_gx **********************/ /* class for the compose_f_gx adapter */ template class compose_f_gx_t : public std::unary_function { private: OP1 op1; // process: op1(op2(x)) OP2 op2; public: // constructor compose_f_gx_t(const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x) const { return op1(op2(x)); } }; /* convenience functions for the compose_f_gx adapter */ template inline compose_f_gx_t compose_f_gx (const OP1& o1, const OP2& o2) { return compose_f_gx_t(o1,o2); } /*********** compose_f_gx_hx_t and compose_f_gx_hx **********************/ /* class for the compose_f_gx_hx adapter */ template class compose_f_gx_hx_t : public std::unary_function { private: OP1 op1; // process: op1(op2(x),op3(x)) OP2 op2; OP3 op3; public: // constructor compose_f_gx_hx_t (const OP1& o1, const OP2& o2, const OP3& o3) : op1(o1), op2(o2), op3(o3) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x) const { return op1(op2(x),op3(x)); } }; /* convenience functions for the compose_f_gx_hx adapter */ template inline compose_f_gx_hx_t compose_f_gx_hx (const OP1& o1, const OP2& o2, const OP3& o3) { return compose_f_gx_hx_t(o1,o2,o3); } /*********** compose_f_gxy_t and compose_f_gxy **********************/ /* class for the compose_f_gxy adapter */ template class compose_f_gxy_t : public std::binary_function { private: OP1 op1; // process: op1(op2(x,y)) OP2 op2; public: // constructor compose_f_gxy_t (const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()(const typename OP2::first_argument_type& x, const typename OP2::second_argument_type& y) const { return op1(op2(x,y)); } }; /* convenience function for the compose_f_gxy adapter */ template inline compose_f_gxy_t compose_f_gxy (const OP1& o1, const OP2& o2) { return compose_f_gxy_t(o1,o2); } /*********** compose_f_gx_hy_t and compose_f_gx_hy **********************/ /* class for the compose_f_gx_hy adapter */ template class compose_f_gx_hy_t : public std::binary_function { private: OP1 op1; // process: op1(op2(x),op3(y)) OP2 op2; OP3 op3; public: // constructor compose_f_gx_hy_t (const OP1& o1, const OP2& o2, const OP3& o3) : op1(o1), op2(o2), op3(o3) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x, const typename OP3::argument_type& y) const { return op1(op2(x),op3(y)); } }; /* convenience function for the compose_f_gx_hy adapter */ template inline compose_f_gx_hy_t compose_f_gx_hy (const OP1& o1, const OP2& o2, const OP3& o3) { return compose_f_gx_hy_t(o1,o2,o3); } /*********** compose_f_g_t and compose_f_g **********************/ /* class for the compose_f_g adapter */ template class compose_f_g_t : public boost::nullary_function { private: OP1 op1; // process: op1(op2()) OP2 op2; public: // constructor compose_f_g_t(const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()() const { return op1(op2()); } }; /* convenience functions for the compose_f_g adapter */ template inline compose_f_g_t compose_f_g (const OP1& o1, const OP2& o2) { return compose_f_g_t(o1,o2); } } /* namespace boost */ #endif /*BOOST_COMPOSE_HPP*/ /* supplementing compose function objects * Fre Dez 31 03:23:40 MET 1999 */ #ifndef BOOST_COMPOSE_HPP #define BOOST_COMPOSE_HPP #include namespace boost { /********************************************************** * type nullary_function * - as supplement to unary_function and binary_function **********************************************************/ template struct nullary_function { typedef Result result_type; }; /********************************************************** * ptr_fun for functions with no argument **********************************************************/ template class pointer_to_nullary_function : public nullary_function { protected: Result (*ptr)(); public: pointer_to_nullary_function() { } explicit pointer_to_nullary_function(Result (*x)()) : ptr(x) { } Result operator()() const { return ptr(); } }; template inline pointer_to_nullary_function ptr_fun(Result (*x)()) { return pointer_to_nullary_function(x); } /*********** compose_f_gx_t and compose_f_gx **********************/ /* class for the compose_f_gx adapter */ template class compose_f_gx_t : public std::unary_function { private: OP1 op1; // process: op1(op2(x)) OP2 op2; public: // constructor compose_f_gx_t(const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x) const { return op1(op2(x)); } }; /* convenience functions for the compose_f_gx adapter */ template inline compose_f_gx_t compose_f_gx (const OP1& o1, const OP2& o2) { return compose_f_gx_t(o1,o2); } /*********** compose_f_gx_hx_t and compose_f_gx_hx **********************/ /* class for the compose_f_gx_hx adapter */ template class compose_f_gx_hx_t : public std::unary_function { private: OP1 op1; // process: op1(op2(x),op3(x)) OP2 op2; OP3 op3; public: // constructor compose_f_gx_hx_t (const OP1& o1, const OP2& o2, const OP3& o3) : op1(o1), op2(o2), op3(o3) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x) const { return op1(op2(x),op3(x)); } }; /* convenience functions for the compose_f_gx_hx adapter */ template inline compose_f_gx_hx_t compose_f_gx_hx (const OP1& o1, const OP2& o2, const OP3& o3) { return compose_f_gx_hx_t(o1,o2,o3); } /*********** compose_f_gxy_t and compose_f_gxy **********************/ /* class for the compose_f_gxy adapter */ template class compose_f_gxy_t : public std::binary_function { private: OP1 op1; // process: op1(op2(x,y)) OP2 op2; public: // constructor compose_f_gxy_t (const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()(const typename OP2::first_argument_type& x, const typename OP2::second_argument_type& y) const { return op1(op2(x,y)); } }; /* convenience function for the compose_f_gxy adapter */ template inline compose_f_gxy_t compose_f_gxy (const OP1& o1, const OP2& o2) { return compose_f_gxy_t(o1,o2); } /*********** compose_f_gx_hy_t and compose_f_gx_hy **********************/ /* class for the compose_f_gx_hy adapter */ template class compose_f_gx_hy_t : public std::binary_function { private: OP1 op1; // process: op1(op2(x),op3(y)) OP2 op2; OP3 op3; public: // constructor compose_f_gx_hy_t (const OP1& o1, const OP2& o2, const OP3& o3) : op1(o1), op2(o2), op3(o3) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x, const typename OP3::argument_type& y) const { return op1(op2(x),op3(y)); } }; /* convenience function for the compose_f_gx_hy adapter */ template inline compose_f_gx_hy_t compose_f_gx_hy (const OP1& o1, const OP2& o2, const OP3& o3) { return compose_f_gx_hy_t(o1,o2,o3); } /*********** compose_f_g_t and compose_f_g **********************/ /* class for the compose_f_g adapter */ template class compose_f_g_t : public boost::nullary_function { private: OP1 op1; // process: op1(op2()) OP2 op2; public: // constructor compose_f_g_t(const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()() const { return op1(op2()); } }; /* convenience functions for the compose_f_g adapter */ template inline compose_f_g_t compose_f_g (const OP1& o1, const OP2& o2) { return compose_f_g_t(o1,o2); } } /* namespace boost */ #endif /*BOOST_COMPOSE_HPP*/ /* supplementing compose function objects * Fre Dez 31 04:37:15 MET 1999 */ #ifndef BOOST_COMPOSE_HPP #define BOOST_COMPOSE_HPP #include namespace boost { /********************************************************** * type nullary_function * - as supplement to unary_function and binary_function **********************************************************/ template struct nullary_function { typedef Result result_type; }; /********************************************************** * ptr_fun for functions with no argument **********************************************************/ template class pointer_to_nullary_function : public nullary_function { protected: Result (*ptr)(); public: pointer_to_nullary_function() { } explicit pointer_to_nullary_function(Result (*x)()) : ptr(x) { } Result operator()() const { return ptr(); } }; template inline pointer_to_nullary_function ptr_fun(Result (*x)()) { return pointer_to_nullary_function(x); } /*********** compose_f_gx_t and compose_f_gx **********************/ /* class for the compose_f_gx adapter */ template class compose_f_gx_t : public std::unary_function { private: OP1 op1; // process: op1(op2(x)) OP2 op2; public: // constructor compose_f_gx_t(const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x) const { return op1(op2(x)); } }; /* convenience functions for the compose_f_gx adapter */ template inline compose_f_gx_t compose_f_gx (const OP1& o1, const OP2& o2) { return compose_f_gx_t(o1,o2); } /*********** compose_f_gx_hx_t and compose_f_gx_hx **********************/ /* class for the compose_f_gx_hx adapter */ template class compose_f_gx_hx_t : public std::unary_function { private: OP1 op1; // process: op1(op2(x),op3(x)) OP2 op2; OP3 op3; public: // constructor compose_f_gx_hx_t (const OP1& o1, const OP2& o2, const OP3& o3) : op1(o1), op2(o2), op3(o3) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x) const { return op1(op2(x),op3(x)); } }; /* convenience functions for the compose_f_gx_hx adapter */ template inline compose_f_gx_hx_t compose_f_gx_hx (const OP1& o1, const OP2& o2, const OP3& o3) { return compose_f_gx_hx_t(o1,o2,o3); } /*********** compose_f_gxy_t and compose_f_gxy **********************/ /* class for the compose_f_gxy adapter */ template class compose_f_gxy_t : public std::binary_function { private: OP1 op1; // process: op1(op2(x,y)) OP2 op2; public: // constructor compose_f_gxy_t (const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()(const typename OP2::first_argument_type& x, const typename OP2::second_argument_type& y) const { return op1(op2(x,y)); } }; /* convenience function for the compose_f_gxy adapter */ template inline compose_f_gxy_t compose_f_gxy (const OP1& o1, const OP2& o2) { return compose_f_gxy_t(o1,o2); } /*********** compose_f_gx_hy_t and compose_f_gx_hy **********************/ /* class for the compose_f_gx_hy adapter */ template class compose_f_gx_hy_t : public std::binary_function { private: OP1 op1; // process: op1(op2(x),op3(y)) OP2 op2; OP3 op3; public: // constructor compose_f_gx_hy_t (const OP1& o1, const OP2& o2, const OP3& o3) : op1(o1), op2(o2), op3(o3) { } // function call typename OP1::result_type operator()(const typename OP2::argument_type& x, const typename OP3::argument_type& y) const { return op1(op2(x),op3(y)); } }; /* convenience function for the compose_f_gx_hy adapter */ template inline compose_f_gx_hy_t compose_f_gx_hy (const OP1& o1, const OP2& o2, const OP3& o3) { return compose_f_gx_hy_t(o1,o2,o3); } /*********** compose_f_g_t and compose_f_g **********************/ /* class for the compose_f_g adapter */ template class compose_f_g_t : public boost::nullary_function { private: OP1 op1; // process: op1(op2()) OP2 op2; public: // constructor compose_f_g_t(const OP1& o1, const OP2& o2) : op1(o1), op2(o2) { } // function call typename OP1::result_type operator()() const { return op1(op2()); } }; /* convenience functions for the compose_f_g adapter */ template inline compose_f_g_t compose_f_g (const OP1& o1, const OP2& o2) { return compose_f_g_t(o1,o2); } } /* namespace boost */ #endif /*BOOST_COMPOSE_HPP*/