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

前端 未结 12 564
-上瘾入骨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:21

    The C++ tuple syntax can be quite a bit more verbose than most people would like.

    Consider:

    typedef boost::tuple MyTuple;
    

    So if you want to make extensive use of tuples you either get tuple typedefs everywhere or you get annoyingly long type names everywhere. I like tuples. I use them when necessary. But it's usually limited to a couple of situations, like an N-element index or when using multimaps to tie the range iterator pairs. And it's usually in a very limited scope.

    It's all very ugly and hacky looking when compared to something like Haskell or Python. When C++0x gets here and we get the 'auto' keyword tuples will begin to look a lot more attractive.

    The usefulness of tuples is inversely proportional to the number of keystrokes required to declare, pack, and unpack them.

提交回复
热议问题