Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) BoostUnitsBug

 

Cpp98BoostQt CreatorLubuntuWindows

 

Boost.Units bug shows a Boost.Units bug. Feel free, however, to call it an 'unexpected feature'.

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppBoostUnitsBug/CppBoostUnitsBug.pro

 

include(../../ConsoleApplication.pri)
include(../../Libraries/Boost.pri)

SOURCES += main.cpp

 

 

 

 

 

./CppBoostUnitsBug/main.cpp

 

#include <cassert>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <boost/units/systems/si/prefixes.hpp>      //nano,milli,kilo
#include <boost/units/systems/si/length.hpp>        //meter
#include <boost/units/systems/si/io.hpp>            // <<
#pragma GCC diagnostic pop

int main()
{
  //Works as expected
  {
    const boost::units::quantity<boost::units::si::length> a(
      1.23 * boost::units::si::meter);
    const boost::units::quantity<boost::units::si::length> b(
      1.23 * boost::units::si::milli * boost::units::si::meter);

    const double x = a / boost::units::si::meter;
    const double y = b / boost::units::si::meter;
    assert(x != y && "A meter is not a millimeter");

  }
  //Works as expected
  {
    const boost::units::quantity<boost::units::si::length> a(
      1.23 * boost::units::si::meter);
    const boost::units::quantity<boost::units::si::length> b(
      1.23 * boost::units::si::milli * boost::units::si::meter);

    const double x = a.value();
    const double y = b.value();
    assert(x != y && "A meter is not a millimeter");

  }
  //FAILS
  {
    assert( (1.23 * boost::units::si::meter).value()
      != (1.23 * boost::units::si::milli * boost::units::si::meter).value()
      && "A meter is not a millimeter");
  }
  //FAILS
  {
    const double x = (1.23 * boost::units::si::meter).value();
    const double y = (1.23 * boost::units::si::milli * boost::units::si::meter).value();
    assert(x != y && "A meter is not a millimeter");
  }
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml