現在、boost :: unitsを使用してトルクをsi単位で表していますが、トルクはポンドフィートで与えられます。私はこれをサポートするためにトルクのpound_footユニットと変換を作成しようとしています。boost :: unitsを使用して独自の基本ユニットとコンバージョンを追加する方法
BOOST_STATIC_CONST(boost::si::torque, pound_feet = 1.3558179483314 * si::newton_meters);
をそして実行します:私の怠惰な試みは、単純に定義することでした
boost::si::torque torque = some_value * pound_feet;
しかし、これは不満足なものに感じています。私の2番目の試みは、pound_footと呼ばれる新しいベースユニットを定義しようと試みることでした(下記参照)。しかし、私は上記のような方法でそれを使用しようとすると(siユニットへのキャスト)私はエラーの完全なページを取得します。正しいアプローチに関する提案はありますか?
#include <boost/units/base_units/us/pound_force.hpp>
#include <boost/units/base_units/us/foot.hpp>
#include <boost/units/systems/si/torque.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/io.hpp>
#include <iostream>
namespace boost {
namespace units {
namespace us {
typedef make_system< foot_base_unit, pound_force_base_unit >::type system;
typedef unit< torque_dimension, system > torque;
BOOST_UNITS_STATIC_CONSTANT(pound_feet,torque);
}
}
}
using namespace boost::units;
int main() {
quantity<us::torque> colonial_measurement(1.0 * us::pound_feet);
std::cerr << quantity<si::torque>(colonial_measurement) << std::endl;
return 0;
}
このプログラムを計算:
namespace us {
struct pound_foot_base_unit : base_unit<pound_foot_base_unit, torque_dimension> { };
typedef units::make_system<
pound_foot_base_unit>::type us_system;
typedef unit<torque_dimension, us_system> torque;
BOOST_UNITS_STATIC_CONSTANT(pound_foot, torque);
BOOST_UNITS_STATIC_CONSTANT(pound_feet, torque);
}
BOOST_UNITS_DEFINE_CONVERSION_FACTOR(us::torque,
boost::units::si::torque,
double, 1.3558179483314);
魅力のように動作します - ありがとう。 –