Remove reference from std::tuple members

后端 未结 2 1250
花落未央
花落未央 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:24

    Thanks to R. Martinho Fernandes, whose code I was able to modify to compile in Visual Studio where tuple is hard-coded as a template with 10 types with unused types being empty structs.

    #define _RR_(x) typename std::remove_reference::type
    #define _no_ref_tuple_  std::tuple<_RR_(T0), _RR_(T1), _RR_(T2), _RR_(T3), _RR_(T4), _RR_(T5), _RR_(T6), _RR_(T7), _RR_(T8), _RR_(T9)>
    
    template 
    _no_ref_tuple_ map_remove_ref(std::tuple const& t) 
    {
        return _no_ref_tuple_(t);
    }
    

    I also think that binding of the refs into tuple like in

    auto tupleRef = std::make_tuple(std::ref(x_0), ..., std::ref(x_n));
    

    can be made less verbose:

    auto tupleRef = std::forward_as_tuple(x_0, ..., x_n);
    

    but this again will not work in VS, as there is no std::forward_as_tuple.

提交回复
热议问题