Skip to content

Commit

Permalink
Made arrayElement<T>(start, end) more elegant and minor fixes (ciesla…
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-bodhi authored Jul 31, 2024
1 parent dbd3487 commit 9c52cb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions include/faker-cxx/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ T arrayElement(const std::array<T, N>& data)
return data[index];
}

template <typename It>
template <std::input_iterator It>
auto arrayElement(It start, It end) -> decltype(*::std::declval<It>())
{
auto size = static_cast<size_t>(end - start);
Expand All @@ -61,7 +61,7 @@ auto arrayElement(It start, It end) -> decltype(*::std::declval<It>())

const std::integral auto index = number::integer<size_t>(size - 1);

return start[index];
return *(start + static_cast<std::iter_difference_t<It>>(index));
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/modules/datatype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@ bool boolean()

bool boolean(double probability)
{
if (probability != nan(""))
if (!std::isnan(probability))
{
double prob = probability;

if (prob <= double(0.))
if (probability <= double(0))
{
return false;
}

if (prob >= double(1.))
if (probability >= double(1))
{
return true;
}

return double(number::decimal(0., 1.)) < prob;
return number::decimal(0., 1.) < probability;
}

return number::decimal(0., 1.) < 0.5;
Expand Down

0 comments on commit 9c52cb4

Please sign in to comment.