Taking out the 'logic' to a header

master
denes 5 years ago
parent e5e4bcb9c3
commit 066627f5e2
Signed by: denes
GPG Key ID: A7D50EAD42F9FC9F

@ -1,3 +1,6 @@
cmake_minimum_required (VERSION 3.10)
project (PerformanceMeasuring)
add_executable(performance_measuring main.cpp)
set(HEADER_FILES dummy_lib.hpp)
add_executable(performance_measuring main.cpp ${HEADER_FILES})

@ -0,0 +1,17 @@
#ifndef DUMMY_LIB_HPP
#define DUMMY_LIB_HPP
#include <vector>
#include <algorithm>
namespace performance_measuring {
int compute(const std::vector<int>& v)
{
int min = *std::min_element(v.begin(), v.end());
return std::count(v.begin(), v.end(), min);
}
}
#endif

@ -2,7 +2,8 @@
#include <ctime>
#include <vector>
#include <algorithm>
#include "dummy_lib.hpp"
std::vector<int> generate_random_numbers(int n, int min, int max)
@ -15,19 +16,13 @@ std::vector<int> generate_random_numbers(int n, int min, int max)
return v;
}
int compute(const std::vector<int>& v)
{
int min = *std::min_element(v.begin(), v.end());
return std::count(v.begin(), v.end(), min);
}
int main(int /*argc*/, char* /*argv*/[])
{
std::vector<int> v = generate_random_numbers(10000, 0, 100);
// How many times does the smallest element occurst in the vector?
int r = compute(v);
int r = performance_measuring::compute(v);
(void)r;

Loading…
Cancel
Save