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;
}
原文地址:https://www.cnblogs.com/vimmer/p/2984199.html