std::get using enum class as template argument

后端 未结 6 1599
孤街浪徒
孤街浪徒 2021-01-04 07:40

I\'m using a std::tuple and defined a class enum to somehow \"naming\" each of the tuple\'s fields, forgetting about their actual indexes.

So instead o

6条回答
  •  囚心锁ツ
    2021-01-04 07:53

    A completely different solution would be:

    A& my_field(std::tuple& t) { return std::get<0>(t); }
    A const& my_field(std::tuple const& t) { return std::get<0>(t); }
    
    B& my_other_field(std::tuple& t) { return std::get<1>(t); }
    B const& my_other_field(std::tuple const& t) { return std::get<1>(t); }
    
    my_field(t) = blah;
    my_other_field(t) = frob;
    

提交回复
热议问题