• boost tuple笔记(待续)


    tuple

    //z 2011-06-18 22:35:34@is2120.CSDN 转载请注明出处
    1. 概述
    定义了一个有固定数目元素的容器,每个元素类型可以不同。类似pair,只是里面的元素更多。
    可以将pair可以看作tuple的特例,tuple是pair的泛化。
    tuple已被收入 c++ 0x TR1草案。

    2. 类摘要
    template <class T0,...,class T9>
    class tuple
    {
    public:
        tuple();
        tuple(T0 to,...);
        tuple(const tuple<...>&);
        tuple& operator=(const tuple&);
        tuple& operator=(const std::pair&);
       
        template <int N> T get();
    };

    3. 细节
    示例:
    typedef tuple<int,string> my_tuple;
    typedef tuple<int,my_tuple1> my_tuple2;

    为方便创建tuple对象,tuple提供了make_tuple()函数。

    访问元素
    tuple中的 get<>()成员函数访问内部的值。
    BOOST_AUTO(t,make_tuple(1,"char[]",100.0));
    assert(t.get<0>() == 1);
    assert(t.get<2>()==100.0);
    cout << t.get<1>();
    cout << ++t.get<0>();

    ------------------------------------------------------------------
    //z 2011-06-18 22:35:34@is2120.CSDN 转载请注明出处
    #include  <cassert>
    #include  <string>
    #include  <boost/tuple/tuple.hpp>
    #include  <boost/tuple/tuple_comparison.hpp>

    using  namespace  std;
    using  namespace  boost;

    int  main()
    {
        typedef  tuple<int  ,double  ,string > my_tuple;

        my_tuple t1 = make_tuple(1 ,100.0 ,string("abc" ));
        my_tuple t2 = make_tuple(1 ,200.0 ,string("def" ));
        assert(t1<t2);

        my_tuple t3(t2);
        assert(t2==t3);

        return  0 ;
    }

    //z 2011-06-18 22:35:34@is2120.CSDN 转载请注明出处

  • 相关阅读:
    Java中的Graphics2D类基本使用教程
    JSP中页面向Action传递参数的几种方式
    中英文统计
    numpy数据集练习 ----------sklearn类
    IDEA在jsp页面写out.print()代码报错
    Tag文件的创建与应用
    Intellij部署Tomcat问题
    单例测试模式中【饿汉式】与【懒汉式】的区别
    java中类与方法叙述正确的是
    下列关于异常处理的描述中,错误的是()。
  • 原文地址:https://www.cnblogs.com/IS2120/p/6746035.html
Copyright © 2020-2023  润新知