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

📄 test_tuple.cpp

📁 Modern C++ Design 一书中实现的程序库
💻 CPP
字号:
#include <cstdio>
#include <typeinfo>
#include "HierarchyGenerators.h"

using namespace Loki;

template<typename T>
void PrintType(T &)
{
    printf("%s\n", typeid(T).name());
}

template<unsigned I>
class PrintTuple
{
public:

    template<typename T>
    explicit PrintTuple(const T &x)
    {
        PrintTuple<I - 1> X(x);
        PrintType(Field<I>(x));
    }
};

template<>
class PrintTuple<0>
{
public:

    template<typename T>
    explicit PrintTuple(const T &x)
    {
        PrintType(Field<0>(x));
    }
};


template<typename T>
void PrintTupleFunc()
{
    T   x;

    PrintTuple<TL::Length<typename T::TList>::value - 1> X(x);
}

template<int> struct A {};

int
main()
{
    typedef TYPELIST_11(A<1>, A<1>, int, int, A<1>, A<2>, int[10], int, int *, A<2>, A<3>) typelist_t; 
    typedef Tuple<typelist_t> tuple_t;
    
    PrintTupleFunc<tuple_t>();

    tuple_t X;
    A<3> Y = Field< A<3> >(X);
    
    // without -Za warning C4239: nonstandard extension used
    // this is because VC sometimes binds temporary to non-const reference
    // which leads to selecting the wrong Field function (non-const version)
    // fixed in VC7.1
    Y = Field< A<3> >(tuple_t());

    A<3> &Y1 = Field< A<3> >(X);
    Y1 = Y;
}


⌨️ 快捷键说明

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