Remove reference from std::tuple members

后端 未结 2 1265
花落未央
花落未央 2021-01-06 05:54

I\'m implementing save/restore functionality for some variables with the help of stl tuples as follows:

double a = 1, b = 2;
int c = 3;
auto tupleRef = std::         


        
2条回答
  •  感情败类
    2021-01-06 06:05

    A simple type alias can be used to apply std::remove_reference to all types in a tuple.

    template 
    using tuple_with_removed_refs = std::tuple::type...>;
    

    Armed with this you can now write the function template:

    template 
    tuple_with_removed_refs remove_ref_from_tuple_members(std::tuple const& t) {
        return tuple_with_removed_refs { t };
    }
    

提交回复
热议问题