0

OSX 10.11.3 でGoogle OR-Tools の例を作成しようとしています。

私が実行すると:

g++  -I../include/ -L../lib -lortools -Wno-c++11-extensions nqueens2.cc

In file included from nqueens2.cc:25:
In file included from ../include/constraint_solver/constraint_solver.h:65:
In file included from ../include/base/hash.h:19:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ext/hash_map:212:5: warning: Use of the header <ext/hash_map> is deprecated.  Migrate to <unordered_map> [-W#warnings]
#   warning Use of the header <ext/hash_map> is deprecated.  Migrate to <unordered_map>
    ^
In file included from nqueens2.cc:25:
In file included from ../include/constraint_solver/constraint_solver.h:65:
In file included from ../include/base/hash.h:20:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ext/hash_set:205:5: warning: Use of the header <ext/hash_set> is deprecated.  Migrate to <unordered_set> [-W#warnings]
#   warning Use of the header <ext/hash_set> is deprecated.  Migrate to <unordered_set>
    ^
In file included from nqueens2.cc:25:
In file included from ../include/constraint_solver/constraint_solver.h:65:
../include/base/hash.h:184:31: error: expected expression
struct hash<std::array<T, N>> {
                              ^
../include/base/hash.h:201:2: error: expected a type
};
 ^
2 warnings and 2 errors generated.

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ext/hash_map問題は、からインクルードしたいときにコンパイラがインクルードしていることだと思い../includeます。

エラーの原因となるコードは次のとおりです../include/base/hash.h(Google OR-Tools に付属しています)。

183 template <class T, std::size_t N>
184 struct hash<std::array<T, N>> {
185  public:
186   size_t operator()(const std::array<T, N>& t) const {
187     uint64 current = 71;
188     for (int index = 0; index < N; ++index) {
189       const T& elem = t[index];
190       const uint64 new_hash = hash<T>()(elem);
191       current = operations_research::Hash64NumWithSeed(current, new_hash);
192     }
193     return current;
194   }
195   // Less than operator for MSVC.
196   bool operator()(const std::array<T, N>& a, const std::array<T, N>& b) const {
197     return a < b;
198   }
199   static const size_t bucket_size = 4;  // These are required by MSVC
200   static const size_t min_buckets = 8;  // 4 and 8 are defaults.
201 };
202 #endif  // STLPORT
203 }  // namespace HASH_NAMESPACE

何かご意見は?

4

2 に答える 2

2

古い g++ コンパイラでは、テンプレート宣言が演算子>として使用されていたため、2 つ連続してテンプレート宣言を行うことはできませんでした。>>そのため、コードで構造体宣言を確認すると、演算子{の式ではなく中括弧が表示されます。>>これは後の c++ 標準で変更され、それに応じて g++ が変更されました。

C++03 コンパイラでは>>、 を右シフト演算子として解釈することが義務付けられていました。これは C++0x 標準で変更されました。

于 2016-02-15T21:27:29.330 に答える