演算新のオーバーロードとかテンプレートとか

まあ適当に練習がてら。

#include <iostream>
#include <string>


template <typename _First, typename _Second>
class foo_pair
{
private:
    _First _first;
    _Second _second;
public:
    foo_pair(const _First& f, const _Second& s) { _first = f; _second = s;} 
    foo_pair(const foo_pair<_First, _Second>& p) { _first = p.first(); _second = p.second(); }
    _First first() {return _first;}
    void first(const _First& _f) { _first = _f;}
    _Second second() {return _second;}
    void second(const _Second& _s) { _second = _s;}
};

template <typename _First, typename _Second>
bool operator == (foo_pair<_First, _Second>& __x, foo_pair<_First, _Second>& __y)
{
    return __x.first() == __y.first() && __x.second() == __y.second();
}


int main(int, char**)
{
    using namespace std;

    foo_pair<int, string> intpair(1, "hoge");
    foo_pair<int, string> intpair2(1, "hoge");
    cout << intpair.first() << ", " << intpair.second() << endl;

    intpair.first(3);

    if (intpair == intpair2) {
        cout << " true" << endl;
    }   
    else {
        cout << " false" << endl;
    }   
    return 0;
}


いやまあなんでかっていうと、なんか <> や :: が続く流れを見慣れないとイライラしてくるからであってw