Boost logo

Boost :

Subject: [boost] Boost.Units problem with user-defined units and dimensionless quantities
From: Pieter (PieterB_at_[hidden])
Date: 2011-09-21 15:29:11


LS,

 

I am having some trouble using user-defined units and dimensionless once.
Consider the example (taken straight from the documentation) that defines
nautical miles (added at the bottom).

When I do the following on VS2010:

 

typedef quantity<boost::units::nautical::length> TDistanceInNMI;

typedef quantity<dimensionless> TDimLess;

 

TDistanceInNMI nm1,nm2,nm3;

TDimLess d;

 

nm1 = nm2 + nm3; // compiles OK

nm1 = d*nm2; // compiles OK

nm1 = nm2 + d*nm3; // does not compile, claims there is no operator+ defined

 

I suppose I might have to add a dimensionless type to the 'nautical' system,
or have some misconceptions on how this should work. I tried adding the
following line (mimicking some of the internal stuff) but that did not due
to trick:

 

typedef unit<dimensionless_type,system> dimensionless;

 

Could anyone tell me whether there is there anything I need to define to
make this work?

 

Any help is appreciated,

Many thanks,

Pieter

 

--- The example ---

namespace boost {

   namespace units {

      namespace nautical {

         struct length_base_unit

            : base_unit<length_base_unit, length_dimension, 1000>

         {

             static std::string name() { return "nautical mile"; }

             static std::string symbol() { return "nmi"; }

         };

         typedef make_system<length_base_unit>::type system;

         typedef unit<length_dimension,system> length;

  // 'typedef unit<dimensionless_type,system> dimensionless';

 

         static const length mile,miles;

      }

   }

}

// helper for conversions between nautical length and si length

BOOST_UNITS_DEFINE_CONVERSION_FACTOR(boost::units::nautical::length_base_uni
t,

                                     boost::units::si::meter_base_unit,

                                     double, 1.852e3);

 

 

 

Pieter


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk