Skip to content

Commit

Permalink
Physical units put in the physical namespace (I am sorry)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed May 8, 2020
1 parent 771a9a1 commit 7e935a4
Show file tree
Hide file tree
Showing 117 changed files with 351 additions and 348 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ the below example for a quick preview of basic library features:
#include <units/physical/international/velocity.h>
#include <iostream>
using namespace units;
using namespace units::physical;
constexpr Velocity auto avg_speed(Length auto d, Time auto t)
{
Expand All @@ -63,7 +63,7 @@ constexpr Velocity auto avg_speed(Length auto d, Time auto t)
int main()
{
using namespace si::literals;
using namespace units::physical::si::literals;
Velocity auto v1 = avg_speed(220q_km, 2q_h);
Velocity auto v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
Velocity auto v3 = quantity_cast<si::metre_per_second>(v2);
Expand Down
24 changes: 12 additions & 12 deletions docs/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ in the design documentation.
Coming back to units, here are a few examples of unit definitions:

```cpp
namespace units::si {
namespace units::physical::si {

// prefixes
struct prefix : prefix_family {};
Expand All @@ -170,7 +170,7 @@ struct kilometre_per_hour : deduced_unit<kilometre_per_hour, dim_velocity, kilom

}

namespace units::us {
namespace units::physical::us {

// length
struct yard : named_scaled_unit<yard, "yd", no_prefix, ratio<9'144, 10'000>, si::metre> {};
Expand Down Expand Up @@ -224,7 +224,7 @@ These identifiers provide total ordering of exponents of base dimensions in a de
The SI physical units system defines 7 base dimensions:
```cpp
namespace units::si {
namespace units::physical::si {
struct dim_length : base_dimension<"L", metre> {};
struct dim_mass : base_dimension<"M", kilogram> {};
Expand All @@ -244,7 +244,7 @@ base unit is needed for the text output of unnamed derived units. Second, there
one system of physical units. For example CGS definitions look as follows:

```cpp
namespace units::cgs {
namespace units::physical::cgs {

using si::centimetre;
using si::gram;
Expand Down Expand Up @@ -354,7 +354,7 @@ directly define a barye in terms of pascal or vice versa.
Below are a few examples of derived dimension definitions:

```cpp
namespace units::si {
namespace units::physical::si {

struct dim_velocity : derived_dimension<dim_velocity, metre_per_second,
exp<dim_length, 1>, exp<dim_time, -1>> {};
Expand Down Expand Up @@ -448,8 +448,8 @@ Beside adding new elements a few other changes where applied compared to the `st

To simplify writing efficient generic code quantities of each dimension have associated:
1. Concept (i.e. `units::Length`) that matches a length dimension of any physical systems.
2. Per-system quantity alias (i.e. `units::si::length<Unit, Rep>` for
`units::quantity<units::si::dim_length, Unit, Rep>`).
2. Per-system quantity alias (i.e. `units::physical::si::length<Unit, Rep>` for
`units::quantity<units::physical::si::dim_length, Unit, Rep>`).

Also, to help instantiate quantities with compile-time known values every unit in the library
has an associated UDL. For example:
Expand Down Expand Up @@ -603,9 +603,9 @@ user. If we will get a compilation error message containing `dim_capacitance` in
the compiler will print the following type instead of the alias:

```text
units::detail::derived_dimension_base<units::exp<units::si::dim_electric_current, 2, 1>,
units::exp<units::si::dim_length, -2, 1>, units::exp<units::si::dim_mass, -1, 1>,
units::exp<units::si::dim_time, 4, 1> >
units::detail::derived_dimension_base<units::exp<units::physical::si::dim_electric_current, 2, 1>,
units::exp<units::physical::si::dim_length, -2, 1>, units::exp<units::physical::si::dim_mass, -1, 1>,
units::exp<units::physical::si::dim_time, 4, 1> >
```

You can notice that even this long syntax was carefully selected to provide quite good user
Expand Down Expand Up @@ -760,8 +760,8 @@ struct unknown_dimension : derived_dimension<unknown_dimension<E, ERest...>,
with this the error log or a debugger breakpoint involving a `temp1` type will include:
```text
units::quantity<units::unknown_dimension<units::exp<units::si::dim_length, 2, 1>,
units::exp<units::si::dim_time, -1, 1> >, units::unknown_coherent_unit, long int>
units::quantity<units::unknown_dimension<units::exp<units::physical::si::dim_length, 2, 1>,
units::exp<units::physical::si::dim_time, -1, 1> >, units::unknown_coherent_unit, long int>
```


Expand Down
1 change: 1 addition & 0 deletions docs/design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Design Deep Dive
For brevity all the code examples in this chapter assume::

using namespace units;
using namespace units::physical;

.. toctree::
:maxdepth: 2
Expand Down
1 change: 1 addition & 0 deletions docs/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Framework Basics
For brevity all the code examples in this chapter assume::

using namespace units;
using namespace units::physical;

.. toctree::
:maxdepth: 2
Expand Down
8 changes: 4 additions & 4 deletions docs/framework/quantities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ values the library provides :abbr:`UDL (User Defined Literal)` s for each
:term:`unit` of every :term:`dimension`. Thanks to them the same code can
be as simple as::

using namespace si::literals;
using namespace units::physical::si::literals;
constexpr auto d1 = 123q_km; // si::length<si::kilometre, std::int64_t>
constexpr auto d2 = 123.q_km; // si::length<si::kilometre, long double>

Expand All @@ -66,7 +66,7 @@ In case the user does not care about the specific unit and representation but
requires quantity of a concrete dimension than dimension-specific concepts can
be used::

using namespace si::literals;
using namespace units::physical::si::literals;
constexpr Length auto d = 123q_km; // si::length<si::kilometre, std::int64_t>

.. note::
Expand All @@ -80,8 +80,8 @@ assume that the user wants to implement an ``avg_speed`` function that will
be calculating the average speed based on provided distance and duration
quantities. The usage of such a function can look as follows::

using namespace si::literals;
using namespace international::literals;
using namespace units::physical::si::literals;
using namespace units::physical::international::literals;
constexpr Velocity auto v1 = avg_speed(220q_km, 2q_h);
constexpr Velocity auto v2 = avg_speed(140q_mi, 2q_h);

Expand Down
4 changes: 2 additions & 2 deletions docs/framework/text_output.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Output Streams
The easiest way to print a quantity is to provide its object to the output
stream::

using namespace si::literals;
using namespace international::literals;
using namespace units::physical::si::literals;
using namespace units::physical::international::literals;
constexpr Velocity auto v1 = avg_speed(220.q_km, 2q_h);
constexpr Velocity auto v2 = avg_speed(140.q_mi, 2q_h);
std::cout << v1 << '\n'; // 110 km/h
Expand Down
6 changes: 3 additions & 3 deletions docs/framework/units.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ of ``N/m``):
:emphasize-lines: 2
struct dim_surface_tension : derived_dimension<dim_surface_tension, newton_per_metre,
exp<si::dim_force, 1>,
exp<si::dim_length, -1>> {}; // N/m
exp<si::dim_force, 1>,
exp<si::dim_length, -1>> {}; // N/m
If we defined the above in terms of base units we would end up with
a ``kg/s²`` derived unit symbol.
Expand Down Expand Up @@ -361,7 +361,7 @@ and user should not instantiate it by him/her-self. However the user can sometim
observe this type in case an unit/dimension conversion expression will end up with an
unknown/undefined unit type like in the below example::

using namespace si::literals;
using namespace units::physical::si::literals;

Length auto l = 100q_km_per_h * 10q_s;

Expand Down
4 changes: 2 additions & 2 deletions docs/quick_start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ of basic library features::
#include <units/physical/international/velocity.h>
#include <iostream>

using namespace units;
using namespace units::physical;

constexpr Velocity auto avg_speed(Length auto d, Time auto t)
{
Expand All @@ -41,7 +41,7 @@ of basic library features::

int main()
{
using namespace si::literals;
using namespace units::physical::si::literals;
Velocity auto v1 = avg_speed(220q_km, 2q_h);
Velocity auto v2 = avg_speed(si::length<international::mile>(140), si::time<si::hour>(2));
Velocity auto v3 = quantity_cast<si::metre_per_second>(v2);
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/systems.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Systems
SI
--

.. doxygennamespace:: units::si
.. doxygennamespace:: units::physical::si
:members:
:undoc-members:
:outline:
Expand Down
1 change: 1 addition & 0 deletions docs/use_cases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Use Cases
For brevity all the code examples in this chapter assume::

using namespace units;
using namespace units::physical;

.. toctree::
:maxdepth: 2
Expand Down
2 changes: 1 addition & 1 deletion docs/use_cases/legacy_interfaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pass it to the library's output:
#include "legacy.h"
#include <units/physical/si/velocity.h>
using namespace units;
using namespace units::physical;
constexpr Velocity auto avg_speed(Length auto d, Time auto t)
{
Expand Down
2 changes: 1 addition & 1 deletion example/alternative_namespaces/acceleration.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace experimental{
namespace acceleration {

template<typename Rep = double>
using m_per_s2 = units::si::acceleration<units::si::metre_per_second_sq, Rep>;
using m_per_s2 = units::physical::si::acceleration<units::physical::si::metre_per_second_sq, Rep>;

template<typename Rep = double>
constexpr m_per_s2<Rep> g{static_cast<Rep>(9.80665)};
Expand Down
4 changes: 2 additions & 2 deletions example/alternative_namespaces/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace area {

template<typename Rep = double>
using m2 = units::si::area<units::si::square_metre, Rep>;
using m2 = units::physical::si::area<units::physical::si::square_metre, Rep>;

template<typename Rep = double>
using fm2 = units::si::area<units::si::square_femtometre, Rep>;
using fm2 = units::physical::si::area<units::physical::si::square_femtometre, Rep>;

} // namespace area
2 changes: 1 addition & 1 deletion example/alternative_namespaces/box_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct Box {

#include <iostream>

using namespace units::si::literals;
using namespace units::physical::si::literals;

int main()
{
Expand Down
2 changes: 1 addition & 1 deletion example/alternative_namespaces/capacitor_time_curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <iostream>

using namespace units::experimental;
using namespace units::si::literals;
using namespace units::physical::si::literals;

int main()
{
Expand Down
4 changes: 2 additions & 2 deletions example/alternative_namespaces/clcpp_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include "./area.h"
#include "./units_str.h"

using namespace units::si::literals;
using namespace units::international;
using namespace units::physical::si::literals;
using namespace units::physical::international;
using namespace units::experimental;

void simple_quantities()
Expand Down
2 changes: 1 addition & 1 deletion example/alternative_namespaces/conversion_factor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ inline constexpr std::common_type_t<typename Target::rep, typename Source::rep>

} // namespace

using namespace units::si::literals;
using namespace units::physical::si::literals;
using namespace units::experimental;

int main()
Expand Down
2 changes: 1 addition & 1 deletion example/alternative_namespaces/density.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace experimental{
namespace density {

template<typename Rep = double>
using kg_per_m3 = units::si::density<units::si::kilogram_per_metre_cub, Rep>;
using kg_per_m3 = units::physical::si::density<units::physical::si::kilogram_per_metre_cub, Rep>;

}

Expand Down
2 changes: 1 addition & 1 deletion example/alternative_namespaces/force.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace experimental{
namespace force {

template<typename Rep = double>
using N = units::si::force<units::si::newton, Rep>;
using N = units::physical::si::force<units::physical::si::newton, Rep>;

}

Expand Down
44 changes: 22 additions & 22 deletions example/alternative_namespaces/length.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,70 +15,70 @@ namespace experimental{
namespace length {

template<typename Rep = double>
using m = units::si::length<units::si::metre, Rep>;
using m = units::physical::si::length<units::physical::si::metre, Rep>;

template<typename Rep = double>
using mm = units::si::length<units::si::millimetre, Rep>;
using mm = units::physical::si::length<units::physical::si::millimetre, Rep>;

template<typename Rep = double>
using fm = units::si::length<units::si::femtometre, Rep>;
using fm = units::physical::si::length<units::physical::si::femtometre, Rep>;

template<typename Rep = double>
using km = units::si::length<units::si::kilometre, Rep>;
using km = units::physical::si::length<units::physical::si::kilometre, Rep>;

template<typename Rep = double>
using AU = units::si::length<units::si::astronomical_unit, Rep>;
using AU = units::physical::si::length<units::physical::si::astronomical_unit, Rep>;

template<typename Rep = double>
using in = units::si::length<units::international::inch, Rep>;
using in = units::physical::si::length<units::physical::international::inch, Rep>;

template<typename Rep = double>
using angstrom = units::si::length<units::iau::angstrom, Rep>;
using angstrom = units::physical::si::length<units::physical::iau::angstrom, Rep>;

template<typename Rep = double>
using ch = units::si::length<units::imperial::chain, Rep>;
using ch = units::physical::si::length<units::physical::imperial::chain, Rep>;

template<typename Rep = double>
using fathom = units::si::length<units::international::fathom, Rep>;
using fathom = units::physical::si::length<units::physical::international::fathom, Rep>;

template<typename Rep = double>
using fathom_us = units::si::length<units::us::fathom, Rep>;
using fathom_us = units::physical::si::length<units::physical::us::fathom, Rep>;

template<typename Rep = double>
using ft = units::si::length<units::international::foot, Rep>;
using ft = units::physical::si::length<units::physical::international::foot, Rep>;

template<typename Rep = double>
using ft_us = units::si::length<units::us::foot, Rep>;
using ft_us = units::physical::si::length<units::physical::us::foot, Rep>;

template<typename Rep = double>
using ly = units::si::length<units::iau::light_year, Rep>;
using ly = units::physical::si::length<units::physical::iau::light_year, Rep>;

template<typename Rep = double>
using mi = units::si::length<units::international::mile, Rep>;
using mi = units::physical::si::length<units::physical::international::mile, Rep>;

template<typename Rep = double>
using mi_naut = units::si::length<units::international::nautical_mile, Rep>;
using mi_naut = units::physical::si::length<units::physical::international::nautical_mile, Rep>;

template<typename Rep = double>
using pc = units::si::length<units::iau::parsec, Rep>;
using pc = units::physical::si::length<units::physical::iau::parsec, Rep>;

template<typename Rep = double>
using pica_comp = units::si::length<units::typographic::pica_comp, Rep>;
using pica_comp = units::physical::si::length<units::physical::typographic::pica_comp, Rep>;

template<typename Rep = double>
using pica_prn = units::si::length<units::typographic::pica_prn, Rep>;
using pica_prn = units::physical::si::length<units::physical::typographic::pica_prn, Rep>;

template<typename Rep = double>
using point_comp = units::si::length<units::typographic::point_comp, Rep>;
using point_comp = units::physical::si::length<units::physical::typographic::point_comp, Rep>;

template<typename Rep = double>
using point_prn = units::si::length<units::typographic::point_prn, Rep>;
using point_prn = units::physical::si::length<units::physical::typographic::point_prn, Rep>;

template<typename Rep = double>
using rd = units::si::length<units::imperial::rod, Rep>;
using rd = units::physical::si::length<units::physical::imperial::rod, Rep>;

template<typename Rep = double>
using yd = units::si::length<units::international::yard, Rep>;
using yd = units::physical::si::length<units::physical::international::yard, Rep>;


} // namespace length
Expand Down
2 changes: 1 addition & 1 deletion example/alternative_namespaces/mass.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace experimental{
namespace mass {

template<typename Rep = double>
using kg = units::si::mass<units::si::kilogram, Rep>;
using kg = units::physical::si::mass<units::physical::si::kilogram, Rep>;

}

Expand Down
Loading

0 comments on commit 7e935a4

Please sign in to comment.