わいえむねっと

Contents
Categories
Calendar
2007/04
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Monthly Archives
~2000/01
Recent Entries
RSS1.0
Templates
Information
Processed: 0.052 sec
Chashed: -
2007/04/06 Fri
豚角煮まんがないのでジューシー肉まん。 ルーチンワークと化した仕事以外の生活を淡々と記録し続けるのも飽きてきたのでというかルーチンそのものには飽きていないのですがまぁとにかくそれはそれとして、メモを残していたり残していなかったり残していないので忘却したり残していてもどこかにやったか忘却したりするような事柄を書いたり書かなかったり酒を飲んでは虚ろな目をしてみることにする。
最後のは余計です。
その前のは今までと変わらないし。
そんな感じで適当に。 structなコンテナに対してalgorithmのsortを使用すると、VisualC++2003では

algorithm(1719): error C2676: 二項演算子 '<' : 'std::allocator<_Ty>::value_type' は、この演算子または定義済の演算子に適切な型への変換の定義を行いません。 (新しい動作; ヘルプを参照)
algorithm(1720): error C2676: 二項演算子 '<' : 'std::allocator<_Ty>::value_type' は、この演算子または定義済の演算子に適切な型への変換の定義を行いません。 (新しい動作; ヘルプを参照)
algorithm(1719): error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : 'const std::_Tree<_Traits> & 用のテンプレート引数を 'std::allocator<_Ty>::value_type' から減少できませんでした。
algorithm(1720): error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : 'const std::_Tree<_Traits> & 用のテンプレート引数を 'std::allocator<_Ty>::value_type' から減少できませんでした。
algorithm(1719): error C2784: 'bool std::operator <(const std::deque<_Ty,_Alloc> &,const std::deque<_Ty,_Alloc> &)' : 'const std::deque<_Ty,_Ax> & 用のテンプレート引数を 'std::allocator<_Ty>::value_type' から減少できませんでした。
algorithm(1720): error C2784: 'bool std::operator <(const std::deque<_Ty,_Alloc> &,const std::deque<_Ty,_Alloc> &)' : 'const std::deque<_Ty,_Ax> & 用のテンプレート引数を 'std::allocator<_Ty>::value_type' から減少できませんでした。
algorithm(1719): error C2784: 'bool std::operator <(const std::list<_Ty,_Alloc> &,const std::list<_Ty,_Alloc> &)' : 'const std::list<_Ty,_Ax> & 用のテンプレート引数を 'std::allocator<_Ty>::value_type' から減少できませんでした。
algorithm(1720): error C2784: 'bool std::operator <(const std::list<_Ty,_Alloc> &,const std::list<_Ty,_Alloc> &)' : 'const std::list<_Ty,_Ax> & 用のテンプレート引数を 'std::allocator<_Ty>::value_type' から減少できませんでした。
algorithm(1719): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : 'const std::pair<_Ty1,_Ty2> & 用のテンプレート引数を 'std::allocator<_Ty>::value_type' から減少できませんでした。
algorithm(1720): error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : 'const std::pair<_Ty1,_Ty2> & 用のテンプレート引数を 'std::allocator<_Ty>::value_type' から減少できませんでした。
algorithm(1719): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : 'const std::reverse_iterator<_RanIt> & 用のテンプレート引数を 'std::allocator<_Ty>::value_type' から減少できませんでした。
algorithm(1720): error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt> &)' : 'const std::reverse_iterator<_RanIt> & 用のテンプレート引数を 'std::allocator<_Ty>::value_type' から減少できませんでした。
algorithm(1719): error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : 'const std::vector<_Ty,_Ax> & 用のテンプレート引数を 'std::allocator<_Ty>::value_type' から減少できませんでした。
algorithm(1720): error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : 'const std::vector<_Ty,_Ax> & 用のテンプレート引数を 'std::allocator<_Ty>::value_type' から減少できませんでした。
algorithm(1720): fatal error C1903: 直前のエラーを修復できません。コンパイルを中止します。

gcc3.4.3だと

stl_algo.h: In function `void std::partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]':
stl_algo.h:2470:   instantiated from `void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >, _Size = int]'
stl_algo.h:2553:   instantiated from `void std::sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
foobar.cc:xxx:   instantiated from here
stl_algo.h:2274: error: no match for 'operator<' in '(&__i)->std::reverse_iterator<_Iterator>::operator* [with _Iterator = __gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > >]() < (&__first)->std::reverse_iterator<_Iterator>::operator* [with _Iterator = __gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > >]()'
stl_algo.h: In function `const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&) [with _Tp = foobar]':
stl_algo.h:2482:   instantiated from `void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >, _Size = int]'
stl_algo.h:2553:   instantiated from `void std::sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
foobar.cc:xxx:   instantiated from here
stl_algo.h:90: error: no match for 'operator<' in '__a < __b'
stl_algo.h:91: error: no match for 'operator<' in '__b < __c'
stl_algo.h:93: error: no match for 'operator<' in '__a < __c'
stl_algo.h:97: error: no match for 'operator<' in '__a < __c'
stl_algo.h:99: error: no match for 'operator<' in '__b < __c'
stl_algo.h: In function `_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, _Tp) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >, _Tp = foobar]':
stl_algo.h:2482:   instantiated from `void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >, _Size = int]'
stl_algo.h:2553:   instantiated from `void std::sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
foobar.cc:xxx:   instantiated from here
stl_algo.h:2014: error: no match for 'operator<' in '(&__first)->std::reverse_iterator<_Iterator>::operator* [with _Iterator = __gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > >]() < __pivot'
stl_algo.h:2482:   instantiated from `void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >, _Size = int]'
stl_algo.h:2553:   instantiated from `void std::sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
foobar.cc:xxx:   instantiated from here
stl_algo.h:2017: error: no match for 'operator<' in '__pivot < (&__last)->std::reverse_iterator<_Iterator>::operator* [with _Iterator = __gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > >]()'
stl_algo.h: In function `void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]':
stl_algo.h:2199:   instantiated from `void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
stl_algo.h:2554:   instantiated from `void std::sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
foobar.cc:xxx:   instantiated from here
stl_algo.h:2117: error: no match for 'operator<' in '__val < (&__first)->std::reverse_iterator<_Iterator>::operator* [with _Iterator = __gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > >]()'
stl_algo.h: In function `void std::__unguarded_linear_insert(_RandomAccessIterator, _Tp) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >, _Tp = foobar]':
stl_algo.h:2123:   instantiated from `void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
stl_algo.h:2199:   instantiated from `void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
stl_algo.h:2554:   instantiated from `void std::sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
foobar.cc:xxx:   instantiated from here
stl_algo.h:2070: error: no match for 'operator<' in '__val < (&__next)->std::reverse_iterator<_Iterator>::operator* [with _Iterator = __gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > >]()'
stl_heap.h: In function `void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >, _Distance = int, _Tp = foobar]':
stl_heap.h:364:   instantiated from `void std::make_heap(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
stl_algo.h:2272:   instantiated from `void std::partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
stl_algo.h:2470:   instantiated from `void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >, _Size = int]'
stl_algo.h:2553:   instantiated from `void std::sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
foobar.cc:xxx:   instantiated from here
stl_heap.h:216: error: no match for 'operator<' in '(&std::reverse_iterator<_Iterator>::operator+(typename std::iterator_traits<_Iterator>::difference_type) const [with _Iterator = __gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > >](__secondChild))->std::reverse_iterator<_Iterator>::operator* [with _Iterator = __gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > >]() < (&std::reverse_iterator<_Iterator>::operator+(typename std::iterator_traits<_Iterator>::difference_type) const [with _Iterator = __gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > >]((__secondChild - 1)))->std::reverse_iterator<_Iterator>::operator* [with _Iterator = __gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > >]()'
stl_heap.h: In function `void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >, _Distance = int, _Tp = foobar]':
stl_heap.h:227:   instantiated from `void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >, _Distance = int, _Tp = foobar]'
stl_heap.h:364:   instantiated from `void std::make_heap(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
stl_algo.h:2272:   instantiated from `void std::partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
stl_algo.h:2470:   instantiated from `void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >, _Size = int]'
stl_algo.h:2553:   instantiated from `void std::sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
foobar.cc:xxx:   instantiated from here
stl_heap.h:121: error: no match for 'operator<' in '(&std::reverse_iterator<_Iterator>::operator+(typename std::iterator_traits<_Iterator>::difference_type) const [with _Iterator = __gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > >](__parent))->std::reverse_iterator<_Iterator>::operator* [with _Iterator = __gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > >]() < __value'

とか怒られる。
<演算子がないとのことなので

struct foobar
{
    int foo, bar;

    bool operator <(foobar& r)
    {
        return foo < r.foo;
    }
};

のようにすると、VisualC++では怒られなくなるが、gccでは

stl_algo.h: In function `const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&) [with _Tp = foobar]':
stl_algo.h:2482:   instantiated from `void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >, _Size = int]'
stl_algo.h:2553:   instantiated from `void std::sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = std::reverse_iterator<__gnu_cxx::__normal_iterator<foobar*, std::vector<foobar, std::allocator<foobar> > > >]'
foobar.cc:xxx:   instantiated from here
stl_algo.h:90: error: no match for 'operator<' in '__a < __b'
foobar.cc:xxx: note: candidates are: bool foobar::operator<(foobar&)
stl_algo.h:91: error: no match for 'operator<' in '__b < __c'
foobar.cc:xxx: note: candidates are: bool foobar::operator<(foobar&)
stl_algo.h:93: error: no match for 'operator<' in '__a < __c'
foobar.cc:xxx: note: candidates are: bool foobar::operator<(foobar&)
stl_algo.h:97: error: no match for 'operator<' in '__a < __c'
foobar.cc:xxx: note: candidates are: bool foobar::operator<(foobar&)
stl_algo.h:99: error: no match for 'operator<' in '__b < __c'
foobar.cc:xxx: note: candidates are: bool foobar::operator<(foobar&)

とかまだ怒られる。
これにSTLFiltを適用すると、

BD Software STL Message Decryptor v2.47a for gcc
stl_algo.h: In function
   `const foobar & __median(const foobar &, const foobar &, const foobar &)':
    [STL Decryptor: Suppressed 2 more STL standard header messages]
foobar.cc:xxx:   instantiated from here
stl_algo.h:90: error: no match for 'operator<' in '__a < __b'
stl_algo.h:91: error: no match for 'operator<' in '__b < __c'
stl_algo.h:93: error: no match for 'operator<' in '__a < __c'
stl_algo.h:97: error: no match for 'operator<' in '__a < __c'
stl_algo.h:99: error: no match for 'operator<' in '__b < __c'

STL Decryptor reminders:
    Use the /hdr:L option to see all suppressed standard lib headers
    Use the /cand:L option to see all suppressed template candidates

のようになる。
constでないのが原因なようなので、

struct foobar
{
    int foo, bar;

    bool operator <(const foobar& r) const
    {
        return foo < r.foo;
    }
};

とかそんな感じに。 STLFilt。
STL絡みのよくわからないエラーメッセージをどうにかするフィルタ。
gccでしか試していないけど、VisualC++にも対応している模様。
アーカイブに含まれるgfiltとgSTLFilt.plを適当に配置して、gfiltの下記あたりを環境に合わせて書き換える。

COMPILER=c++                            # Your g++ compiler command
STLFILT=$HOME/gSTLFilt.pl               # Where you've placed the Perl script

あとはコンパイラをgfiltに置き換えてコンパイルするだけ。
エラーメッセージがどうにかなって出力されるので、唸ったり納得したりする。
http://www.bdsoft​.com/tools/stlfilt.ht​ml