mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-31 02:47:16 +02:00
Remove sandbox.cpp from repo
Examples/clcpp_response.cpp : removed debug #defines
This commit is contained in:
committed by
Mateusz Pusz
parent
283e9d81a3
commit
3b0e445b4c
@ -55,16 +55,16 @@ namespace {
|
||||
|
||||
template <typename Rep = double>
|
||||
using fathom = units::si::length<units::international::fathom,Rep>;
|
||||
#if 1
|
||||
|
||||
template <typename Rep = double>
|
||||
using fathom_us = units::si::length<units::us::fathom,Rep>;
|
||||
#endif
|
||||
|
||||
template <typename Rep = double>
|
||||
using ft = units::si::length<units::international::foot,Rep>;
|
||||
#if 1
|
||||
|
||||
template <typename Rep = double>
|
||||
using ft_us = units::si::length<units::us::foot,Rep>;
|
||||
#endif
|
||||
|
||||
template <typename Rep = double>
|
||||
using ly = units::si::length<units::iau::light_year,Rep>;
|
||||
|
||||
@ -174,13 +174,9 @@ void quantities_with_typed_units()
|
||||
std::cout << " = " << length::angstrom<>(meter) << '\n';
|
||||
std::cout << " = " << length::ch<>(meter) << '\n';
|
||||
std::cout << " = " << length::fathom<>(meter) << '\n';
|
||||
#if 1
|
||||
std::cout << " = " << length::fathom_us<>(meter) << '\n';
|
||||
#endif
|
||||
std::cout << " = " << length::ft<>(meter) << '\n';
|
||||
#if 1
|
||||
std::cout << " = " << length::ft_us<>(meter) << '\n';
|
||||
#endif
|
||||
std::cout << " = " << length::in<>(meter) << '\n';
|
||||
std::cout << " = " << length::ly<>(meter) << '\n';
|
||||
std::cout << " = " << length::mi<>(meter) << '\n';
|
||||
|
@ -1,86 +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/physical/si/length.h>
|
||||
|
||||
/*
|
||||
get conversion factor from one dimensionally-equivalent
|
||||
quantity type to another
|
||||
*/
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
template <
|
||||
units::Quantity Target,
|
||||
units::Quantity Source
|
||||
>
|
||||
requires units::equivalent_dim<typename Source::dimension,typename Target::dimension>
|
||||
constexpr inline
|
||||
std::common_type_t<
|
||||
typename Target::rep,
|
||||
typename Source::rep
|
||||
>
|
||||
conversion_factor()
|
||||
{
|
||||
// get quantities looking like inputs but with Q::rep that doesnt 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}}.count();
|
||||
}
|
||||
|
||||
auto units_str( units::Quantity const & q)
|
||||
{
|
||||
typedef std::remove_cvref_t<decltype(q)> qtype;
|
||||
return units::detail::unit_text<typename qtype::dimension, typename qtype::unit>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
namespace length{
|
||||
using m = units::si::length<units::si::metre,double>;
|
||||
using mm = units::si::length<units::si::millimetre,double>;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace units::si::literals;
|
||||
int main()
|
||||
{
|
||||
length::m constexpr plankA = 2.0m;
|
||||
length::mm constexpr plankB = 1000.0mm;
|
||||
|
||||
std::cout << "ratio plankA / plankB = " << plankA / plankB << '\n';
|
||||
|
||||
std::cout << "conversion factor to convert from vS in " << units_str(plankA) ;
|
||||
std::cout << " to vT in " << units_str(plankB) << " : vT = vS * ";
|
||||
std::cout << conversion_factor<length::mm,length::m >() << '\n';
|
||||
|
||||
// can be evaluated at compile time
|
||||
static_assert(conversion_factor<length::mm,length::m>() == 1000,"error");
|
||||
|
||||
}
|
Reference in New Issue
Block a user