/** * @author Edouard DUPIN * @copyright 2011, Edouard DUPIN, all right reserved * @license MPL-2 (see license file) */ #pragma once #include #include #include namespace etk { template class Pair { public: // this is bad for coding rules, but an idiom of c++ pair imposed by the STL ETK_PAIR_TYPE_1 first; ETK_PAIR_TYPE_2 second; Pair(): first(), second() { } Pair(ETK_PAIR_TYPE_1&& _obj1, ETK_PAIR_TYPE_2&& _obj2): first(etk::move(_obj1)), second(etk::move(_obj2)) { } Pair(const ETK_PAIR_TYPE_1& _obj1, ETK_PAIR_TYPE_2&& _obj2): first(_obj1), second(etk::move(_obj2)) { } Pair(const ETK_PAIR_TYPE_1& _obj1, const ETK_PAIR_TYPE_2& _obj2): first(_obj1), second(_obj2) { } Pair(const Pair& _obj): first(_obj.first), second(_obj.second) { } Pair(Pair&& _obj): first(), second() { _obj.swap(*this); } template Pair(const Pair& _pair): first(_pair.first), second(_pair.second) { } bool operator== (const Pair& _obj) const{ return first == _obj.first && second == _obj.second; } bool operator!= (const Pair& _obj) const{ return first != _obj.first || second != _obj.second; } void swap(Pair& _obj) { etk::swap(first, _obj.first); etk::swap(second, _obj.second); } Pair& operator=(const Pair& _obj) { Pair(_obj).swap(*this); return *this; } Pair& operator=(Pair&& _obj) { Pair(etk::move(_obj)).swap(*this); return *this; }/* template Pair& operator=(Pair&& _obj) { Pair(etk::move(_obj)).swap(*this); return *this; }*/ }; template Pair makePair(ETK_PAIR_TYPE_1 _obj1, ETK_PAIR_TYPE_2 _obj2) { return etk::move(etk::Pair(etk::forward(_obj1), etk::forward(_obj2))); } template etk::Stream& operator <<(etk::Stream& _os, const etk::Pair& _obj) { _os << "("; _os << _obj.first; _os << ";"; _os << _obj.second; _os << ")"; return _os; } template bool operator< (const Pair& _obj1, const Pair& _obj2) { if (_obj1.first == _obj2.first) { return _obj1.second < _obj2.second; } return _obj1.first < _obj2.first; } };