テスト スイートを作成しているときにoperator<<(std::ostream&...
、Boost 単体テストを使用するための実装を提供する必要がありました。
これはうまくいきました:
namespace theseus { namespace core {
std::ostream& operator<<(std::ostream& ss, const PixelRGB& p) {
return (ss << "PixelRGB(" << (int)p.r << "," << (int)p.g << "," << (int)p.b << ")");
}
}}
これはしませんでした:
std::ostream& operator<<(std::ostream& ss, const theseus::core::PixelRGB& p) {
return (ss << "PixelRGB(" << (int)p.r << "," << (int)p.g << "," << (int)p.b << ")");
}
どうやら、g++ が演算子の使用を解決しようとしたときに、2 番目は一致候補に含まれていませんでした。なぜ(これを引き起こすルールは何ですか)?
コード呼び出しoperator<<
は Boost 単体テスト フレームワークの奥深くにありますが、テスト コードは次のとおりです。
BOOST_AUTO_TEST_SUITE(core_image)
BOOST_AUTO_TEST_CASE(test_output) {
using namespace theseus::core;
BOOST_TEST_MESSAGE(PixelRGB(5,5,5)); // only compiles with operator<< definition inside theseus::core
std::cout << PixelRGB(5,5,5) << "\n"; // works with either definition
BOOST_CHECK(true); // prevent no-assertion error
}
BOOST_AUTO_TEST_SUITE_END()
参考までに、私は g++ 4.4 を使用しています (ただし、現時点では、この動作が標準に準拠していると想定しています)。