How Does the Tuple Library Fit with the Standard Library?


The Standard Library provides a special case of tuple, a 2-tuple, called std::pair. This construct is used by Standard Library containers, which you have probably noted when operating on elements of std::map. You can store pairs in container classes, too. Of course, std::pair is not just a tool for container classes, it's useful on its own, and it comes with the convenience function std::make_pair, which automates type deduction, plus a set of operators for comparing pairs. A general solution for tuples, not just 2-tuples, is definitely even more useful. The offering from the Tuple library is not fully general, but it allows tuples up to 10 elements. (If more are needed, which seems unlikely but certainly not impossible, this limit can be extended.) What's more, these tuples are as efficient as a handcrafted solution using structs!



    Beyond the C++ Standard Library(c) An Introduction to Boost
    Beyond the C++ Standard Library: An Introduction to Boost
    ISBN: 0321133544
    EAN: 2147483647
    Year: 2006
    Pages: 125

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net