fork download
  1. #include <iostream>
  2. #include <bitset>
  3. #include <vector>
  4.  
  5. template <size_t SIZE>
  6. bool operator > (const std::bitset<SIZE> & bs1, const std::bitset<SIZE> & bs2){
  7. return(bs1.to_ulong() > bs2.to_ulong());
  8. }
  9. template <size_t SIZE>
  10. bool operator >=(const std::bitset<SIZE> & bs1, const std::bitset<SIZE> & bs2){
  11. return(bs1.to_ulong() >= bs2.to_ulong());
  12. }
  13. template <size_t SIZE>
  14. bool operator < (const std::bitset<SIZE> & bs1, const std::bitset<SIZE> & bs2){
  15. return(bs1.to_ulong() < bs2.to_ulong());
  16. }
  17. template <size_t SIZE>
  18. bool operator <=(const std::bitset<SIZE> & bs1, const std::bitset<SIZE> & bs2){
  19. return(bs1.to_ulong() <= bs2.to_ulong());
  20. }
  21.  
  22. using namespace std;
  23. int main(void){
  24. vector< bitset<5> > x, y;
  25. x.push_back(bitset<5>(0b11011));
  26. x.push_back(bitset<5>(0b00011));
  27. x.push_back(bitset<5>(0b01110));
  28.  
  29. y.push_back(bitset<5>(0b11001));
  30. y.push_back(bitset<5>(0b11001));
  31. y.push_back(bitset<5>(0b11111));
  32.  
  33. cout << (x[0] > y[0]) << endl; // ここは普通にOKなんだけど…
  34. cout << (x > y) << endl; // ここが何故かコンパイルエラー
  35. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_algobase.h: In static member function ‘static bool std::__lexicographical_compare<_BoolType>::__lc(_II1, _II1, _II2, _II2) [with _II1 = const std::bitset<5u>*, _II2 = const std::bitset<5u>*, bool _BoolType = false]’:
/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_algobase.h:924:   instantiated from ‘bool std::__lexicographical_compare_aux(_II1, _II1, _II2, _II2) [with _II1 = const std::bitset<5u>*, _II2 = const std::bitset<5u>*]’
/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_algobase.h:1022:   instantiated from ‘bool std::lexicographical_compare(_II1, _II1, _II2, _II2) [with _II1 = __gnu_cxx::__normal_iterator<const std::bitset<5u>*, std::vector<std::bitset<5u>, std::allocator<std::bitset<5u> > > >, _II2 = __gnu_cxx::__normal_iterator<const std::bitset<5u>*, std::vector<std::bitset<5u>, std::allocator<std::bitset<5u> > > >]’
/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_vector.h:1128:   instantiated from ‘bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&) [with _Tp = std::bitset<5u>, _Alloc = std::allocator<std::bitset<5u> >]’
/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_vector.h:1140:   instantiated from ‘bool std::operator>(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&) [with _Tp = std::bitset<5u>, _Alloc = std::allocator<std::bitset<5u> >]’
prog.cpp:34:   instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_algobase.h:885: error: no match for ‘operator<’ in ‘* __first1 < * __first2’
/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_algobase.h:887: error: no match for ‘operator<’ in ‘* __first2 < * __first1’
stdout
Standard output is empty