用户操作
[即时聊天] [发私信] [加为好友]
pandaID:pandaxcl
86213次访问,排名1155,好友16人,关注者17人。
pandaxcl的文章
原创 62 篇
翻译 0 篇
转载 0 篇
评论 168 篇
pandaxcl的公告

博客文档资源下载在本人的网站下载!!!

我也优先在我的网站论坛上面回答问题

在研究C++自动化编程好久之后,发现C++自动化编程在国内还是一个空白。所谓的C++自动化编程,简单点说就是采用了C++的高级模板技术配合产生式编程技法实现了C++代码的自我配置,自动维护代码之间的种种一致性问题。关于这个问题的讨论,将会在我的网站上面进行细致的讨论。如果有问题,欢迎来我的网站提问哦。看看下面的我的网站的链接。

EMail:pandaxcl@163.com

QQ:56637059

我的网站: http://www.autodev.net

最近评论
pandaxcl:boost里面的mpl是模板元编程的基础结构,而我的这个库目的在于应用模板元到实际的编程中,有很大的区别:)
pandaxcl:呵呵:)这里的any和BOOST里面的any完全是两回事:)
不一样哈;)
whinah:还有boost.spirit,虽然编译速度慢了一点,但是效果很好
whinah:还有boost.spirit,虽然编译速度慢了一点,但是效果很好
whinah:别走火入魔了,你的这个库,boost里面都有,boost.mpl,boost.type_traits,boost.pp
文章分类
收藏
    相册
    友情连接
    小熊猫
    我的另外一个博客
    我的网站-自动化编程社区
    我的论坛-自动化编程社区论坛
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 自定义STL游标实现二分法求解方程的根收藏

    新一篇: 自定义STL游标实现虚拟容器(2) | 旧一篇: 自定义STL游标实现虚拟容器(1)

    //////////////////////////////////////////////////////////////////////////////////////
    //本文假设你已经熟悉自定义STL兼容游标的方法,如果不熟悉自定义STL兼容游标的方法可以参见
    //本人的“自定义STL游标实现虚拟容器”的文章。
    #include <iostream>
    #include <iterator>
    #include <algorithm>
    #include <cmath>
    //////////////////////////////////////////////////////////////////////////////////////
    template<class T,class EQUATION>
    class solve_iterator:public std::iterator<std::forward_iterator_tag,T>
    {
    public:
    solve_iterator(const size_t&i,EQUATION eqn,T&a,T&b,const T&eps)
    :_i(i),_eqn(eqn),_a(a),_b(b),_eps(eps){}
    solve_iterator(const size_t&i,solve_iterator const&it)
    :_i(i),_eqn(it._eqn),_a(it._a),_b(it._b),_eps(it._eps){}
    solve_iterator(solve_iterator const&it)
    :_i(it._i),_eqn(it._eqn),_a(it._a),_b(it._b),_eps(it._eps){}
    solve_iterator&operator=(solve_iterator const&it)
    { if(&it!=this){_i=it._i;_eqn=it._eqn;_a=it._a;_b=it._b;_eps=it._eps;}return*this; }
    size_t& operator*(){return _i;}
    const size_t& operator++()
    { process(); _i++;return _i; }
    bool operator==(const solve_iterator<T,EQUATION>& other) const
    { return _i == other._i; }
    bool operator!=(const solve_iterator<T,EQUATION>& other) const
    { return _i != other._i; }
    bool operator()(const T&i)
    { return fabs(_a - _b)<=_eps; }
    private:
    void process()
    {
    T x,fa,fb,fmid;
    fa=(*_eqn)(_a); fb=(*_eqn)(_b);
    if(fabs(fa)<=_eps) _b = _a;
    else if(fabs(fb)<=_eps) _a = _b;
    else{
    fmid=(*_eqn)(x=(_a+_b)/2);
    if(fmid==0){ _a=x,_b=x; }
    else if(fmid*fa<0){ _b=(_a+_b)/2; }
    else if(fmid*fb<0){ _a=(_a+_b)/2; }
    }
    }
    private:
    size_t _i;
    T _eps;
    EQUATION _eqn;
    T &_a,&_b;
    };
    //////////////////////////////////////////////////////////////////////////////////////
    //下面是测试代码:
    int main()
    {
    struct X{
    static double f1(const double&x){return x*x-1;}
    static double f2(const double&x){return x*x-2;}
    };
    typedef solve_iterator<double,double(*)(const double&x)> SOLVE;
    std::cout.precision(20);
    {
    double a=0,b=2;
    SOLVE begin(0,X::f1,a,b,1e-8),end(10000,begin),root(begin);
    root=std::find_if(begin,end,root);
    std::cout << "迭代次数:[" <<*root<<"] a=[" << a << "] b=[" << b << "]" << std::endl;
    }
    {
    double a=0,b=2;
    SOLVE begin(0,X::f2,a,b,1e-15),end(10000,begin),root(begin);
    root=std::find_if(begin,end,root);
    std::cout << "迭代次数:[" <<*root<<"] a=[" << a << "] b=[" << b << "]" << std::endl;
    }
    return 0;
    }
    ////////////////////////////////////////////////////////////////////////////////
    //运行结果如下:
    /*******************************************************************************
    迭代次数:[1] a=[1] b=[1]
    迭代次数:[51] a=[1.4142135623730949] b=[1.4142135623730958]
    *******************************************************************************/
    ////////////////////////////////////////////////////////////////////////////////

    发表于 @ 2006年03月29日 19:13:00|评论(loading...)|编辑

    新一篇: 自定义STL游标实现虚拟容器(2) | 旧一篇: 自定义STL游标实现虚拟容器(1)

    评论:没有评论。

    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © pandaxcl