zoukankan      html  css  js  c++  java
  • boost 程序库完全开发_ch4_utility

    #include <iostream>
    #include <boost/utility.hpp>
    //#include <boost/noncopyable.hpp>
    //#include <boost/assign.hpp>
    #include <boost/swap.hpp>
    #include <algorithm>
    
    using namespace std;
    using namespace boost;
    
    #if 0
    //class X:noncopyable
    class X
    {
        X(const X& );
        const X& operator=(const X&);
    protected:
        X(){}
        ~X(){}
    
    
    };
    
    class Y: noncopyable{};
    class Z:X{};
    #endif
    
    
    
    #if 0
    #define foreach(container,it) \
        for(typeof((container).begin()) it = (container).begin();it!=(container).end();++it)
    #endif
    struct OP{
        void operator()(int& v)
        {
            cout <<  v << endl;
        }
    };
    
    #if 0
    struct OPStr{
        void operator() (string& str)
        {
            //cout <<str.c_str()<<endl;
            //cout << str.c_str() << endl;
        }
    };
    #endif
    
    #if 0
    void foo(int& v)
    {
        cout <<"foo"<<endl;
    }
    #endif
    
    class point
    {
        int x, y, z;
    public:
        explicit point (int a = 0, int b= 0, int c=0):x(a), y(b),z(c){}
        void print() const 
        {
            cout << "x = " << x << " y = " << y << " z =  " << z << endl;
        }
        void swap(point& p)
        {
            std::swap(x, p.x);
            std::swap(y, p.y);
            std::swap(z, p.z);
    
            cout <<"inner swap" << endl;
        }
    };
    
    
    //namespace std
    
    //{
    //    template<>
        void swap(point& x, point& y)
        {
            x.swap(y);
        }
    //}
    
    int main()
    {
    
        point p1(1,2,3), p2(4,5,6);
        cout <<"std::swap"<<endl;
        std::swap(p1, p2);
        cout <<"boost::swap " << endl;
        boost::swap(p1, p2);
    #if 0
        int a1[10];
        int a2[10];
    
        std::fill_n (a1, 10, 5);
        std::fill_n (a2, 10, 15);
        //boost::swap(a1,a2);
        std:swap(a1,a2);
        //for_each(a1[0], a1[9], OP());
    #endif
    
    //    using namespace boost::assign;
    #if 0
        vector<int> v;
        v += 1,2,3,4,5, 6 * 6;
         std::for_each(v.begin(), v.end(), OP());
         //int n;
         //std::for_each(v.begin(), v.end(), foo(n));
    
        //using namespace boost::assign;
         ///set<string> s;
         //s += "cpp", "java", "c#", "python";
         //insert(s) ("cpp") ("java") ("c#") ("python");
    
         deque<string> d
         push_front (d) ()  ="cpp", "java", "c#", "python";
        // for_each(s.begin(), s.end(), OP());
         //for_each(s.begin(), s.end(), OPStr());
    
    #endif
    
    #if 0
        //X x;
        Y y;
        Z z;
        //y = z;
    #endif
    #if 0
        X y;
    
        //next statement test the as if copyable
        x = y;
    #endif
    
        return 0;
    }
  • 相关阅读:
    MySQL5.7 容器化安装
    什么是架构?——软件系统架构的定义
    服务端高并发分布式架构演进之路(转)
    CentOS7 增加回环地址
    三句话看明白jdk收费吗
    【转载】C#里怎么把string类型转换成double
    【转载】如何查看自己网站的搜索引擎收录量和索引量
    【转载】c# datatable 判断值是否存在
    【转载】C#中Datatable修改列名
    【转载】C#使用typeof运算符获取对象变量的具体类型Type
  • 原文地址:https://www.cnblogs.com/vimmer/p/2984199.html
Copyright © 2011-2022 走看看