Why is the use of tuples in C++ not more common?

前端 未结 12 548
-上瘾入骨i
-上瘾入骨i 2021-01-29 23:48

Why does nobody seem to use tuples in C++, either the Boost Tuple Library or the standard library for TR1? I have read a lot of C++ code, and very rarely do I see the use of tup

12条回答
  •  后悔当初
    2021-01-30 00:39

    As a data-store std::tuple has the worst characteristics of both a struct and an array; all access is nth position based but one cannot iterate through a tuple using a for loop.

    So if the elements in the tuple are conceptually an array, I will use an array and if the elements are not conceptually an array, a struct (which has named elements) is more maintainable. ( a.lastname is more explanatory than std::get<1>(a)).

    This leaves the transformation mentioned by the OP as the only viable usecase for tuples.

提交回复
热议问题