次のコードを修正する最もエレガントな方法は次のとおりです。
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef map< int, int > row_t;
typedef vector< row_t > board_t;
typedef row_t::iterator area_t;
bool operator< ( area_t const& a, area_t const& b ) {
return( a->first < b->first );
};
int main( int argc, char* argv[] )
{
int row_num;
area_t it;
set< pair< int, area_t > > queue;
queue.insert( make_pair( row_num, it ) ); // does not compile
};
それを修正する 1 つの方法は、less< の定義を名前空間 std に移動することです (私は知って いますが、そうすることは想定されていません。 )
namespace std {
bool operator< ( area_t const& a, area_t const& b ) {
return( a->first < b->first );
};
};
別の明白な解決策は、ペア < int、area_t > に対して less than< を定義することですが、それを避けて、定義されていないペアの 1 つの要素に対してのみ演算子を定義できるようにしたいと考えています。