Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Made range arrayFormat overload more elegant + minor fixes #837

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading