//******************************************************** // The following code example is taken from the book // C++20 - The Complete Guide // by Nicolai M. Josuttis (www.josuttis.com) // http://www.cppstd20.com // // The code is licensed under a // Creative Commons Attribution 4.0 International License // http://creativecommons.org/licenses/by/4.0/ //******************************************************** #include #include #include // don't include yet !! struct Data { int id; std::string value; }; std::ostream& operator<< (std::ostream& strm, const Data& d) { return strm << '[' << d.id << ": " << d.value << ']'; } // tuple-like access to Data: namespace std { template<> struct tuple_size : integral_constant { }; template<> struct tuple_element<0, Data> { using type = int; }; template<> struct tuple_element<1, Data> { using type = std::string; }; template auto get(const Data& d) { if constexpr (Idx == 0) { return d.id; } else { return d.value; } } } // namespace std