units building and packaging redesigned + Travis CI support

This commit is contained in:
Mateusz Pusz
2019-04-06 23:25:35 +02:00
parent 09457e9b8f
commit 8d86d9401f
18 changed files with 888 additions and 501 deletions
+1 -15
View File
@@ -20,23 +20,9 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
cmake_minimum_required(VERSION 3.8)
project(units_example)
# set path to custom cmake modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake/common/cmake")
# include common tools and workarounds
include(tools)
# add dependencies
if(NOT TARGET mp::units)
find_package(units CONFIG REQUIRED)
endif()
# example app
add_executable(example example.cpp)
target_link_libraries(example
PRIVATE
mp::units
units::units
)
+24 -10
View File
@@ -23,26 +23,40 @@
#include "units/si/velocity.h"
#include <iostream>
using namespace units;
namespace {
template<Velocity V, Time T>
void foo(V v, T t)
using namespace units::literals;
template<units::Length D, units::Time T>
constexpr units::Velocity avg_speed(D d, T t)
{
const Length distance = v * t;
std::cout << "A car driving " << v.count() << " km/h in a time of " << t.count() << " minutes will pass "
<< quantity_cast<length<meter, double>>(distance).count() << " meters.\n";
return d / t;
}
void foo()
template<units::Velocity V, units::Time T>
void example_1(V v, T t)
{
using namespace units::literals;
foo(60_kmph, 10.0_min);
const units::Length distance = v * t;
std::cout << "A car driving " << v.count() << " km/h in a time of " << t.count() << " minutes will pass "
<< units::quantity_cast<units::length<units::meter, double>>(distance).count() << " meters.\n";
}
void example_2(double distance_v, double duration_v)
{
units::length<units::kilometer> distance(distance_v);
units::time<units::hour> duration(duration_v);
const auto kmph = avg_speed(distance, duration);
std::cout << "Average speed of a car that makes " << distance.count() << " km in "
<< duration.count() << " hours is " << kmph.count() << " km/h.\n";
}
}
int main()
{
try {
foo();
example_1(60_kmph, 10.0_min);
example_2(220, 2);
}
catch (const std::exception& ex) {
std::cerr << "Unhandled std exception caught: " << ex.what() << '\n';