// This ensures that this file is included at most once // in any program, as there may be multiple include // statements. #pragma once #include /////////////////////// // Class declaration // /////////////////////// class Pair; ////////////////////// // Class definition // ////////////////////// // Store a pair of indices. class Pair { public: std::size_t first_; std::size_t second_; }; // Note: The C++ standard library already provides a class // called std::pair in the library. Unlike our Pair // class, std::pair uses templates, allowing the two stored // values to have specified, and possibly different, types. // // For example, // // std::pair p{ 3, 7 }; // // creates a pair containing two std::size_t values. The two // values are accessed using the member variables 'first' // and 'second', rather than 'first_' and 'second_': // // p.first // p.second // // You will learn about templates in upper-year courses, // but in essence, they allow you to write, for example, // an array class for which the user can specify the type // of the entries in the array. In this case, templates // allow the user to specify the types of both items // stored in the pair: /* template class Pair { public: T first; // The first type U second; // The second type }; int main() { Pair p{ 3, 4.5 }; std::cout << p.first << std::endl; // 3 std::cout << p.second << std::endl; // 4.5 return 0; } */