Skip to content

Commit 267aa9f

Browse files
Make use of move semantics for parameters where possible
1 parent dd7a18c commit 267aa9f

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/util/string_join.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ class joined_strings
5454
ostringstream_typet;
5555

5656
public:
57-
joined_strings(It begin, const It end, const Str &sep)
58-
: begin(begin), end(end), sep(sep)
57+
template<typename It_In, typename Str_In>
58+
joined_strings(It_In &&begin, It_In &&end, Str_In &&sep)
59+
: begin(std::forward<It_In>(begin)),
60+
end(std::forward<It_In>(end)),
61+
sep(std::forward<Str_In>(sep))
5962
{
6063
}
6164

@@ -84,16 +87,19 @@ class joined_strings
8487

8588

8689
template<typename Str, typename It>
87-
inline joined_strings<Str, It> join(It begin, const It end, const Str &sep)
90+
inline joined_strings<Str, It> join(It begin, It end, const Str &sep)
8891
{
89-
return joined_strings<Str, It>(begin, end, sep);
92+
return joined_strings<Str, It>(std::move(begin), std::move(end), sep);
9093
}
9194

9295
template<typename It>
9396
inline joined_strings<const char *, It> join(
94-
It begin, const It end, const char *sep)
97+
It begin, It end, const char *sep)
9598
{
96-
return joined_strings<const char *, It>(begin, end, sep);
99+
return joined_strings<const char *, It>(
100+
std::move(begin),
101+
std::move(end),
102+
sep);
97103
}
98104

99105

@@ -105,10 +111,11 @@ class joined_strings_container
105111
Container container;
106112

107113
public:
108-
joined_strings_container(const Container &container, const Str &sep)
114+
template<typename Container_In, typename Str_In>
115+
joined_strings_container(Container_In &&container, Str_In &&sep)
109116
: joined_strings<Str, typename Container::const_iterator>(
110-
container.begin(), container.end(), sep),
111-
container(container)
117+
container.begin(), container.end(), std::forward<Str_In>(sep)),
118+
container(std::forward<Container_In>(container))
112119
{
113120
}
114121
};

0 commit comments

Comments
 (0)