From a007162172020b36f481cf2258ccad0fd5410e42 Mon Sep 17 00:00:00 2001 From: Jeremy Lloyd Conlin Date: Mon, 29 Jun 2020 17:16:43 -0600 Subject: [PATCH 1/7] Trying to fix the map issue. --- src/constants/CODATA2014.hpp | 119 +++++++++++++-------------- src/constants/CODATA2018.hpp | 119 ++++++++++++++------------- src/constants/map.hpp | 37 +++++++-- src/constants/src/addUncertainty.hpp | 6 +- 4 files changed, 153 insertions(+), 128 deletions(-) diff --git a/src/constants/CODATA2014.hpp b/src/constants/CODATA2014.hpp index 1826019..e18edd3 100644 --- a/src/constants/CODATA2014.hpp +++ b/src/constants/CODATA2014.hpp @@ -6,70 +6,69 @@ namespace njoy { namespace constants { -static constexpr auto CODATA2014 = addUncertainty( - hana::make_map( - hana::make_pair( avogadro , 6.022140857e23/mole ), - hana::make_pair( boltzmann , 1.38064852e-23*joule/kelvin ), - hana::make_pair( conductanceQuantum, 7.7480917310e-5*siemens ), - hana::make_pair( electric, 8.854187817e-12*farad/meter ), - hana::make_pair( electronRadius, 2.8179403227e-15*meter ), - hana::make_pair( elementaryCharge, 1.6021766208e-19*coulomb ), - hana::make_pair( faraday, 9.648533289e4*coulomb/mole ), - hana::make_pair( fineStructure, 7.2973525664e-3*meter/meter ), - hana::make_pair( magnetic, 1.2566370614e-6*newton/ampere/ampere ), - hana::make_pair( magneticFluxQuantum, 2.067833831e-15*weber ), - hana::make_pair( molarGas, 8.3144598*joule/mole/kelvin ), - hana::make_pair( newtonianGravitation, - 6.67408e-11*meter*meter*meter/kilo( gram )/second/second ), - hana::make_pair( planck , 6.626070040e-34*joule*second ), - hana::make_pair( reducedPlanck, 1.054571800e-34*joule*second ), - hana::make_pair( rydberg, 1.0973731568508e7/meter ), - hana::make_pair( speedOfLight , 2.99792458e8*meter/second ), - hana::make_pair( stefanBoltzmann, - 5.670367e-8*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), +constexpr auto values = hana::make_map( + hana::make_pair( avogadro , 6.022140857e23/mole ), + hana::make_pair( boltzmann , 1.38064852e-23*joule/kelvin ), + hana::make_pair( conductanceQuantum, 7.7480917310e-5*siemens ), + hana::make_pair( electric, 8.854187817e-12*farad/meter ), + hana::make_pair( electronRadius, 2.8179403227e-15*meter ), + hana::make_pair( elementaryCharge, 1.6021766208e-19*coulomb ), + hana::make_pair( faraday, 9.648533289e4*coulomb/mole ), + hana::make_pair( fineStructure, 7.2973525664e-3*meter/meter ), + hana::make_pair( magnetic, 1.2566370614e-6*newton/ampere/ampere ), + hana::make_pair( magneticFluxQuantum, 2.067833831e-15*weber ), + hana::make_pair( molarGas, 8.3144598*joule/mole/kelvin ), + hana::make_pair( newtonianGravitation, + 6.67408e-11*meter*meter*meter/kilo( gram )/second/second ), + hana::make_pair( planck , 6.626070040e-34*joule*second ), + hana::make_pair( reducedPlanck, 1.054571800e-34*joule*second ), + hana::make_pair( rydberg, 1.0973731568508e7/meter ), + hana::make_pair( speedOfLight , 2.99792458e8*meter/second ), + hana::make_pair( stefanBoltzmann, + 5.670367e-8*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), - // Masses - hana::make_pair( electronMass , 9.10938356e-31*kilo( gram ) ), - hana::make_pair( neutronMass , 1.674927471e-27*kilo( gram ) ), - hana::make_pair( protonMass , 1.672621898e-27*kilo( gram ) ), - hana::make_pair( deuteronMass , 3.343583719e-27*kilo( gram ) ), - hana::make_pair( helionMass , 5.0064127000e-27*kilo( gram ) ), - hana::make_pair( tritonMass , 5.007356665e-27*kilo( gram ) ), - hana::make_pair( alphaMass , 6.644657230e-27*kilo( gram ) ) - ), + // Masses + hana::make_pair( electronMass , 9.10938356e-31*kilo( gram ) ), + hana::make_pair( neutronMass , 1.674927471e-27*kilo( gram ) ), + hana::make_pair( protonMass , 1.672621898e-27*kilo( gram ) ), + hana::make_pair( deuteronMass , 3.343583719e-27*kilo( gram ) ), + hana::make_pair( helionMass , 5.0064127000e-27*kilo( gram ) ), + hana::make_pair( tritonMass , 5.007356665e-27*kilo( gram ) ), + hana::make_pair( alphaMass , 6.644657230e-27*kilo( gram ) ) +); // Uncertainties - hana::make_map( - hana::make_pair( avogadro , 0.000000074e23/mole ), - hana::make_pair( boltzmann , 0.00000079e-23*joule/kelvin ), - hana::make_pair( conductanceQuantum, 1.8E-14*siemens ), - hana::make_pair( electric, 0.0*farad/meter ), - hana::make_pair( electronRadius, 1.9e-24*meter ), - hana::make_pair( elementaryCharge, 0.0000000098e-19*coulomb ), - hana::make_pair( faraday, 5.9e-4*coulomb/mole ), - hana::make_pair( fineStructure, 1.7e-12*meter/meter ), - hana::make_pair( magnetic, 0.0*newton/ampere/ampere ), - hana::make_pair( magneticFluxQuantum, 1.3e-23*weber ), - hana::make_pair( molarGas, 4.8e-6*joule/mole/kelvin ), - hana::make_pair( newtonianGravitation, - 0.00031e-11*meter*meter*meter/kilo( gram )/second/second ), - hana::make_pair( planck , 0.000000081e-34*joule*second ), - hana::make_pair( reducedPlanck, 0.000000013e-34*joule*second ), - hana::make_pair( rydberg, 6.5e-5/meter ), - hana::make_pair( speedOfLight , 0.0*meter/second ), - hana::make_pair( stefanBoltzmann, - 1.3e-13*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), +constexpr auto uncertainties = hana::make_map( + hana::make_pair( avogadro , 0.000000074e23/mole ), + hana::make_pair( boltzmann , 0.00000079e-23*joule/kelvin ), + hana::make_pair( conductanceQuantum, 1.8E-14*siemens ), + hana::make_pair( electric, 0.0*farad/meter ), + hana::make_pair( electronRadius, 1.9e-24*meter ), + hana::make_pair( elementaryCharge, 0.0000000098e-19*coulomb ), + hana::make_pair( faraday, 5.9e-4*coulomb/mole ), + hana::make_pair( fineStructure, 1.7e-12*meter/meter ), + hana::make_pair( magnetic, 0.0*newton/ampere/ampere ), + hana::make_pair( magneticFluxQuantum, 1.3e-23*weber ), + hana::make_pair( molarGas, 4.8e-6*joule/mole/kelvin ), + hana::make_pair( newtonianGravitation, + 0.00031e-11*meter*meter*meter/kilo( gram )/second/second ), + hana::make_pair( planck , 0.000000081e-34*joule*second ), + hana::make_pair( reducedPlanck, 0.000000013e-34*joule*second ), + hana::make_pair( rydberg, 6.5e-5/meter ), + hana::make_pair( speedOfLight , 0.0*meter/second ), + hana::make_pair( stefanBoltzmann, + 1.3e-13*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), - // Masses - hana::make_pair( electronMass , 0.00000011e-31*kilo( gram ) ), - hana::make_pair( neutronMass , 0.000000021e-27*kilo( gram ) ), - hana::make_pair( protonMass , 0.000000021e-27*kilo( gram ) ), - hana::make_pair( deuteronMass , 0.000000041e-27*kilo( gram ) ), - hana::make_pair( helionMass , 0.000000062e-27*kilo( gram ) ), - hana::make_pair( tritonMass , 0.000000062e-27*kilo( gram ) ), - hana::make_pair( alphaMass , 0.000000082e-27*kilo( gram ) ) - ) -); + // Masses + hana::make_pair( electronMass , 0.00000011e-31*kilo( gram ) ), + hana::make_pair( neutronMass , 0.000000021e-27*kilo( gram ) ), + hana::make_pair( protonMass , 0.000000021e-27*kilo( gram ) ), + hana::make_pair( deuteronMass , 0.000000041e-27*kilo( gram ) ), + hana::make_pair( helionMass , 0.000000062e-27*kilo( gram ) ), + hana::make_pair( tritonMass , 0.000000062e-27*kilo( gram ) ), + hana::make_pair( alphaMass , 0.000000082e-27*kilo( gram ) ) + ); +static constexpr auto CODATA2014 = map( values, uncertainties ); } // namespace constants } // namespace njoy #endif // NJOY_CONSTANTS_CODATA2014_HPP diff --git a/src/constants/CODATA2018.hpp b/src/constants/CODATA2018.hpp index e526d96..df00d63 100644 --- a/src/constants/CODATA2018.hpp +++ b/src/constants/CODATA2018.hpp @@ -6,70 +6,71 @@ namespace njoy { namespace constants { -static constexpr auto CODATA2018 = addUncertainty( - hana::make_map( - hana::make_pair( avogadro , 6.02214076e23/mole ), - hana::make_pair( boltzmann , 1.380649e-23*joule/kelvin ), - hana::make_pair( conductanceQuantum, 7.748091729e-5*siemens ), - hana::make_pair( electric, 8.8541878128e-12*farad/meter ), - hana::make_pair( electronRadius, 2.8179403262e-15*meter ), - hana::make_pair( elementaryCharge, 1.602176634e-19*coulomb ), - hana::make_pair( faraday, 9.648533212e4*coulomb/mole ), - hana::make_pair( fineStructure, 7.2973525693e-3*meter/meter ), - hana::make_pair( magnetic, 1.25663706212e-6*newton/ampere/ampere ), - hana::make_pair( magneticFluxQuantum, 2.067833848e-15*weber ), - hana::make_pair( molarGas, 8.314462618*joule/mole/kelvin ), - hana::make_pair( newtonianGravitation, - 6.67430e-11*meter*meter*meter/kilo( gram )/second/second ), - hana::make_pair( planck , 6.62607015e-34*joule*second ), - hana::make_pair( reducedPlanck, 1.054571817e-34*joule*second ), - hana::make_pair( rydberg, 1.0973731568160e7/meter ), - hana::make_pair( speedOfLight , 2.99792458e8*meter/second ), - hana::make_pair( stefanBoltzmann, - 5.670374419e-8*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), +static constexpr auto values = hana::make_map( + hana::make_pair( avogadro , 6.02214076e23/mole ), + hana::make_pair( boltzmann , 1.380649e-23*joule/kelvin ), + hana::make_pair( conductanceQuantum, 7.748091729e-5*siemens ), + hana::make_pair( electric, 8.8541878128e-12*farad/meter ), + hana::make_pair( electronRadius, 2.8179403262e-15*meter ), + hana::make_pair( elementaryCharge, 1.602176634e-19*coulomb ), + hana::make_pair( faraday, 9.648533212e4*coulomb/mole ), + hana::make_pair( fineStructure, 7.2973525693e-3*meter/meter ), + hana::make_pair( magnetic, 1.25663706212e-6*newton/ampere/ampere ), + hana::make_pair( magneticFluxQuantum, 2.067833848e-15*weber ), + hana::make_pair( molarGas, 8.314462618*joule/mole/kelvin ), + hana::make_pair( newtonianGravitation, + 6.67430e-11*meter*meter*meter/kilo( gram )/second/second ), + hana::make_pair( planck , 6.62607015e-34*joule*second ), + hana::make_pair( reducedPlanck, 1.054571817e-34*joule*second ), + hana::make_pair( rydberg, 1.0973731568160e7/meter ), + hana::make_pair( speedOfLight , 2.99792458e8*meter/second ), + hana::make_pair( stefanBoltzmann, + 5.670374419e-8*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), + + // Masses + hana::make_pair( electronMass , 9.1093837015e-31*kilo( gram ) ), + hana::make_pair( neutronMass , 1.67492749804e-27*kilo( gram ) ), + hana::make_pair( protonMass , 1.67262192369e-27*kilo( gram ) ), + hana::make_pair( deuteronMass , 3.3435837724e-27*kilo( gram ) ), + hana::make_pair( helionMass , 5.0064127796e-27*kilo( gram ) ), + hana::make_pair( tritonMass , 5.0073567446e-27*kilo( gram ) ), + hana::make_pair( alphaMass , 6.6446573357e-27*kilo( gram ) ) +); - // Masses - hana::make_pair( electronMass , 9.1093837015e-31*kilo( gram ) ), - hana::make_pair( neutronMass , 1.67492749804e-27*kilo( gram ) ), - hana::make_pair( protonMass , 1.67262192369e-27*kilo( gram ) ), - hana::make_pair( deuteronMass , 3.3435837724e-27*kilo( gram ) ), - hana::make_pair( helionMass , 5.0064127796e-27*kilo( gram ) ), - hana::make_pair( tritonMass , 5.0073567446e-27*kilo( gram ) ), - hana::make_pair( alphaMass , 6.6446573357e-27*kilo( gram ) ) - ), // Uncertainties - hana::make_map( - hana::make_pair( avogadro , 0.0/mole ), - hana::make_pair( boltzmann , 0.0*joule/kelvin ), - hana::make_pair( conductanceQuantum, 0.0*siemens ), - hana::make_pair( electric, 1.3e-21*farad/meter ), - hana::make_pair( electronRadius, 1.3e-24*meter ), - hana::make_pair( elementaryCharge, 0.0*coulomb ), - hana::make_pair( faraday, 0.0*coulomb/mole ), - hana::make_pair( fineStructure, 1.1e-12*meter/meter ), - hana::make_pair( magnetic, 1.9e-16*newton/ampere/ampere ), - hana::make_pair( magneticFluxQuantum, 0.0*weber ), - hana::make_pair( molarGas, 0.0*joule/mole/kelvin ), - hana::make_pair( newtonianGravitation, - 1.5e-15*meter*meter*meter/kilo( gram )/second/second ), - hana::make_pair( planck , 0.0*joule*second ), - hana::make_pair( reducedPlanck, 0.0*joule*second ), - hana::make_pair( rydberg, 2.1e-5/meter ), - hana::make_pair( speedOfLight , 0.0*meter/second ), - hana::make_pair( stefanBoltzmann, - 0.0*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), +static constexpr auto uncertainties = hana::make_map( + hana::make_pair( avogadro , 0.0/mole ), + hana::make_pair( boltzmann , 0.0*joule/kelvin ), + hana::make_pair( conductanceQuantum, 0.0*siemens ), + hana::make_pair( electric, 1.3e-21*farad/meter ), + hana::make_pair( electronRadius, 1.3e-24*meter ), + hana::make_pair( elementaryCharge, 0.0*coulomb ), + hana::make_pair( faraday, 0.0*coulomb/mole ), + hana::make_pair( fineStructure, 1.1e-12*meter/meter ), + hana::make_pair( magnetic, 1.9e-16*newton/ampere/ampere ), + hana::make_pair( magneticFluxQuantum, 0.0*weber ), + hana::make_pair( molarGas, 0.0*joule/mole/kelvin ), + hana::make_pair( newtonianGravitation, + 1.5e-15*meter*meter*meter/kilo( gram )/second/second ), + hana::make_pair( planck , 0.0*joule*second ), + hana::make_pair( reducedPlanck, 0.0*joule*second ), + hana::make_pair( rydberg, 2.1e-5/meter ), + hana::make_pair( speedOfLight , 0.0*meter/second ), + hana::make_pair( stefanBoltzmann, + 0.0*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), - // Masses - hana::make_pair( electronMass , 0.0000000028e-31*kilo( gram ) ), - hana::make_pair( neutronMass , 0.00000000095e-27*kilo( gram ) ), - hana::make_pair( protonMass , 0.00000000051e-27*kilo( gram ) ), - hana::make_pair( deuteronMass , 0.0000000010e-27*kilo( gram ) ), - hana::make_pair( helionMass , 0.0000000015e-27*kilo( gram ) ), - hana::make_pair( tritonMass , 0.0000000015e-27*kilo( gram ) ), - hana::make_pair( alphaMass , 0.0000000020e-27*kilo( gram ) ) - ) + // Masses + hana::make_pair( electronMass , 0.0000000028e-31*kilo( gram ) ), + hana::make_pair( neutronMass , 0.00000000095e-27*kilo( gram ) ), + hana::make_pair( protonMass , 0.00000000051e-27*kilo( gram ) ), + hana::make_pair( deuteronMass , 0.0000000010e-27*kilo( gram ) ), + hana::make_pair( helionMass , 0.0000000015e-27*kilo( gram ) ), + hana::make_pair( tritonMass , 0.0000000015e-27*kilo( gram ) ), + hana::make_pair( alphaMass , 0.0000000020e-27*kilo( gram ) ) ); +static constexpr auto CODATA2018 = map( values, uncertainties ); + } // namespace constants } // namespace njoy #endif // NJOY_CONSTANTS_CODATA2018_HPP diff --git a/src/constants/map.hpp b/src/constants/map.hpp index 2c6a2ad..fcb686f 100644 --- a/src/constants/map.hpp +++ b/src/constants/map.hpp @@ -1,8 +1,33 @@ -template< typename Base1, typename Base2 > -struct map: Base1{ - Base2 uncertainty; - constexpr map(Base1 b1, Base2 b2 ): - Base1( b1 ), - uncertainty( b2 ) +template< typename Values, typename Uncertainty > +struct map{ +private: + Values values; +public: + Uncertainty uncertainty; + + constexpr map(Values v, Uncertainty u ): + Values( v ), + uncertainty( u ) { } + +template + constexpr decltype(auto) operator[](Key&& key) & { + return static_cast(values)[ + std::forward(key)]; + } + template + constexpr decltype(auto) operator[](Key&& key) && { + return static_cast(values)[ + std::forward(key)]; + } + template + constexpr decltype(auto) operator[](Key&& key) const& { + return static_cast(values)[ + std::forward(key)]; + } }; + +// Deduction guide +template< typename Values, typename Keys > +map( Values values, Keys keys ) -> map< Values, Keys >; + diff --git a/src/constants/src/addUncertainty.hpp b/src/constants/src/addUncertainty.hpp index afcfd37..1faf5c4 100644 --- a/src/constants/src/addUncertainty.hpp +++ b/src/constants/src/addUncertainty.hpp @@ -1,4 +1,4 @@ -template< typename Base1, typename Base2 > -constexpr auto addUncertainty(Base1 values, Base2 uncertainty ) { - return map< Base1, Base2 >( values, uncertainty ); +template< typename Values, typename Uncertainty > +constexpr auto addUncertainty(Values&& values, Uncertainty&& uncertainty ) { + return map< Values, Uncertainty >( values, uncertainty ); } From a3bfb0c07364ccb6e3bd3906322fc12d6ee49fa7 Mon Sep 17 00:00:00 2001 From: Jeremy Lloyd Conlin Date: Mon, 29 Jun 2020 20:12:58 -0600 Subject: [PATCH 2/7] Fixing the map. Now I just need to fix the keys. --- src/constants.hpp | 1 - src/constants/CODATA2014.hpp | 3 +- .../CODATA2014/test/CODATA2014.test.cpp | 5 +- src/constants/CODATA2018.hpp | 114 +++++++++--------- .../CODATA2018/test/CODATA2018.test.cpp | 94 ++++++++------- src/constants/map.hpp | 10 +- src/constants/src/addUncertainty.hpp | 4 - 7 files changed, 114 insertions(+), 117 deletions(-) delete mode 100644 src/constants/src/addUncertainty.hpp diff --git a/src/constants.hpp b/src/constants.hpp index 441a2df..170f208 100644 --- a/src/constants.hpp +++ b/src/constants.hpp @@ -12,7 +12,6 @@ namespace constants { #include "constants/math.hpp" #include "constants/tags.hpp" #include "constants/map.hpp" -#include "constants/src/addUncertainty.hpp" } // namespace constants } // namespace njoy diff --git a/src/constants/CODATA2014.hpp b/src/constants/CODATA2014.hpp index e18edd3..ac8ba79 100644 --- a/src/constants/CODATA2014.hpp +++ b/src/constants/CODATA2014.hpp @@ -68,7 +68,8 @@ constexpr auto uncertainties = hana::make_map( hana::make_pair( alphaMass , 0.000000082e-27*kilo( gram ) ) ); -static constexpr auto CODATA2014 = map( values, uncertainties ); +static constexpr auto CODATA2014 = Map_t( values, uncertainties ); + } // namespace constants } // namespace njoy #endif // NJOY_CONSTANTS_CODATA2014_HPP diff --git a/src/constants/CODATA2014/test/CODATA2014.test.cpp b/src/constants/CODATA2014/test/CODATA2014.test.cpp index 59eb1b3..8c0e11e 100644 --- a/src/constants/CODATA2014/test/CODATA2014.test.cpp +++ b/src/constants/CODATA2014/test/CODATA2014.test.cpp @@ -42,8 +42,7 @@ auto stringFor = hana::make_map( hana::make_pair( alphaMass, std::string{ "alpha particle mass" } ) ); -template< typename MAP > -void checkMap( MAP& map ){ +void checkMap( Map_t& map ){ auto referenceValues = testing::defineReferenceValues( std::ifstream("CODATA2014.txt") ); @@ -64,7 +63,7 @@ SCENARIO("test all the constants"){ checkMap( CODATA2014 ); - auto aliasMap = addUncertainty( + auto aliasMap = Map_t( hana::make_map( hana::make_pair( k, CODATA2014[ k ] ), hana::make_pair( h, CODATA2014[ h ] ), diff --git a/src/constants/CODATA2018.hpp b/src/constants/CODATA2018.hpp index df00d63..cbbe452 100644 --- a/src/constants/CODATA2018.hpp +++ b/src/constants/CODATA2018.hpp @@ -6,70 +6,70 @@ namespace njoy { namespace constants { -static constexpr auto values = hana::make_map( - hana::make_pair( avogadro , 6.02214076e23/mole ), - hana::make_pair( boltzmann , 1.380649e-23*joule/kelvin ), - hana::make_pair( conductanceQuantum, 7.748091729e-5*siemens ), - hana::make_pair( electric, 8.8541878128e-12*farad/meter ), - hana::make_pair( electronRadius, 2.8179403262e-15*meter ), - hana::make_pair( elementaryCharge, 1.602176634e-19*coulomb ), - hana::make_pair( faraday, 9.648533212e4*coulomb/mole ), - hana::make_pair( fineStructure, 7.2973525693e-3*meter/meter ), - hana::make_pair( magnetic, 1.25663706212e-6*newton/ampere/ampere ), - hana::make_pair( magneticFluxQuantum, 2.067833848e-15*weber ), - hana::make_pair( molarGas, 8.314462618*joule/mole/kelvin ), - hana::make_pair( newtonianGravitation, - 6.67430e-11*meter*meter*meter/kilo( gram )/second/second ), - hana::make_pair( planck , 6.62607015e-34*joule*second ), - hana::make_pair( reducedPlanck, 1.054571817e-34*joule*second ), - hana::make_pair( rydberg, 1.0973731568160e7/meter ), - hana::make_pair( speedOfLight , 2.99792458e8*meter/second ), - hana::make_pair( stefanBoltzmann, - 5.670374419e-8*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), +auto values = hana::make_map( + hana::make_pair( avogadro , 6.02214076e23/mole ) + // hana::make_pair( boltzmann , 1.380649e-23*joule/kelvin ), + // hana::make_pair( conductanceQuantum, 7.748091729e-5*siemens ), + // hana::make_pair( electric, 8.8541878128e-12*farad/meter ), + // hana::make_pair( electronRadius, 2.8179403262e-15*meter ), + // hana::make_pair( elementaryCharge, 1.602176634e-19*coulomb ), + // hana::make_pair( faraday, 9.648533212e4*coulomb/mole ), + // hana::make_pair( fineStructure, 7.2973525693e-3*meter/meter ), + // hana::make_pair( magnetic, 1.25663706212e-6*newton/ampere/ampere ), + // hana::make_pair( magneticFluxQuantum, 2.067833848e-15*weber ), + // hana::make_pair( molarGas, 8.314462618*joule/mole/kelvin ), + // hana::make_pair( newtonianGravitation, + // 6.67430e-11*meter*meter*meter/kilo( gram )/second/second ), + // hana::make_pair( planck , 6.62607015e-34*joule*second ), + // hana::make_pair( reducedPlanck, 1.054571817e-34*joule*second ), + // hana::make_pair( rydberg, 1.0973731568160e7/meter ), + // hana::make_pair( speedOfLight , 2.99792458e8*meter/second ), + // hana::make_pair( stefanBoltzmann, + // 5.670374419e-8*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), - // Masses - hana::make_pair( electronMass , 9.1093837015e-31*kilo( gram ) ), - hana::make_pair( neutronMass , 1.67492749804e-27*kilo( gram ) ), - hana::make_pair( protonMass , 1.67262192369e-27*kilo( gram ) ), - hana::make_pair( deuteronMass , 3.3435837724e-27*kilo( gram ) ), - hana::make_pair( helionMass , 5.0064127796e-27*kilo( gram ) ), - hana::make_pair( tritonMass , 5.0073567446e-27*kilo( gram ) ), - hana::make_pair( alphaMass , 6.6446573357e-27*kilo( gram ) ) + // // Masses + // hana::make_pair( electronMass , 9.1093837015e-31*kilo( gram ) ), + // hana::make_pair( neutronMass , 1.67492749804e-27*kilo( gram ) ), + // hana::make_pair( protonMass , 1.67262192369e-27*kilo( gram ) ), + // hana::make_pair( deuteronMass , 3.3435837724e-27*kilo( gram ) ), + // hana::make_pair( helionMass , 5.0064127796e-27*kilo( gram ) ), + // hana::make_pair( tritonMass , 5.0073567446e-27*kilo( gram ) ), + // hana::make_pair( alphaMass , 6.6446573357e-27*kilo( gram ) ) ); // Uncertainties -static constexpr auto uncertainties = hana::make_map( - hana::make_pair( avogadro , 0.0/mole ), - hana::make_pair( boltzmann , 0.0*joule/kelvin ), - hana::make_pair( conductanceQuantum, 0.0*siemens ), - hana::make_pair( electric, 1.3e-21*farad/meter ), - hana::make_pair( electronRadius, 1.3e-24*meter ), - hana::make_pair( elementaryCharge, 0.0*coulomb ), - hana::make_pair( faraday, 0.0*coulomb/mole ), - hana::make_pair( fineStructure, 1.1e-12*meter/meter ), - hana::make_pair( magnetic, 1.9e-16*newton/ampere/ampere ), - hana::make_pair( magneticFluxQuantum, 0.0*weber ), - hana::make_pair( molarGas, 0.0*joule/mole/kelvin ), - hana::make_pair( newtonianGravitation, - 1.5e-15*meter*meter*meter/kilo( gram )/second/second ), - hana::make_pair( planck , 0.0*joule*second ), - hana::make_pair( reducedPlanck, 0.0*joule*second ), - hana::make_pair( rydberg, 2.1e-5/meter ), - hana::make_pair( speedOfLight , 0.0*meter/second ), - hana::make_pair( stefanBoltzmann, - 0.0*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), +auto uncertainties = hana::make_map( + hana::make_pair( avogadro , 0.0/mole ) + // hana::make_pair( boltzmann , 0.0*joule/kelvin ), + // hana::make_pair( conductanceQuantum, 0.0*siemens ), + // hana::make_pair( electric, 1.3e-21*farad/meter ), + // hana::make_pair( electronRadius, 1.3e-24*meter ), + // hana::make_pair( elementaryCharge, 0.0*coulomb ), + // hana::make_pair( faraday, 0.0*coulomb/mole ), + // hana::make_pair( fineStructure, 1.1e-12*meter/meter ), + // hana::make_pair( magnetic, 1.9e-16*newton/ampere/ampere ), + // hana::make_pair( magneticFluxQuantum, 0.0*weber ), + // hana::make_pair( molarGas, 0.0*joule/mole/kelvin ), + // hana::make_pair( newtonianGravitation, + // 1.5e-15*meter*meter*meter/kilo( gram )/second/second ), + // hana::make_pair( planck , 0.0*joule*second ), + // hana::make_pair( reducedPlanck, 0.0*joule*second ), + // hana::make_pair( rydberg, 2.1e-5/meter ), + // hana::make_pair( speedOfLight , 0.0*meter/second ), + // hana::make_pair( stefanBoltzmann, + // 0.0*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), - // Masses - hana::make_pair( electronMass , 0.0000000028e-31*kilo( gram ) ), - hana::make_pair( neutronMass , 0.00000000095e-27*kilo( gram ) ), - hana::make_pair( protonMass , 0.00000000051e-27*kilo( gram ) ), - hana::make_pair( deuteronMass , 0.0000000010e-27*kilo( gram ) ), - hana::make_pair( helionMass , 0.0000000015e-27*kilo( gram ) ), - hana::make_pair( tritonMass , 0.0000000015e-27*kilo( gram ) ), - hana::make_pair( alphaMass , 0.0000000020e-27*kilo( gram ) ) + // // Masses + // hana::make_pair( electronMass , 0.0000000028e-31*kilo( gram ) ), + // hana::make_pair( neutronMass , 0.00000000095e-27*kilo( gram ) ), + // hana::make_pair( protonMass , 0.00000000051e-27*kilo( gram ) ), + // hana::make_pair( deuteronMass , 0.0000000010e-27*kilo( gram ) ), + // hana::make_pair( helionMass , 0.0000000015e-27*kilo( gram ) ), + // hana::make_pair( tritonMass , 0.0000000015e-27*kilo( gram ) ), + // hana::make_pair( alphaMass , 0.0000000020e-27*kilo( gram ) ) ); -static constexpr auto CODATA2018 = map( values, uncertainties ); +auto CODATA2018 = Map_t( values, uncertainties ); } // namespace constants } // namespace njoy diff --git a/src/constants/CODATA2018/test/CODATA2018.test.cpp b/src/constants/CODATA2018/test/CODATA2018.test.cpp index a2fd70e..9382ed2 100644 --- a/src/constants/CODATA2018/test/CODATA2018.test.cpp +++ b/src/constants/CODATA2018/test/CODATA2018.test.cpp @@ -13,33 +13,33 @@ using namespace njoy::constants; using namespace dimwits; auto stringFor = hana::make_map( - hana::make_pair( avogadro, std::string{ "Avogadro constant" } ), - hana::make_pair( boltzmann, std::string{ "Boltzmann constant" } ), - hana::make_pair( electric, std::string{ "vacuum electric permittivity" } ), - hana::make_pair( electronRadius, std::string{ "classical electron radius" } ), - hana::make_pair( elementaryCharge, std::string{ "elementary charge" } ), - hana::make_pair( faraday, std::string{ "Faraday constant" } ), - hana::make_pair( fineStructure, std::string{ "fine-structure constant" } ), - hana::make_pair( conductanceQuantum, std::string{ "conductance quantum" } ), - hana::make_pair( magnetic, std::string{ "vacuum mag. permeability" } ), - hana::make_pair( magneticFluxQuantum, std::string{ "mag. flux quantum" } ), - hana::make_pair( molarGas, std::string{ "molar gas constant" } ), - hana::make_pair( newtonianGravitation, - std::string{ "Newtonian constant of gravitation" } ), - hana::make_pair( planck, std::string{ "Planck constant" } ), - hana::make_pair( reducedPlanck, std::string{ "reduced Planck constant" } ), - hana::make_pair( rydberg, std::string{ "Rydberg constant" } ), - hana::make_pair( speedOfLight, std::string{ "speed of light in vacuum" } ), - hana::make_pair( stefanBoltzmann, std::string{ "Stefan-Boltzmann constant" } ), + hana::make_pair( avogadro, std::string{ "Avogadro constant" } ) + // hana::make_pair( boltzmann, std::string{ "Boltzmann constant" } ), + // hana::make_pair( electric, std::string{ "vacuum electric permittivity" } ), + // hana::make_pair( electronRadius, std::string{ "classical electron radius" } ), + // hana::make_pair( elementaryCharge, std::string{ "elementary charge" } ), + // hana::make_pair( faraday, std::string{ "Faraday constant" } ), + // hana::make_pair( fineStructure, std::string{ "fine-structure constant" } ), + // hana::make_pair( conductanceQuantum, std::string{ "conductance quantum" } ), + // hana::make_pair( magnetic, std::string{ "vacuum mag. permeability" } ), + // hana::make_pair( magneticFluxQuantum, std::string{ "mag. flux quantum" } ), + // hana::make_pair( molarGas, std::string{ "molar gas constant" } ), + // hana::make_pair( newtonianGravitation, + // std::string{ "Newtonian constant of gravitation" } ), + // hana::make_pair( planck, std::string{ "Planck constant" } ), + // hana::make_pair( reducedPlanck, std::string{ "reduced Planck constant" } ), + // hana::make_pair( rydberg, std::string{ "Rydberg constant" } ), + // hana::make_pair( speedOfLight, std::string{ "speed of light in vacuum" } ), + // hana::make_pair( stefanBoltzmann, std::string{ "Stefan-Boltzmann constant" } ), - // Masses - hana::make_pair( electronMass, std::string{ "electron mass" } ), - hana::make_pair( neutronMass, std::string{ "neutron mass" } ), - hana::make_pair( protonMass, std::string{ "proton mass" } ), - hana::make_pair( deuteronMass, std::string{ "deuteron mass" } ), - hana::make_pair( helionMass, std::string{ "helion mass" } ), - hana::make_pair( tritonMass, std::string{ "triton mass" } ), - hana::make_pair( alphaMass, std::string{ "alpha particle mass" } ) + // // Masses + // hana::make_pair( electronMass, std::string{ "electron mass" } ), + // hana::make_pair( neutronMass, std::string{ "neutron mass" } ), + // hana::make_pair( protonMass, std::string{ "proton mass" } ), + // hana::make_pair( deuteronMass, std::string{ "deuteron mass" } ), + // hana::make_pair( helionMass, std::string{ "helion mass" } ), + // hana::make_pair( tritonMass, std::string{ "triton mass" } ), + // hana::make_pair( alphaMass, std::string{ "alpha particle mass" } ) ); template< typename MAP > @@ -47,7 +47,9 @@ void checkMap( MAP& map ){ auto referenceValues = testing::defineReferenceValues( std::ifstream("CODATA2018.txt") ); - hana::for_each( hana::keys( map ), + auto keys = hana::keys( map ); + hana::for_each( + keys, [&]( auto&& key ){ auto refKey = stringFor[ key ]; @@ -62,26 +64,26 @@ void checkMap( MAP& map ){ SCENARIO("test all the constants"){ - checkMap( CODATA2018 ); + // checkMap( CODATA2018 ); - auto aliasMap = addUncertainty( - hana::make_map( - hana::make_pair( k, CODATA2018[ k ] ), - hana::make_pair( h, CODATA2018[ h ] ), - hana::make_pair( hbar, CODATA2018[ hbar ] ), - hana::make_pair( G, CODATA2018[ G ] ), - hana::make_pair( c, CODATA2018[ c ] ) - ), + // auto aliasMap = Map_t( + // hana::make_map( + // hana::make_pair( k, CODATA2018[ k ] ), + // hana::make_pair( h, CODATA2018[ h ] ), + // hana::make_pair( hbar, CODATA2018[ hbar ] ), + // hana::make_pair( G, CODATA2018[ G ] ), + // hana::make_pair( c, CODATA2018[ c ] ) + // ), - // Uncertainties - hana::make_map( - hana::make_pair( k, CODATA2018.uncertainty[ k ] ), - hana::make_pair( h, CODATA2018.uncertainty[ h ] ), - hana::make_pair( hbar, CODATA2018.uncertainty[ hbar ] ), - hana::make_pair( G, CODATA2018.uncertainty[ G ] ), - hana::make_pair( c, CODATA2018.uncertainty[ c ] ) - ) - ); + // // Uncertainties + // hana::make_map( + // hana::make_pair( k, CODATA2018.uncertainty[ k ] ), + // hana::make_pair( h, CODATA2018.uncertainty[ h ] ), + // hana::make_pair( hbar, CODATA2018.uncertainty[ hbar ] ), + // hana::make_pair( G, CODATA2018.uncertainty[ G ] ), + // hana::make_pair( c, CODATA2018.uncertainty[ c ] ) + // ) + // ); - checkMap( aliasMap ); + // checkMap( aliasMap ); } diff --git a/src/constants/map.hpp b/src/constants/map.hpp index fcb686f..ff01718 100644 --- a/src/constants/map.hpp +++ b/src/constants/map.hpp @@ -1,16 +1,16 @@ template< typename Values, typename Uncertainty > -struct map{ +struct Map_t{ private: Values values; public: Uncertainty uncertainty; - constexpr map(Values v, Uncertainty u ): - Values( v ), + constexpr Map_t( Values v, Uncertainty u ): + values( v ), uncertainty( u ) { } -template + template constexpr decltype(auto) operator[](Key&& key) & { return static_cast(values)[ std::forward(key)]; @@ -29,5 +29,5 @@ template // Deduction guide template< typename Values, typename Keys > -map( Values values, Keys keys ) -> map< Values, Keys >; +Map_t( Values values, Keys keys ) -> Map_t< Values, Keys >; diff --git a/src/constants/src/addUncertainty.hpp b/src/constants/src/addUncertainty.hpp deleted file mode 100644 index 1faf5c4..0000000 --- a/src/constants/src/addUncertainty.hpp +++ /dev/null @@ -1,4 +0,0 @@ -template< typename Values, typename Uncertainty > -constexpr auto addUncertainty(Values&& values, Uncertainty&& uncertainty ) { - return map< Values, Uncertainty >( values, uncertainty ); -} From ef9e5805c2f2bf8698f72de7aa2d804068cf35f8 Mon Sep 17 00:00:00 2001 From: Jeremy Lloyd Conlin Date: Mon, 29 Jun 2020 20:29:06 -0600 Subject: [PATCH 3/7] Everything is fixed --- src/constants/CODATA2014.hpp | 4 +- .../CODATA2014/test/CODATA2014.test.cpp | 5 +- src/constants/CODATA2018.hpp | 114 +++++++++--------- .../CODATA2018/test/CODATA2018.test.cpp | 92 +++++++------- src/constants/map.hpp | 20 ++- 5 files changed, 116 insertions(+), 119 deletions(-) diff --git a/src/constants/CODATA2014.hpp b/src/constants/CODATA2014.hpp index ac8ba79..977465e 100644 --- a/src/constants/CODATA2014.hpp +++ b/src/constants/CODATA2014.hpp @@ -6,7 +6,7 @@ namespace njoy { namespace constants { -constexpr auto values = hana::make_map( +static constexpr auto values = hana::make_map( hana::make_pair( avogadro , 6.022140857e23/mole ), hana::make_pair( boltzmann , 1.38064852e-23*joule/kelvin ), hana::make_pair( conductanceQuantum, 7.7480917310e-5*siemens ), @@ -37,7 +37,7 @@ constexpr auto values = hana::make_map( hana::make_pair( alphaMass , 6.644657230e-27*kilo( gram ) ) ); // Uncertainties -constexpr auto uncertainties = hana::make_map( +static constexpr auto uncertainties = hana::make_map( hana::make_pair( avogadro , 0.000000074e23/mole ), hana::make_pair( boltzmann , 0.00000079e-23*joule/kelvin ), hana::make_pair( conductanceQuantum, 1.8E-14*siemens ), diff --git a/src/constants/CODATA2014/test/CODATA2014.test.cpp b/src/constants/CODATA2014/test/CODATA2014.test.cpp index 8c0e11e..94335e5 100644 --- a/src/constants/CODATA2014/test/CODATA2014.test.cpp +++ b/src/constants/CODATA2014/test/CODATA2014.test.cpp @@ -42,11 +42,12 @@ auto stringFor = hana::make_map( hana::make_pair( alphaMass, std::string{ "alpha particle mass" } ) ); -void checkMap( Map_t& map ){ +template< typename MAP > +void checkMap( MAP& map ){ auto referenceValues = testing::defineReferenceValues( std::ifstream("CODATA2014.txt") ); - hana::for_each( hana::keys( map ), + hana::for_each( hana::keys( map.value ), [&]( auto&& key ){ auto refKey = stringFor[ key ]; diff --git a/src/constants/CODATA2018.hpp b/src/constants/CODATA2018.hpp index cbbe452..845c594 100644 --- a/src/constants/CODATA2018.hpp +++ b/src/constants/CODATA2018.hpp @@ -6,70 +6,70 @@ namespace njoy { namespace constants { -auto values = hana::make_map( - hana::make_pair( avogadro , 6.02214076e23/mole ) - // hana::make_pair( boltzmann , 1.380649e-23*joule/kelvin ), - // hana::make_pair( conductanceQuantum, 7.748091729e-5*siemens ), - // hana::make_pair( electric, 8.8541878128e-12*farad/meter ), - // hana::make_pair( electronRadius, 2.8179403262e-15*meter ), - // hana::make_pair( elementaryCharge, 1.602176634e-19*coulomb ), - // hana::make_pair( faraday, 9.648533212e4*coulomb/mole ), - // hana::make_pair( fineStructure, 7.2973525693e-3*meter/meter ), - // hana::make_pair( magnetic, 1.25663706212e-6*newton/ampere/ampere ), - // hana::make_pair( magneticFluxQuantum, 2.067833848e-15*weber ), - // hana::make_pair( molarGas, 8.314462618*joule/mole/kelvin ), - // hana::make_pair( newtonianGravitation, - // 6.67430e-11*meter*meter*meter/kilo( gram )/second/second ), - // hana::make_pair( planck , 6.62607015e-34*joule*second ), - // hana::make_pair( reducedPlanck, 1.054571817e-34*joule*second ), - // hana::make_pair( rydberg, 1.0973731568160e7/meter ), - // hana::make_pair( speedOfLight , 2.99792458e8*meter/second ), - // hana::make_pair( stefanBoltzmann, - // 5.670374419e-8*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), +static constexpr auto values = hana::make_map( + hana::make_pair( avogadro , 6.02214076e23/mole ), + hana::make_pair( boltzmann , 1.380649e-23*joule/kelvin ), + hana::make_pair( conductanceQuantum, 7.748091729e-5*siemens ), + hana::make_pair( electric, 8.8541878128e-12*farad/meter ), + hana::make_pair( electronRadius, 2.8179403262e-15*meter ), + hana::make_pair( elementaryCharge, 1.602176634e-19*coulomb ), + hana::make_pair( faraday, 9.648533212e4*coulomb/mole ), + hana::make_pair( fineStructure, 7.2973525693e-3*meter/meter ), + hana::make_pair( magnetic, 1.25663706212e-6*newton/ampere/ampere ), + hana::make_pair( magneticFluxQuantum, 2.067833848e-15*weber ), + hana::make_pair( molarGas, 8.314462618*joule/mole/kelvin ), + hana::make_pair( newtonianGravitation, + 6.67430e-11*meter*meter*meter/kilo( gram )/second/second ), + hana::make_pair( planck , 6.62607015e-34*joule*second ), + hana::make_pair( reducedPlanck, 1.054571817e-34*joule*second ), + hana::make_pair( rydberg, 1.0973731568160e7/meter ), + hana::make_pair( speedOfLight , 2.99792458e8*meter/second ), + hana::make_pair( stefanBoltzmann, + 5.670374419e-8*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), - // // Masses - // hana::make_pair( electronMass , 9.1093837015e-31*kilo( gram ) ), - // hana::make_pair( neutronMass , 1.67492749804e-27*kilo( gram ) ), - // hana::make_pair( protonMass , 1.67262192369e-27*kilo( gram ) ), - // hana::make_pair( deuteronMass , 3.3435837724e-27*kilo( gram ) ), - // hana::make_pair( helionMass , 5.0064127796e-27*kilo( gram ) ), - // hana::make_pair( tritonMass , 5.0073567446e-27*kilo( gram ) ), - // hana::make_pair( alphaMass , 6.6446573357e-27*kilo( gram ) ) + // Masses + hana::make_pair( electronMass , 9.1093837015e-31*kilo( gram ) ), + hana::make_pair( neutronMass , 1.67492749804e-27*kilo( gram ) ), + hana::make_pair( protonMass , 1.67262192369e-27*kilo( gram ) ), + hana::make_pair( deuteronMass , 3.3435837724e-27*kilo( gram ) ), + hana::make_pair( helionMass , 5.0064127796e-27*kilo( gram ) ), + hana::make_pair( tritonMass , 5.0073567446e-27*kilo( gram ) ), + hana::make_pair( alphaMass , 6.6446573357e-27*kilo( gram ) ) ); // Uncertainties -auto uncertainties = hana::make_map( - hana::make_pair( avogadro , 0.0/mole ) - // hana::make_pair( boltzmann , 0.0*joule/kelvin ), - // hana::make_pair( conductanceQuantum, 0.0*siemens ), - // hana::make_pair( electric, 1.3e-21*farad/meter ), - // hana::make_pair( electronRadius, 1.3e-24*meter ), - // hana::make_pair( elementaryCharge, 0.0*coulomb ), - // hana::make_pair( faraday, 0.0*coulomb/mole ), - // hana::make_pair( fineStructure, 1.1e-12*meter/meter ), - // hana::make_pair( magnetic, 1.9e-16*newton/ampere/ampere ), - // hana::make_pair( magneticFluxQuantum, 0.0*weber ), - // hana::make_pair( molarGas, 0.0*joule/mole/kelvin ), - // hana::make_pair( newtonianGravitation, - // 1.5e-15*meter*meter*meter/kilo( gram )/second/second ), - // hana::make_pair( planck , 0.0*joule*second ), - // hana::make_pair( reducedPlanck, 0.0*joule*second ), - // hana::make_pair( rydberg, 2.1e-5/meter ), - // hana::make_pair( speedOfLight , 0.0*meter/second ), - // hana::make_pair( stefanBoltzmann, - // 0.0*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), +static constexpr auto uncertainties = hana::make_map( + hana::make_pair( avogadro , 0.0/mole ), + hana::make_pair( boltzmann , 0.0*joule/kelvin ), + hana::make_pair( conductanceQuantum, 0.0*siemens ), + hana::make_pair( electric, 1.3e-21*farad/meter ), + hana::make_pair( electronRadius, 1.3e-24*meter ), + hana::make_pair( elementaryCharge, 0.0*coulomb ), + hana::make_pair( faraday, 0.0*coulomb/mole ), + hana::make_pair( fineStructure, 1.1e-12*meter/meter ), + hana::make_pair( magnetic, 1.9e-16*newton/ampere/ampere ), + hana::make_pair( magneticFluxQuantum, 0.0*weber ), + hana::make_pair( molarGas, 0.0*joule/mole/kelvin ), + hana::make_pair( newtonianGravitation, + 1.5e-15*meter*meter*meter/kilo( gram )/second/second ), + hana::make_pair( planck , 0.0*joule*second ), + hana::make_pair( reducedPlanck, 0.0*joule*second ), + hana::make_pair( rydberg, 2.1e-5/meter ), + hana::make_pair( speedOfLight , 0.0*meter/second ), + hana::make_pair( stefanBoltzmann, + 0.0*watt/meter/meter/kelvin/kelvin/kelvin/kelvin ), - // // Masses - // hana::make_pair( electronMass , 0.0000000028e-31*kilo( gram ) ), - // hana::make_pair( neutronMass , 0.00000000095e-27*kilo( gram ) ), - // hana::make_pair( protonMass , 0.00000000051e-27*kilo( gram ) ), - // hana::make_pair( deuteronMass , 0.0000000010e-27*kilo( gram ) ), - // hana::make_pair( helionMass , 0.0000000015e-27*kilo( gram ) ), - // hana::make_pair( tritonMass , 0.0000000015e-27*kilo( gram ) ), - // hana::make_pair( alphaMass , 0.0000000020e-27*kilo( gram ) ) + // Masses + hana::make_pair( electronMass , 0.0000000028e-31*kilo( gram ) ), + hana::make_pair( neutronMass , 0.00000000095e-27*kilo( gram ) ), + hana::make_pair( protonMass , 0.00000000051e-27*kilo( gram ) ), + hana::make_pair( deuteronMass , 0.0000000010e-27*kilo( gram ) ), + hana::make_pair( helionMass , 0.0000000015e-27*kilo( gram ) ), + hana::make_pair( tritonMass , 0.0000000015e-27*kilo( gram ) ), + hana::make_pair( alphaMass , 0.0000000020e-27*kilo( gram ) ) ); -auto CODATA2018 = Map_t( values, uncertainties ); +static constexpr auto CODATA2018 = Map_t( values, uncertainties ); } // namespace constants } // namespace njoy diff --git a/src/constants/CODATA2018/test/CODATA2018.test.cpp b/src/constants/CODATA2018/test/CODATA2018.test.cpp index 9382ed2..8279e0f 100644 --- a/src/constants/CODATA2018/test/CODATA2018.test.cpp +++ b/src/constants/CODATA2018/test/CODATA2018.test.cpp @@ -13,33 +13,33 @@ using namespace njoy::constants; using namespace dimwits; auto stringFor = hana::make_map( - hana::make_pair( avogadro, std::string{ "Avogadro constant" } ) - // hana::make_pair( boltzmann, std::string{ "Boltzmann constant" } ), - // hana::make_pair( electric, std::string{ "vacuum electric permittivity" } ), - // hana::make_pair( electronRadius, std::string{ "classical electron radius" } ), - // hana::make_pair( elementaryCharge, std::string{ "elementary charge" } ), - // hana::make_pair( faraday, std::string{ "Faraday constant" } ), - // hana::make_pair( fineStructure, std::string{ "fine-structure constant" } ), - // hana::make_pair( conductanceQuantum, std::string{ "conductance quantum" } ), - // hana::make_pair( magnetic, std::string{ "vacuum mag. permeability" } ), - // hana::make_pair( magneticFluxQuantum, std::string{ "mag. flux quantum" } ), - // hana::make_pair( molarGas, std::string{ "molar gas constant" } ), - // hana::make_pair( newtonianGravitation, - // std::string{ "Newtonian constant of gravitation" } ), - // hana::make_pair( planck, std::string{ "Planck constant" } ), - // hana::make_pair( reducedPlanck, std::string{ "reduced Planck constant" } ), - // hana::make_pair( rydberg, std::string{ "Rydberg constant" } ), - // hana::make_pair( speedOfLight, std::string{ "speed of light in vacuum" } ), - // hana::make_pair( stefanBoltzmann, std::string{ "Stefan-Boltzmann constant" } ), + hana::make_pair( avogadro, std::string{ "Avogadro constant" } ), + hana::make_pair( boltzmann, std::string{ "Boltzmann constant" } ), + hana::make_pair( electric, std::string{ "vacuum electric permittivity" } ), + hana::make_pair( electronRadius, std::string{ "classical electron radius" } ), + hana::make_pair( elementaryCharge, std::string{ "elementary charge" } ), + hana::make_pair( faraday, std::string{ "Faraday constant" } ), + hana::make_pair( fineStructure, std::string{ "fine-structure constant" } ), + hana::make_pair( conductanceQuantum, std::string{ "conductance quantum" } ), + hana::make_pair( magnetic, std::string{ "vacuum mag. permeability" } ), + hana::make_pair( magneticFluxQuantum, std::string{ "mag. flux quantum" } ), + hana::make_pair( molarGas, std::string{ "molar gas constant" } ), + hana::make_pair( newtonianGravitation, + std::string{ "Newtonian constant of gravitation" } ), + hana::make_pair( planck, std::string{ "Planck constant" } ), + hana::make_pair( reducedPlanck, std::string{ "reduced Planck constant" } ), + hana::make_pair( rydberg, std::string{ "Rydberg constant" } ), + hana::make_pair( speedOfLight, std::string{ "speed of light in vacuum" } ), + hana::make_pair( stefanBoltzmann, std::string{ "Stefan-Boltzmann constant" } ), - // // Masses - // hana::make_pair( electronMass, std::string{ "electron mass" } ), - // hana::make_pair( neutronMass, std::string{ "neutron mass" } ), - // hana::make_pair( protonMass, std::string{ "proton mass" } ), - // hana::make_pair( deuteronMass, std::string{ "deuteron mass" } ), - // hana::make_pair( helionMass, std::string{ "helion mass" } ), - // hana::make_pair( tritonMass, std::string{ "triton mass" } ), - // hana::make_pair( alphaMass, std::string{ "alpha particle mass" } ) + // Masses + hana::make_pair( electronMass, std::string{ "electron mass" } ), + hana::make_pair( neutronMass, std::string{ "neutron mass" } ), + hana::make_pair( protonMass, std::string{ "proton mass" } ), + hana::make_pair( deuteronMass, std::string{ "deuteron mass" } ), + hana::make_pair( helionMass, std::string{ "helion mass" } ), + hana::make_pair( tritonMass, std::string{ "triton mass" } ), + hana::make_pair( alphaMass, std::string{ "alpha particle mass" } ) ); template< typename MAP > @@ -47,9 +47,7 @@ void checkMap( MAP& map ){ auto referenceValues = testing::defineReferenceValues( std::ifstream("CODATA2018.txt") ); - auto keys = hana::keys( map ); - hana::for_each( - keys, + hana::for_each( hana::keys( map.value ), [&]( auto&& key ){ auto refKey = stringFor[ key ]; @@ -64,26 +62,26 @@ void checkMap( MAP& map ){ SCENARIO("test all the constants"){ - // checkMap( CODATA2018 ); + checkMap( CODATA2018 ); - // auto aliasMap = Map_t( - // hana::make_map( - // hana::make_pair( k, CODATA2018[ k ] ), - // hana::make_pair( h, CODATA2018[ h ] ), - // hana::make_pair( hbar, CODATA2018[ hbar ] ), - // hana::make_pair( G, CODATA2018[ G ] ), - // hana::make_pair( c, CODATA2018[ c ] ) - // ), + auto aliasMap = Map_t( + hana::make_map( + hana::make_pair( k, CODATA2018[ k ] ), + hana::make_pair( h, CODATA2018[ h ] ), + hana::make_pair( hbar, CODATA2018[ hbar ] ), + hana::make_pair( G, CODATA2018[ G ] ), + hana::make_pair( c, CODATA2018[ c ] ) + ), - // // Uncertainties - // hana::make_map( - // hana::make_pair( k, CODATA2018.uncertainty[ k ] ), - // hana::make_pair( h, CODATA2018.uncertainty[ h ] ), - // hana::make_pair( hbar, CODATA2018.uncertainty[ hbar ] ), - // hana::make_pair( G, CODATA2018.uncertainty[ G ] ), - // hana::make_pair( c, CODATA2018.uncertainty[ c ] ) - // ) - // ); + // Uncertainties + hana::make_map( + hana::make_pair( k, CODATA2018.uncertainty[ k ] ), + hana::make_pair( h, CODATA2018.uncertainty[ h ] ), + hana::make_pair( hbar, CODATA2018.uncertainty[ hbar ] ), + hana::make_pair( G, CODATA2018.uncertainty[ G ] ), + hana::make_pair( c, CODATA2018.uncertainty[ c ] ) + ) + ); // checkMap( aliasMap ); } diff --git a/src/constants/map.hpp b/src/constants/map.hpp index ff01718..fcadd25 100644 --- a/src/constants/map.hpp +++ b/src/constants/map.hpp @@ -1,33 +1,31 @@ -template< typename Values, typename Uncertainty > +template< typename Value, typename Uncertainty > struct Map_t{ -private: - Values values; -public: + Value value; Uncertainty uncertainty; - constexpr Map_t( Values v, Uncertainty u ): - values( v ), + constexpr Map_t( Value v, Uncertainty u ): + value( v ), uncertainty( u ) { } template constexpr decltype(auto) operator[](Key&& key) & { - return static_cast(values)[ + return static_cast(value)[ std::forward(key)]; } template constexpr decltype(auto) operator[](Key&& key) && { - return static_cast(values)[ + return static_cast(value)[ std::forward(key)]; } template constexpr decltype(auto) operator[](Key&& key) const& { - return static_cast(values)[ + return static_cast(value)[ std::forward(key)]; } }; // Deduction guide -template< typename Values, typename Keys > -Map_t( Values values, Keys keys ) -> Map_t< Values, Keys >; +template< typename Value, typename Keys > +Map_t( Value value, Keys keys ) -> Map_t< Value, Keys >; From f893df509e303f7bc73a10f29ca7d007de7c16e2 Mon Sep 17 00:00:00 2001 From: Jeremy Lloyd Conlin Date: Mon, 29 Jun 2020 20:30:32 -0600 Subject: [PATCH 4/7] Create ContinuousIntegration.yml --- .github/workflows/ContinuousIntegration.yml | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/ContinuousIntegration.yml diff --git a/.github/workflows/ContinuousIntegration.yml b/.github/workflows/ContinuousIntegration.yml new file mode 100644 index 0000000..32e6b44 --- /dev/null +++ b/.github/workflows/ContinuousIntegration.yml @@ -0,0 +1,36 @@ +# GitHub workflow to enable continuous integratoin +name: Continuous Integration + +# This workflow is triggered on pushes and pull requests to the repository. +on: + push: + branches: '**' + pull_request: + branches: 'master' + +jobs: + build: + runs-on: ${{matrix.os}} + strategy: + matrix: + os: [ ubuntu-18.04, macos-10.15 ] + cxx: [ g++-9, clang++ ] + build_type: [ Debug, Release ] + + steps: + - name: which CXX + run: | + which ${{matrix.cxx}} + ${{matrix.cxx}} --version + - uses: actions/checkout@v2 + - name: mkdir bin + run: mkdir bin + - name: cmake + run: cmake -D CMAKE_CXX_COMPILER=`which ${{matrix.cxx}}` -D CMAKE_BUILD_TYPE=${{matrix.build_type}} .. + working-directory: ./bin + - name: make + run: make + working-directory: ./bin + - name: ctest + run: ctest -j2 + working-directory: ./bin From dacf4c5b566d14eafff77c749fe269740d5befa2 Mon Sep 17 00:00:00 2001 From: Jeremy Lloyd Conlin Date: Mon, 29 Jun 2020 20:33:24 -0600 Subject: [PATCH 5/7] Fixing up CMake stuff. --- CMakeLists.txt | 51 +++++++++++++++++----------------- metaconfigure/description.json | 3 +- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6890d7c..56b0568 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,18 +103,6 @@ set( constants_AppleClang_Darwin_link_time_optimization_flags "-flto" ) set( constants_AppleClang_Darwin_profile_use_flags "-fprofile-use='${CMAKE_BINARY_DIR}/profiling'" ) set( constants_AppleClang_Darwin_nonportable_optimization_flags "-march=native" ) set( constants_AppleClang_Darwin_static_flags "-static" ) -set( constants_GNU_Windows_common_flags "-Wno-subobject-linkage" "-Wall" "-Wextra" "-Wpedantic" "-std=c++17" ) -set( constants_GNU_Windows_DEBUG_flags "-O0" "-g" "-gdwarf-3" "-fsignaling-nans" ) -set( constants_GNU_Windows_RELEASE_flags "-O3" "-DNDEBUG" ) -set( constants_GNU_Windows_strict_flags "-Werror" ) -set( constants_GNU_Windows_coverage_flags "--coverage" ) -set( constants_GNU_Windows_subproject_flags ) -set( constants_GNU_Windows_base_project_flags ) -set( constants_GNU_Windows_profile_generate_flags "-fprofile-generate='${CMAKE_BINARY_DIR}/profiling'" ) -set( constants_GNU_Windows_link_time_optimization_flags "-flto" ) -set( constants_GNU_Windows_profile_use_flags "-fprofile-use='${CMAKE_BINARY_DIR}/profiling'" ) -set( constants_GNU_Windows_nonportable_optimization_flags "-march=native" ) -set( constants_GNU_Windows_static_flags "-static" ) set( constants_GNU_CYGWIN_common_flags "-Wno-subobject-linkage" "-Wall" "-Wextra" "-Wpedantic" "-std=gnu++17" ) set( constants_GNU_CYGWIN_DEBUG_flags "-O0" "-g" "-gdwarf-3" "-fsignaling-nans" ) set( constants_GNU_CYGWIN_RELEASE_flags "-O3" "-DNDEBUG" ) @@ -151,6 +139,18 @@ set( constants_GNU_MinGW_link_time_optimization_flags "-flto" ) set( constants_GNU_MinGW_profile_use_flags "-fprofile-use='${CMAKE_BINARY_DIR}/profiling'" ) set( constants_GNU_MinGW_nonportable_optimization_flags "-march=native" ) set( constants_GNU_MinGW_static_flags "-static" ) +set( constants_GNU_Windows_common_flags "-Wno-subobject-linkage" "-Wall" "-Wextra" "-Wpedantic" "-std=c++17" ) +set( constants_GNU_Windows_DEBUG_flags "-O0" "-g" "-gdwarf-3" "-fsignaling-nans" ) +set( constants_GNU_Windows_RELEASE_flags "-O3" "-DNDEBUG" ) +set( constants_GNU_Windows_strict_flags "-Werror" ) +set( constants_GNU_Windows_coverage_flags "--coverage" ) +set( constants_GNU_Windows_subproject_flags ) +set( constants_GNU_Windows_base_project_flags ) +set( constants_GNU_Windows_profile_generate_flags "-fprofile-generate='${CMAKE_BINARY_DIR}/profiling'" ) +set( constants_GNU_Windows_link_time_optimization_flags "-flto" ) +set( constants_GNU_Windows_profile_use_flags "-fprofile-use='${CMAKE_BINARY_DIR}/profiling'" ) +set( constants_GNU_Windows_nonportable_optimization_flags "-march=native" ) +set( constants_GNU_Windows_static_flags "-static" ) set( constants_GNU_Darwin_common_flags "-Wno-subobject-linkage" "-Wall" "-Wextra" "-Wpedantic" "-std=c++17" ) set( constants_GNU_Darwin_DEBUG_flags "-O0" "-g" "-gdwarf-3" "-fsignaling-nans" ) set( constants_GNU_Darwin_RELEASE_flags "-O3" "-DNDEBUG" ) @@ -163,18 +163,6 @@ set( constants_GNU_Darwin_link_time_optimization_flags "-flto" ) set( constants_GNU_Darwin_profile_use_flags "-fprofile-use='${CMAKE_BINARY_DIR}/profiling'" ) set( constants_GNU_Darwin_nonportable_optimization_flags "-march=native" ) set( constants_GNU_Darwin_static_flags "-static" ) -set( constants_Clang_Windows_common_flags "-stdlib=libc++" "-Wall" "-Wextra" "-Wpedantic" "-std=c++17" ) -set( constants_Clang_Windows_DEBUG_flags "-O0" "-g" "-gdwarf-3" ) -set( constants_Clang_Windows_RELEASE_flags "-O3" "-DNDEBUG" ) -set( constants_Clang_Windows_strict_flags "-Werror" ) -set( constants_Clang_Windows_coverage_flags "--coverage" ) -set( constants_Clang_Windows_subproject_flags ) -set( constants_Clang_Windows_base_project_flags ) -set( constants_Clang_Windows_profile_generate_flags "-fprofile-generate='${CMAKE_BINARY_DIR}/profiling'" ) -set( constants_Clang_Windows_link_time_optimization_flags "-flto" ) -set( constants_Clang_Windows_profile_use_flags "-fprofile-use='${CMAKE_BINARY_DIR}/profiling'" ) -set( constants_Clang_Windows_nonportable_optimization_flags "-march=native" ) -set( constants_Clang_Windows_static_flags "-static" ) set( constants_Clang_CYGWIN_common_flags "-Wno-subobject-linkage" "-Wall" "-Wextra" "-Wpedantic" "-std=gnu++17" ) set( constants_Clang_CYGWIN_DEBUG_flags "-O0" "-g" "-gdwarf-3" "-fsignaling-nans" ) set( constants_Clang_CYGWIN_RELEASE_flags "-O3" "-DNDEBUG" ) @@ -211,6 +199,18 @@ set( constants_Clang_MinGW_link_time_optimization_flags "-flto" ) set( constants_Clang_MinGW_profile_use_flags "-fprofile-use='${CMAKE_BINARY_DIR}/profiling'" ) set( constants_Clang_MinGW_nonportable_optimization_flags "-march=native" ) set( constants_Clang_MinGW_static_flags "-static" ) +set( constants_Clang_Windows_common_flags "-stdlib=libc++" "-Wall" "-Wextra" "-Wpedantic" "-std=c++17" ) +set( constants_Clang_Windows_DEBUG_flags "-O0" "-g" "-gdwarf-3" ) +set( constants_Clang_Windows_RELEASE_flags "-O3" "-DNDEBUG" ) +set( constants_Clang_Windows_strict_flags "-Werror" ) +set( constants_Clang_Windows_coverage_flags "--coverage" ) +set( constants_Clang_Windows_subproject_flags ) +set( constants_Clang_Windows_base_project_flags ) +set( constants_Clang_Windows_profile_generate_flags "-fprofile-generate='${CMAKE_BINARY_DIR}/profiling'" ) +set( constants_Clang_Windows_link_time_optimization_flags "-flto" ) +set( constants_Clang_Windows_profile_use_flags "-fprofile-use='${CMAKE_BINARY_DIR}/profiling'" ) +set( constants_Clang_Windows_nonportable_optimization_flags "-march=native" ) +set( constants_Clang_Windows_static_flags "-static" ) set( constants_Clang_Darwin_common_flags "-stdlib=libc++" "-Wall" "-Wextra" "-Wpedantic" "-std=c++17" ) set( constants_Clang_Darwin_DEBUG_flags "-O0" "-g" "-gdwarf-3" ) set( constants_Clang_Darwin_RELEASE_flags "-O3" "-DNDEBUG" ) @@ -292,8 +292,7 @@ target_sources( constants INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/src/constants.h "${CMAKE_CURRENT_SOURCE_DIR}/src/constants/tags.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/constants/CODATA2018.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/constants/testing/src/defineReferenceValues.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/src/constants/testing/src/toValue.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/src/constants/src/addUncertainty.hpp" ) + "${CMAKE_CURRENT_SOURCE_DIR}/src/constants/testing/src/toValue.hpp" ) target_include_directories( constants INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/src src/ ) diff --git a/metaconfigure/description.json b/metaconfigure/description.json index 58c2095..ef96b85 100644 --- a/metaconfigure/description.json +++ b/metaconfigure/description.json @@ -596,8 +596,7 @@ "src/constants/tags.hpp", "src/constants/CODATA2018.hpp", "src/constants/testing/src/defineReferenceValues.hpp", - "src/constants/testing/src/toValue.hpp", - "src/constants/src/addUncertainty.hpp" + "src/constants/testing/src/toValue.hpp" ], "ignore pattern": "$^", "implementation files": [], From fe06262b644378394d579dac9c4a6cd1e3d7a1bb Mon Sep 17 00:00:00 2001 From: Jeremy Lloyd Conlin Date: Mon, 29 Jun 2020 20:37:16 -0600 Subject: [PATCH 6/7] Adding status badge for GitHub Actions. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9213746..b0bf5c9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](http://jenkins.njoy21.io:8080/buildStatus/icon?job=constants)](http://jenkins.njoy21.io:8080/job/constants/) +![Continuous Integration](https://github.com/njoy/constants/workflows/Continuous%20Integration/badge.svg) # constants This repository contains a collection of mathematical and physical constants. Additional information about the constants provided—and their values— see the associated README files. From 112a244ee4e38b855abd15ae14ad3412196da17e Mon Sep 17 00:00:00 2001 From: Jeremy Lloyd Conlin Date: Tue, 7 Jul 2020 03:16:12 -0600 Subject: [PATCH 7/7] Responding to Pull Request comments. --- src/constants/CODATA2018/test/CODATA2018.test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants/CODATA2018/test/CODATA2018.test.cpp b/src/constants/CODATA2018/test/CODATA2018.test.cpp index 8279e0f..495269e 100644 --- a/src/constants/CODATA2018/test/CODATA2018.test.cpp +++ b/src/constants/CODATA2018/test/CODATA2018.test.cpp @@ -83,5 +83,5 @@ SCENARIO("test all the constants"){ ) ); - // checkMap( aliasMap ); + checkMap( aliasMap ); }