c++ 使用tuple存储内容

 代码抄自pybind11.

#include 
#include 
#include 
/// Helper template to strip away type modifiers
template 
struct intrinsic_type {
    using type = T;
};
template 
struct intrinsic_type {
    using type = typename intrinsic_type::type;
};
template 
struct intrinsic_type {
    using type = typename intrinsic_type::type;
};
template 
struct intrinsic_type {
    using type = typename intrinsic_type::type;
};
template 
struct intrinsic_type {
    using type = typename intrinsic_type::type;
};
template 
struct intrinsic_type {
    using type = typename intrinsic_type::type;
};
template 
struct intrinsic_type {
    using type = typename intrinsic_type::type;
};
template 
using intrinsic_t = typename intrinsic_type::type;
template 
class type_caster{
public:
    bool load(){
        return true;
    }
};
template 
using make_caster = type_caster>;


template 
struct index_sequence {};
template 
struct make_index_sequence_impl : make_index_sequence_impl {};
template 
struct make_index_sequence_impl<0, S...> {
    using type = index_sequence;
};
template 
using make_index_sequence = typename make_index_sequence_impl::type;

template 
class argument_loader{
public:
    using indices = make_index_sequence;
    void print(){
        print_info(indices{});
    }
private:
    template 
    void print_info(index_sequence){
        std::cout<(args).load()...}){
            std::cout<...> args;
};

int main() {
    argument_loader me;
    me.print();
    return 0;
}

 解释两个模板的用法,第一处

std::tuple...> args;

按照main中传入的参数,这句代码会被编译器处理为:

std::tuple,make_caster,make_caster> args;

 第二处:

  for(bool r:{std::get(args).load()...})

编译器处理后,{}中内容是由函数返回值组成的序列。
[1]c++里,如何把模版函数放入数组中?

你可能感兴趣的:(c++ 使用tuple存储内容)