Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename concepts to lower case #123

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/alternative_namespaces/conversion_factor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace {

template<units::Quantity Target, units::Quantity Source>
template<units::in_quantity Target, units::in_quantity Source>
requires units::equivalent_dim<typename Source::dimension, typename Target::dimension>
inline constexpr std::common_type_t<typename Target::rep, typename Source::rep> conversion_factor(Target, Source)
{
Expand Down
2 changes: 1 addition & 1 deletion example/alternative_namespaces/units_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <units/physical/si/prefixes.h>
#include <units/quantity.h>
// get at the units text of the quantity, without its numeric value
inline auto constexpr units_str(const units::Quantity AUTO& q)
inline auto constexpr units_str(const units::in_quantity AUTO& q)
{
typedef std::remove_cvref_t<decltype(q)> qtype;
return units::detail::unit_text<typename qtype::dimension, typename qtype::unit>();
Expand Down
18 changes: 9 additions & 9 deletions example/avg_speed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ fixed_double_si_avg_speed(si::length<si::metre> d,
}

template<typename U1, typename R1, typename U2, typename R2>
constexpr Speed AUTO si_avg_speed(si::length<U1, R1> d,
constexpr in_speed AUTO si_avg_speed(si::length<U1, R1> d,
si::time<U2, R2> t)
{
return d / t;
}

constexpr Speed AUTO avg_speed(Length AUTO d, Time AUTO t)
constexpr in_speed AUTO avg_speed(in_length AUTO d, in_time AUTO t)
{
return d / t;
}

template<Length D, Time T, Speed V>
template<in_length D, in_time T, in_speed V>
void print_result(D distance, T duration, V speed)
{
const auto result_in_kmph = units::quantity_cast<si::speed<si::kilometre_per_hour>>(speed);
Expand All @@ -68,7 +68,7 @@ void example()
// SI (int)
{
using namespace units::physical::si::literals;
constexpr Length AUTO distance = 220q_km; // constructed from a UDL
constexpr in_length AUTO distance = 220q_km; // constructed from a UDL
constexpr si::time<si::hour, int> duration(2); // constructed from a value

std::cout << "SI units with 'int' as representation\n";
Expand All @@ -82,7 +82,7 @@ void example()
// SI (double)
{
using namespace units::physical::si::literals;
constexpr Length AUTO distance = 220.q_km; // constructed from a UDL
constexpr in_length AUTO distance = 220.q_km; // constructed from a UDL
constexpr si::time<si::hour> duration(2); // constructed from a value

std::cout << "\nSI units with 'double' as representation\n";
Expand All @@ -98,7 +98,7 @@ void example()
// Customary Units (int)
{
using namespace units::physical::international::literals;
constexpr Length AUTO distance = 140q_mi; // constructed from a UDL
constexpr in_length AUTO distance = 140q_mi; // constructed from a UDL
constexpr si::time<si::hour, int> duration(2); // constructed from a value

std::cout << "\nUS Customary Units with 'int' as representation\n";
Expand All @@ -114,7 +114,7 @@ void example()
// Customary Units (double)
{
using namespace units::physical::international::literals;
constexpr Length AUTO distance = 140q_mi; // constructed from a UDL
constexpr in_length AUTO distance = 140q_mi; // constructed from a UDL
constexpr si::time<si::hour> duration(2); // constructed from a value

std::cout << "\nUS Customary Units with 'double' as representation\n";
Expand All @@ -132,7 +132,7 @@ void example()
// CGS (int)
{
using namespace units::physical::cgs::literals;
constexpr Length AUTO distance = 22'000'000q_cm; // constructed from a UDL
constexpr in_length AUTO distance = 22'000'000q_cm; // constructed from a UDL
constexpr cgs::time<si::hour, int> duration(2); // constructed from a value

std::cout << "\nCGS units with 'int' as representation\n";
Expand All @@ -151,7 +151,7 @@ void example()
// CGS (double)
{
using namespace units::physical::cgs::literals;
constexpr Length AUTO distance = 22'000'000q_cm; // constructed from a UDL
constexpr in_length AUTO distance = 22'000'000q_cm; // constructed from a UDL
constexpr cgs::time<si::hour> duration(2); // constructed from a value

std::cout << "\nCGS units with 'double' as representation\n";
Expand Down
2 changes: 1 addition & 1 deletion example/capacitor_time_curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main()
constexpr auto R = 4.7q_kR;

for (auto t = 0q_ms; t <= 50q_ms; ++t) {
const Voltage AUTO Vt = V0 * std::exp(-t / (R * C));
const in_voltage AUTO Vt = V0 * std::exp(-t / (R * C));

std::cout << "at " << t << " voltage is ";

Expand Down
2 changes: 1 addition & 1 deletion example/conversion_factor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace {

template<units::Quantity Target, units::Quantity Source>
template<units::in_quantity Target, units::in_quantity Source>
requires units::equivalent_dim<typename Source::dimension, typename Target::dimension>
inline constexpr std::common_type_t<typename Target::rep, typename Source::rep> conversion_factor(Target, Source)
{
Expand Down
2 changes: 1 addition & 1 deletion example/experimental_angle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main()
auto torque = 20.0q_Nm;
auto energy = 20.0q_J;

physical::Angle AUTO angle = torque / energy;
physical::in_angle AUTO angle = torque / energy;

std::cout << angle << '\n';
}
10 changes: 5 additions & 5 deletions example/hello_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@

using namespace units::physical;

constexpr Speed AUTO avg_speed(Length AUTO d, Time AUTO t)
constexpr in_speed AUTO avg_speed(in_length AUTO d, in_time AUTO t)
{
return d / t;
}

int main()
{
using namespace units::physical::si::literals;
Speed AUTO v1 = avg_speed(220q_km, 2q_h);
Speed AUTO v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
Speed AUTO v3 = quantity_cast<si::metre_per_second>(v2);
Speed AUTO v4 = quantity_cast<int>(v3);
in_speed AUTO v1 = avg_speed(220q_km, 2q_h);
in_speed AUTO v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
in_speed AUTO v3 = quantity_cast<si::metre_per_second>(v2);
in_speed AUTO v4 = quantity_cast<int>(v3);

std::cout << v1 << '\n'; // 110 km/h
std::cout << fmt::format("{}", v2) << '\n'; // 70 mi/h
Expand Down
2 changes: 1 addition & 1 deletion example/kalman_filter-alpha_beta_filter_example2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace {

template<units::Quantity Q>
template<units::in_quantity Q>
struct state_variable {
Q estimated_current_state;
Q predicted_next_state;
Expand Down
19 changes: 14 additions & 5 deletions example/linear_algebra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,22 @@ void matrix_of_quantity_tests()
matrix_of_quantity_divide_by_scalar();
}

/*
template<units::Unit U = si::metre, units::Scalar Rep = double>
using length_v = si::length<U, vector<Rep>>;

template<units::Unit U = si::newton, units::Scalar Rep = double>
using force_v = si::force<U, vector<Rep>>;


void quantity_of_vector_add()
{
std::cout << "\nquantity_of_vector_add:\n";

length_v<> v(vector<>{ 1, 2, 3 });
length_v<> u(vector<>{ 3, 2, 1 });
length_v<si::kilometre> t(vector<>{ 3, 2, 1 });
vector<> vrep { 1.0, 2.0, 3.0 };
length_v<> v(vrep);
length_v<> u(vector<>{ 3.0, 2.0, 1.0 });
length_v<si::kilometre> t(vector<>{ 3.0, 2.0, 1.0 });

std::cout << "v = " << v << "\n";
std::cout << "u = " << u << "\n";
Expand Down Expand Up @@ -266,6 +269,8 @@ void quantity_of_vector_divide_by_scalar()
// std::cout << "v / 2 = " << v / 2 << "\n";
}



void quantity_of_vector_tests()
{
quantity_of_vector_add();
Expand All @@ -274,6 +279,8 @@ void quantity_of_vector_tests()
quantity_of_vector_divide_by_scalar();
}



template<units::Unit U = si::metre, units::Scalar Rep = double>
using length_m = si::length<U, matrix<Rep>>;

Expand Down Expand Up @@ -346,12 +353,14 @@ void quantity_of_matrix_tests()
quantity_of_matrix_divide_by_scalar();
}

*/

}

int main()
{
vector_of_quantity_tests();
matrix_of_quantity_tests();
quantity_of_vector_tests();
quantity_of_matrix_tests();
// quantity_of_vector_tests();
// quantity_of_matrix_tests();
}
4 changes: 2 additions & 2 deletions example/measurement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class measurement {
value_type uncertainty_{};
};

static_assert(units::Scalar<measurement<double>>);
static_assert(units::in_numeric_value<measurement<double>>);

} // namespace

Expand All @@ -162,7 +162,7 @@ void example()
const auto a = si::acceleration<si::metre_per_second_sq, measurement<double>>(measurement(9.8, 0.1));
const auto t = si::time<si::second, measurement<double>>(measurement(1.2, 0.1));

const Speed AUTO v1 = a * t;
const in_speed AUTO v1 = a * t;
std::cout << a << " * " << t << " = " << v1 << " = " << quantity_cast<si::kilometre_per_hour>(v1) << '\n';

si::length<si::metre, measurement<double>> length(measurement(123., 1.));
Expand Down
14 changes: 7 additions & 7 deletions example/total_energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace {

using namespace units::physical;

Energy AUTO total_energy(Momentum AUTO p, Mass AUTO m, Speed AUTO c)
in_energy AUTO total_energy(in_momentum AUTO p, in_mass AUTO m, in_speed AUTO c)
{
return sqrt(pow<2>(p * c) + pow<2>(m * pow<2>(c)));
}
Expand All @@ -42,13 +42,13 @@ void si_example()
using namespace units::physical::si;
using GeV = gigaelectronvolt;

constexpr Speed AUTO c = si2019::speed_of_light<>;
constexpr in_speed AUTO c = si2019::speed_of_light<>;

std::cout << "\n*** SI units (c = " << c << ") ***\n";

const Momentum AUTO p = 4.q_GeV / c;
const Mass AUTO m = 3.q_GeV / pow<2>(c);
const Energy AUTO E = total_energy(p, m, c);
const in_momentum AUTO p = 4.q_GeV / c;
const in_mass AUTO m = 3.q_GeV / pow<2>(c);
const in_energy AUTO E = total_energy(p, m, c);

std::cout << "[in GeV]\n"
<< "p = " << p << "\n"
Expand All @@ -73,10 +73,10 @@ void natural_example()
using namespace units::physical::natural;
using GeV = gigaelectronvolt;

constexpr Speed AUTO c = speed_of_light<>;
constexpr in_speed AUTO c = speed_of_light<>;
const momentum<GeV> p(4);
const mass<GeV> m(3);
const Energy AUTO E = total_energy(p, m, c);
const in_energy AUTO E = total_energy(p, m, c);

std::cout << "\n*** Natural units (c = " << c << ") ***\n"
<< "p = " << p << "\n"
Expand Down
14 changes: 7 additions & 7 deletions example/unknown_dimension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

namespace {

template<units::physical::Length D, units::physical::Time T>
constexpr units::physical::Speed AUTO avg_speed(D d, T t)
template<units::physical::in_length D, units::physical::in_time T>
constexpr units::physical::in_speed AUTO avg_speed(D d, T t)
{
return d / t;
}
Expand All @@ -36,13 +36,13 @@ void example()
using namespace units::physical;
using namespace units::physical::si::literals;

Length AUTO d1 = 123q_m;
Time AUTO t1 = 10q_s;
Speed AUTO v1 = avg_speed(d1, t1);
in_length AUTO d1 = 123q_m;
in_time AUTO t1 = 10q_s;
in_speed AUTO v1 = avg_speed(d1, t1);

auto temp1 = v1 * 50q_m; // produces intermediate unknown dimension with 'unknown_coherent_unit' as its 'coherent_unit'
Speed AUTO v2 = temp1 / 100q_m; // back to known dimensions again
Length AUTO d2 = v2 * 60q_s;
in_speed AUTO v2 = temp1 / 100q_m; // back to known dimensions again
in_length AUTO d2 = v2 * 60q_s;

std::cout << "d1 = " << d1 << '\n';
std::cout << "t1 = " << t1 << '\n';
Expand Down
10 changes: 5 additions & 5 deletions src/include/units/base_dimension.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ namespace units {
*
* Base unit is a measurement unit that is adopted by convention for a base quantity in a specific system of units.
*
* Pair of Symbol and Unit template parameters form an unique identifier of the base dimension. The same identifiers can
* be multiplied and divided which will result with an adjustment of its factor in an Exponent of a DerivedDimension
* Pair of Symbol and in_unit template parameters form an unique identifier of the base dimension. The same identifiers can
* be multiplied and divided which will result with an adjustment of its factor in an in_exponent of a in_derived_dimension
* (in case of zero the dimension will be simplified and removed from further analysis of current expresion). In case
* the Symbol is the same but the Unit differs (i.e. mixing SI and CGS length), there is no automatic simplification but
* the Symbol is the same but the in_unit differs (i.e. mixing SI and CGS length), there is no automatic simplification but
* is possible to force it with a quantity_cast.
*
* @tparam Symbol an unique identifier of the base dimension used to provide dimensional analysis support
* @tparam U a base unit to be used for this base dimension
*/
template<basic_fixed_string Symbol, Unit U>
template<basic_fixed_string Symbol, in_unit U>
requires U::is_named
struct base_dimension {
using base_type_workaround = base_dimension; // TODO Replace with is_base_dimension when fixed
Expand All @@ -56,7 +56,7 @@ struct base_dimension {
};

// base_dimension_less
template<BaseDimension D1, BaseDimension D2>
template<in_base_dimension D1, in_base_dimension D2>
struct base_dimension_less :
std::bool_constant<(D1::symbol < D2::symbol) ||
(D1::symbol == D2::symbol && D1::base_unit::symbol < D1::base_unit::symbol)> {
Expand Down
2 changes: 1 addition & 1 deletion src/include/units/bits/base_units_ratio.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

namespace units::detail {

template<Exponent E>
template<in_exponent E>
requires (E::den == 1 || E::den == 2) // TODO provide support for any den
struct exp_ratio {
using base_ratio = E::dimension::base_unit::ratio;
Expand Down
6 changes: 3 additions & 3 deletions src/include/units/bits/common_quantity.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace units {

template<Dimension D, UnitOf<D> U, Scalar Rep>
template<in_dimension D, in_unit_of<D> U, in_numeric_value Rep>
class quantity;

namespace detail {
Expand Down Expand Up @@ -59,7 +59,7 @@ struct common_quantity_impl<quantity<D1, U1, Rep1>, quantity<D2, U2, Rep2>, Rep>

} // namespace detail

template<Quantity Q1, Quantity Q2, Scalar Rep = std::common_type_t<typename Q1::rep, typename Q2::rep>>
template<in_quantity Q1, in_quantity Q2, in_numeric_value Rep = std::common_type_t<typename Q1::rep, typename Q2::rep>>
requires equivalent_dim<typename Q1::dimension, typename Q2::dimension>
using common_quantity = detail::common_quantity_impl<Q1, Q2, Rep>::type;

Expand All @@ -75,7 +75,7 @@ namespace concepts {

#endif

template<units::Quantity Q1, units::Quantity Q2>
template<units::in_quantity Q1, units::in_quantity Q2>
requires units::equivalent_dim<typename Q1::dimension, typename Q2::dimension>
struct common_type<Q1, Q2> {
using type = units::common_quantity<Q1, Q2>;
Expand Down
2 changes: 1 addition & 1 deletion src/include/units/bits/deduced_symbol_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ constexpr auto deduced_symbol_text(exp_list<Es...>, std::index_sequence<Idxs...>
return (exp_text<Es, Us::symbol, neg_exp, Idxs>() + ...);
}

template<DerivedDimension Dim, Unit... Us>
template<in_derived_dimension Dim, in_unit... Us>
constexpr auto deduced_symbol_text()
{
return deduced_symbol_text<Us...>(typename Dim::recipe(), std::index_sequence_for<Us...>());
Expand Down
Loading