C++ Tuple vs Struct

后端 未结 12 1829
耶瑟儿~
耶瑟儿~ 2020-12-07 10:51

Is there is any difference between using a std::tuple and a data-only struct?

typedef std::tuple foo_t;

s         


        
12条回答
  •  忘掉有多难
    2020-12-07 11:41

    Tuple has built in default(for == and != it compares every element, for <.<=... compares first, if same compares second...) comparators: http://en.cppreference.com/w/cpp/utility/tuple/operator_cmp

    edit: as noted in the comment C++20 spaceship operator gives you a way to specify this functionality with one(ugly, but still just one) line of code.

提交回复
热议问题