FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
extra_string.inl
1/*
2 * Copyright 2024 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17namespace fge
18{
19namespace string
20{
21
22template<class T>
23std::string ToStr(std::list<T> const& val, char separator)
24{
25 std::string result;
26 for (auto it = val.cbegin(); it != val.cend(); ++it)
27 {
28 result += fge::string::ToStr(*it) + separator;
29 }
30 if (!result.empty())
31 {
32 result.pop_back();
33 }
34 return result;
35}
36template<class T>
37std::string ToStr(std::vector<T> const& val, char separator)
38{
39 std::string result;
40 for (auto it = val.cbegin(); it != val.cend(); ++it)
41 {
42 result += fge::string::ToStr(*it) + separator;
43 }
44 if (!result.empty())
45 {
46 result.pop_back();
47 }
48 return result;
49}
50
51template<class T>
52std::string ToStr(std::optional<T> const& val)
53{
54 if (val.has_value())
55 {
56 return fge::string::ToStr(val.value());
57 }
58 return "NO_VALUE";
59}
60
61} // namespace string
62} // namespace fge
FGE_API std::string ToStr(bool val)
Convert efficiently a boolean to a string.