refactor: References are now guarded UNITS_REFERENCES with (ON by default) + examples duplicated to subdirectories

Now References can be disabled to meassure a compile time impact. Also the same examples are now provided in two subdirectories to be able to easily compare the pros and cons of every quantity construction technique.
This commit is contained in:
Mateusz Pusz
2021-04-06 15:57:28 +02:00
parent b842c3f94a
commit b982921d27
118 changed files with 2841 additions and 71 deletions
-61
View File
@@ -1,61 +0,0 @@
/*
Copyright (c) 2003-2020 Andy Little.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses./
*/
#include <units/format.h>
#include <units/isq/si/length.h>
#include <iostream>
#include <type_traits>
/*
get conversion factor from one dimensionally equivalent
quantity type to another
*/
namespace {
template<units::Quantity Target, units::Quantity Source>
requires units::equivalent<typename Source::dimension, typename Target::dimension>
inline constexpr std::common_type_t<typename Target::rep, typename Source::rep> conversion_factor(Target, Source)
{
// get quantities looking like inputs but with Q::rep that doesn't have narrowing conversion
typedef std::common_type_t<typename Target::rep, typename Source::rep> rep;
typedef units::quantity<typename Source::dimension, typename Source::unit, rep> source;
typedef units::quantity<typename Target::dimension, typename Target::unit, rep> target;
return target{source{1}}.number();
}
} // namespace
int main()
{
using namespace units::isq::si;
using namespace units::isq::si::references;
std::cout << "conversion factor in mp-units...\n\n";
constexpr length<metre> lengthA = 2.0 * m;
constexpr length<millimetre> lengthB = lengthA;
std::cout << fmt::format("lengthA( {} ) and lengthB( {} )\n", lengthA, lengthB)
<< "represent the same length in different units.\n\n";
std::cout << fmt::format("therefore ratio lengthA / lengthB == {}\n\n", lengthA / lengthB);
std::cout << fmt::format("conversion factor from lengthA::unit of {:%q} to lengthB::unit of {:%q}:\n\n", lengthA, lengthB)
<< fmt::format("lengthB.number( {} ) == lengthA.number( {} ) * conversion_factor( {} )\n",
lengthB.number(), lengthA.number(), conversion_factor(lengthB, lengthA));
}