// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <iostream>
#include <string>
#include <format>

using namespace std;

class Data
{
private:
    int iv;
    string sv;
public:
    Data(int iv, string sv);
    string ToString() const;
};

Data::Data(int iv, string sv)
{
    this->iv = iv;
    this->sv = sv;
}

string Data::ToString() const
{
    return format("({0},{1})", iv, sv);
}

template<>
struct std::formatter<Data> : std::formatter<string_view>
{
    format_context::iterator format(const Data& d, format_context& ctx) const
    {
        return format_to(ctx.out(), "{}", d.ToString());
    }
};

int main()
{
    Data d(123, "ABC");
    cout << format("{0}", d) << endl;
    return 0;
}
    
