Problem in debugging templates. Build fails specifically for Linux GCC 7, GCC 6, GCC 5, GCC 4.9 error: template argument 1 is invalid
Problem in debugging templates. Build fails specifically for Linux GCC 7, GCC 6, GCC 5, GCC 4.9 error: template argument 1 is invalid
我的 Travis 仅在 Linux GCC 7、GCC 6、GCC 5、GCC 4.9 上失败并出现错误
libs/astronomy/test/coordinate/equatorial_coord.cpp:22:57: error: template argument 1 is invalid
RightAscension<double, quantity<bud::plane_angle>>
^
libs/astronomy/test/coordinate/equatorial_coord.cpp:23:39: error: template argument 2 is invalid
ra(25.0 * bud::degrees);
这里是equatorial_cord.cpp
#define BOOST_TEST_MODULE equatorial_coord_test
#include <iostream>
#include <boost/units/io.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/systems/angle/degrees.hpp>
#include <boost/units/systems/si/plane_angle.hpp>
#include <boost/astronomy/coordinate/coord_sys/equatorial_coord.hpp>
#include <boost/test/unit_test.hpp>
using namespace boost::astronomy::coordinate;
using namespace boost::units;
using namespace boost::units::si;
namespace bud = boost::units::degree;
namespace bu = boost::units;
BOOST_AUTO_TEST_SUITE(angle)
BOOST_AUTO_TEST_CASE(right_ascension) {
//Create object of Right Ascension
RightAscension<double, quantity<bud::plane_angle>>
ra(25.0 * bud::degrees);
//Check value
BOOST_CHECK_CLOSE(ra.get_angle().value(), 25.0, 0.001);
//Quantity stored as expected?
BOOST_TEST((std::is_same<decltype(ra.get_angle()), quantity<bud::plane_angle>>::value));
}
BOOST_AUTO_TEST_SUITE_END()
其中包括并使用 Equatorial_coord.hpp
#include <iostream>
#include <boost/units/io.hpp>
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/units/systems/angle/degrees.hpp>
#include <boost/units/systems/si/plane_angle.hpp>
#include <boost/astronomy/coordinate/coord_sys/coord_sys.hpp>
namespace boost {
namespace astronomy {
namespace coordinate {
namespace bu = boost::units;
namespace bg = boost::geometry;
namespace bud = boost::units::degree;
//Right Ascension
template
<
typename CoordinateType = double,
typename RightAscensionQuantity = bu::quantity<bu::si::plane_angle, CoordinateType>
>
struct RightAscension {
private:
RightAscensionQuantity ra;
public:
RightAscension(){
ra = 0.0 * bu::si::radian;
};
RightAscension(RightAscensionQuantity const& _ra) : ra(_ra) {}
RightAscensionQuantity get_angle() const{
return static_cast<RightAscensionQuantity>(ra);
}
void print() {
std::cout << "Right Ascension: " << ra;
}
};
...
它在我的机器上完美构建,我已经尝试了一些代码变体,但我不明白我遗漏了什么,因为 Linux GCC 7、GCC 6、GCC 5、GCC 4.9 的构建失败。
在这个项目中,我以类似的方式做了很多headers,但从未遇到过这样的问题。如果有任何建议,我将不胜感激。
项目中 namespace bud = boost::units::degree;
的多个定义导致了问题。将其从 Equatorial_coord.hpp
中删除会为您带来神奇的效果。
我的 Travis 仅在 Linux GCC 7、GCC 6、GCC 5、GCC 4.9 上失败并出现错误
libs/astronomy/test/coordinate/equatorial_coord.cpp:22:57: error: template argument 1 is invalid
RightAscension<double, quantity<bud::plane_angle>>
^
libs/astronomy/test/coordinate/equatorial_coord.cpp:23:39: error: template argument 2 is invalid
ra(25.0 * bud::degrees);
这里是equatorial_cord.cpp
#define BOOST_TEST_MODULE equatorial_coord_test
#include <iostream>
#include <boost/units/io.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/systems/angle/degrees.hpp>
#include <boost/units/systems/si/plane_angle.hpp>
#include <boost/astronomy/coordinate/coord_sys/equatorial_coord.hpp>
#include <boost/test/unit_test.hpp>
using namespace boost::astronomy::coordinate;
using namespace boost::units;
using namespace boost::units::si;
namespace bud = boost::units::degree;
namespace bu = boost::units;
BOOST_AUTO_TEST_SUITE(angle)
BOOST_AUTO_TEST_CASE(right_ascension) {
//Create object of Right Ascension
RightAscension<double, quantity<bud::plane_angle>>
ra(25.0 * bud::degrees);
//Check value
BOOST_CHECK_CLOSE(ra.get_angle().value(), 25.0, 0.001);
//Quantity stored as expected?
BOOST_TEST((std::is_same<decltype(ra.get_angle()), quantity<bud::plane_angle>>::value));
}
BOOST_AUTO_TEST_SUITE_END()
其中包括并使用 Equatorial_coord.hpp
#include <iostream>
#include <boost/units/io.hpp>
#include <boost/geometry/core/cs.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/units/systems/angle/degrees.hpp>
#include <boost/units/systems/si/plane_angle.hpp>
#include <boost/astronomy/coordinate/coord_sys/coord_sys.hpp>
namespace boost {
namespace astronomy {
namespace coordinate {
namespace bu = boost::units;
namespace bg = boost::geometry;
namespace bud = boost::units::degree;
//Right Ascension
template
<
typename CoordinateType = double,
typename RightAscensionQuantity = bu::quantity<bu::si::plane_angle, CoordinateType>
>
struct RightAscension {
private:
RightAscensionQuantity ra;
public:
RightAscension(){
ra = 0.0 * bu::si::radian;
};
RightAscension(RightAscensionQuantity const& _ra) : ra(_ra) {}
RightAscensionQuantity get_angle() const{
return static_cast<RightAscensionQuantity>(ra);
}
void print() {
std::cout << "Right Ascension: " << ra;
}
};
...
它在我的机器上完美构建,我已经尝试了一些代码变体,但我不明白我遗漏了什么,因为 Linux GCC 7、GCC 6、GCC 5、GCC 4.9 的构建失败。
在这个项目中,我以类似的方式做了很多headers,但从未遇到过这样的问题。如果有任何建议,我将不胜感激。
项目中 namespace bud = boost::units::degree;
的多个定义导致了问题。将其从 Equatorial_coord.hpp
中删除会为您带来神奇的效果。