Defining element initialization order when constructing std::tuple

后端 未结 2 676
深忆病人
深忆病人 2021-01-25 18:10

I would like to store the initialization values for elements in a tuple inside a separate tuple, so that I can use the same values as a preset for other tuples of the respective

2条回答
  •  花落未央
    2021-01-25 18:23

    There is no requirement in the standard for the order of std::tuple member initialisation, I am afraid.

    You can iterate over a tuple in a specific order though, e.g.:

    #include 
    #include 
    
    #include 
    #include 
    
    int main()
    {
        auto a = std::make_tuple(true, 42, 3.14, "abc");
        boost::fusion::for_each(a, [](auto& value) {
                std::cout << value << '\n';
            });
    }
    

    Outputs:

    1
    42
    3.14
    abc
    

提交回复
热议问题