@@ -113,16 +113,12 @@ namespace colour
113
113
/* *
114
114
* @brief Struct for delimited strings.
115
115
*/
116
- template <typename StringType>
117
116
struct coloured_string_t
118
117
{
119
- static_assert (std::is_reference_v<StringType> or std::is_pointer_v<StringType>,
120
- " String type must be pointer or reference" );
121
-
122
118
/* *
123
119
* @brief Construct a new coloured string t object
124
120
*/
125
- coloured_string_t (StringType s, colour_type fc, colour_type bc, style_type st)
121
+ coloured_string_t (std::string_view s, colour_type fc, colour_type bc, style_type st)
126
122
: m_str(s)
127
123
, m_fore_colour(static_cast <int >(fc) + 30 )
128
124
, m_back_colour(static_cast <int >(bc) + 40 )
@@ -152,12 +148,14 @@ namespace colour
152
148
<< cs.m_str
153
149
<< " \033 [0m" ;
154
150
}
151
+ else
152
+ os << cs.m_str ;
155
153
156
154
return os;
157
155
}
158
156
159
157
// / @cond
160
- StringType m_str;
158
+ std::string_view m_str;
161
159
int m_fore_colour, m_back_colour;
162
160
int m_style;
163
161
// / @endcond
@@ -191,39 +189,13 @@ namespace colour
191
189
* @param st Text style to use
192
190
*/
193
191
194
- template <typename char_type>
195
- inline auto coloured (const char_type *str,
196
- colour::colour_type fg, colour::colour_type bg = colour::colour_type::none,
197
- colour::style_type st = colour::style_type::regular)
198
- {
199
- return colour::detail::coloured_string_t <const char_type *>(str, fg, bg, st);
200
- }
201
-
202
- // / @brief Manipulator for coloured strings.
203
- template <typename char_type, typename traits_type, typename allocator_type>
204
- inline auto coloured (const std::basic_string<char_type, traits_type, allocator_type> &str,
205
- colour::colour_type fg, colour::colour_type bg = colour::colour_type::none,
206
- colour::style_type st = colour::style_type::regular)
207
- {
208
- return colour::detail::coloured_string_t <const std::basic_string<char_type, traits_type, allocator_type> &>(str, fg, bg, st);
209
- }
210
-
211
- // / @brief Manipulator for coloured strings.
212
- template <typename char_type, typename traits_type, typename allocator_type>
213
- inline auto coloured (std::basic_string<char_type, traits_type, allocator_type> &str,
214
- colour::colour_type fg, colour::colour_type bg = colour::colour_type::none,
215
- colour::style_type st = colour::style_type::regular)
216
- {
217
- return colour::detail::coloured_string_t <std::basic_string<char_type, traits_type, allocator_type> &>(str, fg, bg, st);
218
- }
219
-
220
- // / @brief Manipulator for coloured strings.
221
- template <typename char_type, typename traits_type>
222
- inline auto coloured (std::basic_string_view<char_type, traits_type> &str,
192
+ template <typename T>
193
+ requires std::is_assignable_v<std::string_view, T>
194
+ inline auto coloured (T str,
223
195
colour::colour_type fg, colour::colour_type bg = colour::colour_type::none,
224
196
colour::style_type st = colour::style_type::regular)
225
197
{
226
- return colour::detail::coloured_string_t <std::basic_string_view<char_type, traits_type> &> (str, fg, bg, st);
198
+ return colour::detail::coloured_string_t (str, fg, bg, st);
227
199
}
228
200
229
201
// --------------------------------------------------------------------
0 commit comments