Skip to content

Commit e9ea386

Browse files
committed
fix Time operators
1 parent 478f4c0 commit e9ea386

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

include/gf2/core/Namegen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ namespace gf {
4949

5050
};
5151

52-
struct NamegenSettings {
52+
struct GF_CORE_API NamegenSettings {
5353
std::size_t min_length = 0;
5454
std::size_t max_length = std::numeric_limits<std::size_t>::max();
5555
std::string starts_with;

include/gf2/core/Time.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,24 @@ namespace gf {
142142
return Time(lhs.as_duration() - rhs.as_duration());
143143
}
144144

145-
template<typename T>
146-
constexpr Time operator*(Time lhs, std::enable_if_t<std::is_arithmetic_v<T>, T> rhs)
145+
template<typename T, std::enable_if_t<std::is_arithmetic_v<T>, bool> = true>
146+
constexpr Time operator*(Time lhs, T rhs)
147147
{
148-
auto duration = lhs * rhs;
148+
auto duration = lhs.as_duration() * rhs;
149149
return Time(std::chrono::duration_cast<details::DurationType>(duration));
150150
}
151151

152-
template<typename T>
153-
constexpr Time operator*(std::enable_if_t<std::is_arithmetic_v<T>, T> lhs, Time rhs)
152+
template<typename T, std::enable_if_t<std::is_arithmetic_v<T>, bool> = true>
153+
constexpr Time operator*(T lhs, Time rhs)
154154
{
155-
auto duration = lhs * rhs;
155+
auto duration = lhs * rhs.as_duration();
156156
return Time(std::chrono::duration_cast<details::DurationType>(duration));
157157
}
158158

159-
template<typename T>
160-
constexpr Time operator/(Time lhs, std::enable_if_t<std::is_arithmetic_v<T>, T> rhs)
159+
template<typename T, std::enable_if_t<std::is_arithmetic_v<T>, bool> = true>
160+
constexpr Time operator/(Time lhs, T rhs)
161161
{
162-
auto duration = lhs / rhs;
162+
auto duration = lhs.as_duration() / rhs;
163163
return Time(std::chrono::duration_cast<details::DurationType>(duration));
164164
}
165165

library/core/Namegen.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,10 @@ namespace gf {
198198
std::vector<std::string> NamegenManager::generate_multiple(Random& random, std::size_t count, Time max_time_per_name, const NamegenSettings& settings) const
199199
{
200200
std::vector<std::string> names;
201+
const Time max_time = count * max_time_per_name;
201202
Clock clock;
202203

203-
while (names.size() < count && clock.restart() < max_time_per_name) {
204+
while (names.size() < count && clock.elapsed_time() < max_time) {
204205
if (auto maybe_name = generate_single(random, settings); maybe_name) {
205206
names.push_back(std::move(maybe_name).value());
206207
}

0 commit comments

Comments
 (0)