Skip to content

Commit

Permalink
Auto-format C++ code using ms-vscode.cpptools
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobiasd committed Dec 26, 2023
1 parent 6cd97b3 commit 7c80ac9
Show file tree
Hide file tree
Showing 87 changed files with 27,612 additions and 27,175 deletions.
26 changes: 12 additions & 14 deletions examples/99_problems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ using namespace fplus;
typedef std::vector<int> Ints;
typedef std::vector<Ints> Intss;
typedef std::vector<std::size_t> Idxs;
Ints xs = {0,2,2,2,1,3,3,4};
Intss xss = {{0,1,2},{3,4}};
Ints xs = {0, 2, 2, 2, 1, 3, 3, 4};
Intss xss = {{0, 1, 2}, {3, 4}};
typedef std::pair<std::size_t, int> size_t_int_pair;
typedef std::vector<size_t_int_pair> size_t_int_pairs;
size_t_int_pairs xs_run_length_encoded = {{1, 0}, {3, 2}, {1, 1}, {2, 3}, {1, 4}};

template <typename T>
void print_result(const T& x)
void print_result(const T &x)
{
std::cout << show(x) << std::endl;
}
Expand Down Expand Up @@ -79,7 +79,7 @@ void problem_09()
// P10 (*) Run-length encoding of a list.
void problem_10()
{
auto group_to_pair = [](const Ints& group) -> size_t_int_pair
auto group_to_pair = [](const Ints &group) -> size_t_int_pair
{
return std::make_pair(size_of_cont(group), group.front());
};
Expand All @@ -89,23 +89,21 @@ void problem_10()
// P11 (*) Modified run-length encoding.
void problem_11()
{
const auto modify = [](const auto& p) -> Ints
const auto modify = [](const auto &p) -> Ints
{
return p.first == 1 ?
Ints({p.second})
: Ints({static_cast<int>(p.first), p.second});
return p.first == 1 ? Ints({p.second})
: Ints({static_cast<int>(p.first), p.second});
};

print_result(fwd::apply(xs,
fwd::run_length_encode(),
fwd::transform(modify)
));
fwd::run_length_encode(),
fwd::transform(modify)));
}

// P12 (**) Decode a run-length encoded list.
void problem_12()
{
const auto pair_to_vec = [](const size_t_int_pair& p) -> Ints
const auto pair_to_vec = [](const size_t_int_pair &p) -> Ints
{
return replicate(p.first, p.second);
};
Expand All @@ -115,7 +113,7 @@ void problem_12()
// P13 (**) Run-length encoding of a list (direct solution).
void problem_13()
{
const auto f = [](const Intss& acc, int x) -> Intss
const auto f = [](const Intss &acc, int x) -> Intss
{
if (is_empty(acc))
{
Expand Down Expand Up @@ -170,7 +168,7 @@ void problem_17()
// P18 (**) Extract a slice from a list.
void problem_18()
{
print_result(get_segment(2, 4+1, xs));
print_result(get_segment(2, 4 + 1, xs));
}

// P19 (**) Rotate a list N places to the left.
Expand Down
28 changes: 10 additions & 18 deletions examples/performance_range_v3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

int main()
{
const auto times_3 = [](int i){return 3 * i;};
const auto is_odd_int = [](int i){return i % 2 != 0;};
const auto as_string_length = [](int i){return std::to_string(i).size();};
const auto times_3 = [](int i)
{ return 3 * i; };
const auto is_odd_int = [](int i)
{ return i % 2 != 0; };
const auto as_string_length = [](int i)
{ return std::to_string(i).size(); };

typedef std::chrono::time_point<std::chrono::system_clock> Time;

Expand All @@ -21,32 +24,21 @@ int main()
Time startTimeFPlus = std::chrono::system_clock::now();
using namespace fplus;
const auto result_fplus = fwd::apply(
numbers(0, 15000000)
, fwd::transform(times_3)
, fwd::drop_if(is_odd_int)
, fwd::transform(as_string_length)
, fwd::sum());
numbers(0, 15000000), fwd::transform(times_3), fwd::drop_if(is_odd_int), fwd::transform(as_string_length), fwd::sum());
Time endTimeFPlus = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_s_fplus =
endTimeFPlus - startTimeFPlus;
std::cout << "(check: " << result_fplus <<
"), elapsed time fplus: " << elapsed_s_fplus.count() << "s\n";
std::cout << "(check: " << result_fplus << "), elapsed time fplus: " << elapsed_s_fplus.count() << "s\n";

// range-v3
Time startTimeRangev3 = std::chrono::system_clock::now();
using namespace ranges;
const auto result_range_v3 =
accumulate(
view::ints(0)
| view::take(15000000)
| view::transform(times_3)
| view::remove_if(is_odd_int)
| view::transform(as_string_length)
, 0);
view::ints(0) | view::take(15000000) | view::transform(times_3) | view::remove_if(is_odd_int) | view::transform(as_string_length), 0);
Time endTimeRangev3 = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_s_rangev3 =
endTimeRangev3 - startTimeRangev3;
std::cout << "(check: " << result_range_v3 <<
"), elapsed time range-v3: " << elapsed_s_rangev3.count() << "s\n";
std::cout << "(check: " << result_range_v3 << "), elapsed time range-v3: " << elapsed_s_rangev3.count() << "s\n";
}
}
10 changes: 5 additions & 5 deletions examples/readme_perf_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bool is_odd_int(int x) { return x % 2 != 0; }
void Test_example_KeepIf()
{
typedef std::vector<int> Ints;
Ints values = { 24, 11, 65, 44, 80, 18, 73, 90, 69, 18 };
Ints values = {24, 11, 65, 44, 80, 18, 73, 90, 69, 18};

{ // Version 1: hand written range based for loop
Ints odds;
Expand All @@ -35,7 +35,7 @@ void Test_example_KeepIf()
{ // Version 2: STL
Ints odds;
std::copy_if(std::begin(values), std::end(values),
std::back_inserter(odds), is_odd_int);
std::back_inserter(odds), is_odd_int);
}

{ // Version : FunctionalPlus
Expand All @@ -44,7 +44,7 @@ void Test_example_KeepIf()
}

void run_n_times(std::function<std::vector<int>(std::vector<int>)> f,
std::size_t n, const std::string& name, const std::vector<int>& inList)
std::size_t n, const std::string &name, const std::vector<int> &inList)
{
typedef std::chrono::time_point<std::chrono::system_clock> Time;
Time startTime = std::chrono::system_clock::now();
Expand Down Expand Up @@ -75,11 +75,11 @@ void Test_example_KeepIf_performance()
{
Ints odds;
std::copy_if(std::begin(values), std::end(values),
std::back_inserter(odds), is_odd_int);
std::back_inserter(odds), is_odd_int);
return odds;
};
auto run_FunctionalPlus = [&](const Ints values)
{ return keep_if(is_odd_int, values); };
{ return keep_if(is_odd_int, values); };

// make debug runs faster
#if defined NDEBUG || defined _DEBUG
Expand Down
Loading

0 comments on commit 7c80ac9

Please sign in to comment.