⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transformation.hpp

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 HPP
📖 第 1 页 / 共 2 页
字号:
// Copyright 2005 Daniel Wallin. // Copyright 2005 Joel de Guzman.// Copyright 2005 Dan Marsden. //// Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at// http://www.boost.org/LICENSE_1_0.txt)//// Modeled after range_ex, Copyright 2004 Eric Niebler#ifndef PHOENIX_ALGORITHM_TRANSFORMATION_HPP#define PHOENIX_ALGORITHM_TRANSFORMATION_HPP#include <algorithm>#include <numeric>#include <boost/spirit/home/phoenix/stl/algorithm/detail/has_sort.hpp>#include <boost/spirit/home/phoenix/stl/algorithm/detail/has_remove.hpp>#include <boost/spirit/home/phoenix/stl/algorithm/detail/has_remove_if.hpp>#include <boost/spirit/home/phoenix/stl/algorithm/detail/has_unique.hpp>#include <boost/spirit/home/phoenix/stl/algorithm/detail/has_reverse.hpp>#include <boost/spirit/home/phoenix/stl/algorithm/detail/has_sort.hpp>#include <boost/spirit/home/phoenix/stl/algorithm/detail/begin.hpp>#include <boost/spirit/home/phoenix/stl/algorithm/detail/end.hpp>#include <boost/spirit/home/phoenix/stl/algorithm/detail/decay_array.hpp>#include <boost/spirit/home/phoenix/function/function.hpp>#include <boost/range/result_iterator.hpp>#include <boost/range/difference_type.hpp>#include <boost/mpl/if.hpp>#include <boost/type_traits/is_void.hpp>namespace boost { namespace phoenix { namespace impl{    struct swap    {        template <class A, class B>        struct result        {            typedef void type;        };        template <class A, class B>        void operator()(A& a, B& b) const        {            using std::swap;            swap(a, b);        }    };    struct copy    {        template<class R, class I>        struct result            : detail::decay_array<I>        {};        template<class R, class I>        typename result<R,I>::type        operator()(R& r, I i) const        {            return std::copy(detail::begin_(r), detail::end_(r), i);        }    };    struct copy_backward    {        template<class R, class I>        struct result        {            typedef I type;        };        template<class R, class I>        I operator()(R& r, I i) const        {            return std::copy_backward(detail::begin_(r), detail::end_(r), i);        }    };    struct transform    {        template<class R, class OutorI1, class ForOut, class BinF = void>        struct result            : detail::decay_array<            typename mpl::if_<is_void<BinF>, OutorI1, ForOut>::type>        {        };        template<class R, class O, class F>        typename result<R,O,F>::type        operator()(R& r, O o, F f) const        {            return std::transform(detail::begin_(r), detail::end_(r), o, f);        }        template<class R, class I, class O, class F>        typename result<R,I,O,F>::type        operator()(R& r, I i, O o, F f) const        {            return std::transform(detail::begin_(r), detail::end_(r), i, o, f);        }    };    struct replace    {        template<class R, class T, class T2>        struct result        {            typedef void type;        };        template<class R, class T>        void operator()(R& r, T const& what, T const& with) const        {            std::replace(detail::begin_(r), detail::end_(r), what, with);        }    };    struct replace_if    {        template<class R, class P, class T>        struct result        {            typedef void type;        };        template<class R, class P, class T>        void operator()(R& r, P p, T const& with) const        {            std::replace_if(detail::begin_(r), detail::end_(r), p, with);        }    };    struct replace_copy    {        template<class R, class O, class T, class T2>        struct result            : detail::decay_array<O>        {};        template<class R, class O, class T>        typename result<R,O,T,T>::type         operator()(R& r, O o, T const& what, T const& with) const        {            return std::replace_copy(detail::begin_(r), detail::end_(r), o, what, with);        }    };    struct replace_copy_if    {        template<class R, class O, class P, class T>        struct result            : detail::decay_array<O>        {};        template<class R, class O, class P, class T>        typename result<R,O,P,T>::type        operator()(R& r, O o, P p, T const& with) const        {            return std::replace_copy_if(detail::begin_(r), detail::end_(r), o, p, with);        }    };    struct fill    {        template<class R, class T>        struct result        {            typedef void type;        };        template<class R, class T>        void operator()(R& r, T const& x) const        {            std::fill(detail::begin_(r), detail::end_(r), x);        }    };    struct fill_n    {        template<class R, class N, class T>        struct result        {            typedef void type;        };        template<class R, class N, class T>        void operator()(R& r, N n, T const& x) const        {            std::fill_n(detail::begin_(r), n, x);        }    };    struct generate    {        template<class R, class G>        struct result        {            typedef void type;        };        template<class R, class G>        void operator()(R& r, G g) const        {            std::generate(detail::begin_(r), detail::end_(r), g);        }    };    struct generate_n    {        template<class R, class N, class G>        struct result        {            typedef void type;        };        template<class R, class N, class G>        void operator()(R& r, N n, G g) const        {            std::generate_n(detail::begin_(r), n, g);        }    };    struct remove    {        template<class R, class T>        struct result : range_result_iterator<R>        {        };        template<class R, class T>        typename result<R, T>::type execute(R& r, T const& x, mpl::true_) const        {            r.remove(x);            return detail::end_(r);        }        template<class R, class T>        typename result<R, T>::type execute(R& r, T const& x, mpl::false_) const        {            return std::remove(detail::begin_(r), detail::end_(r), x);        }        template<class R, class T>        typename result<R, T>::type operator()(R& r, T const& x) const        {            return execute(r, x, has_remove<R>());        }    };    struct remove_if    {        template<class R, class P>        struct result : range_result_iterator<R>        {        };        template<class R, class P>        typename result<R, P>::type execute(R& r, P p, mpl::true_) const        {            r.remove_if(p);            return detail::end_(r);        }        template<class R, class P>        typename result<R, P>::type execute(R& r, P p, mpl::false_) const        {            return std::remove_if(detail::begin_(r), detail::end_(r), p);        }        template<class R, class P>        typename result<R, P>::type operator()(R& r, P p) const        {            return execute(r, p, has_remove_if<R>());        }    };    struct remove_copy    {        template<class R, class O, class T>        struct result            : detail::decay_array<O>        {};        template<class R, class O, class T>        typename result<R,O,T>::type        operator()(R& r, O o, T const& x) const        {            return std::remove_copy(detail::begin_(r), detail::end_(r), o, x);        }    };    struct remove_copy_if    {        template<class R, class O, class P>        struct result            : detail::decay_array<O>        {};        template<class R, class O, class P>        typename result<R,O,P>::type        operator()(R& r, O o, P p) const        {            return std::remove_copy_if(detail::begin_(r), detail::end_(r), o, p);        }    };    struct unique    {        template<class R, class P = void>        struct result : range_result_iterator<R>        {        };        template<class R>        typename result<R>::type execute(R& r, mpl::true_) const        {            r.unique();            return detail::end_(r);        }        template<class R>        typename result<R>::type execute(R& r, mpl::false_) const        {            return std::unique(detail::begin_(r), detail::end_(r));        }        template<class R>        typename result<R>::type operator()(R& r) const        {            return execute(r, has_unique<R>());        }        template<class R, class P>        typename result<R>::type execute(R& r, P p, mpl::true_) const        {            r.unique(p);            return detail::end_(r);        }        template<class R, class P>        typename result<R, P>::type execute(R& r, P p, mpl::false_) const        {            return std::unique(detail::begin_(r), detail::end_(r), p);        }        template<class R, class P>        typename result<R, P>::type operator()(R& r, P p) const        {            return execute(r, p, has_unique<R>());        }    };    struct unique_copy    {        template<class R, class O, class P = void>        struct result            : detail::decay_array<O>        {};        template<class R, class O>        typename result<R, O>::type operator()(R& r, O o) const        {            return std::unique_copy(                detail::begin_(r)                , detail::end_(r)                , o                );        }        template<class R, class O, class P>        typename result<R, O, P>::type operator()(R& r, O o, P p) const        {            return std::unique_copy(                detail::begin_(r)                , detail::end_(r)                , o                , p                );        }    };    struct reverse    {        template<class R>        struct result        {            typedef void type;        };        template<class R>        void execute(R& r, mpl::true_) const        {            r.reverse();        }        template<class R>        void execute(R& r, mpl::false_) const        {            std::reverse(detail::begin_(r), detail::end_(r));        }        template<class R>        void operator()(R& r) const        {            execute(r, has_reverse<R>());        }    };    struct reverse_copy    {        template<class R, class O>        struct result            : detail::decay_array<O>        {};        template<class R, class O>        typename result<R, O>::type operator()(R& r, O o) const        {            return std::reverse_copy(                detail::begin_(r)                , detail::end_(r)                , o                );        }    };    struct rotate    {        template<class R, class M>        struct result        {            typedef void type;        };        template<class R, class M>        void operator()(R& r, M m) const        {            std::rotate(                detail::begin_(r)                , m                , detail::end_(r)                );        }    };    struct rotate_copy    {        template<class R, class M, class O>        struct result            : detail::decay_array<O>        {};        template<class R, class M, class O>        typename result<R, M, O>::type operator()(R& r, M m, O o) const        {            return std::rotate_copy(                detail::begin_(r)                , m                , detail::end_(r)                , o                );        }    };    struct random_shuffle    {        template<class R, class G = void>        struct result        {            typedef void type;        };        template<class R>        void operator()(R& r) const        {            return std::random_shuffle(detail::begin_(r), detail::end_(r));        }        template<class R, class G>        void operator()(R& r, G g) const        {            return std::random_shuffle(detail::begin_(r), detail::end_(r), g);        }    };    struct partition    {        template<class R, class P>        struct result : range_result_iterator<R>        {};        template<class R, class P>        typename result<R, P>::type operator()(R& r, P p) const        {            return std::partition(detail::begin_(r), detail::end_(r), p);        }    };    struct stable_partition    {        template<class R, class P>        struct result : range_result_iterator<R>        {};        template<class R, class P>        typename result<R, P>::type operator()(R& r, P p) const        {            return std::stable_partition(detail::begin_(r), detail::end_(r), p);        }    };    struct sort    {        template<class R, class C = void>        struct result        {            typedef void type;        };        template<class R>        void execute(R& r, mpl::true_) const        {            r.sort();        }        template<class R>        void execute(R& r, mpl::false_) const        {            std::sort(detail::begin_(r), detail::end_(r));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -