Skip to content

Commit 70185e7

Browse files
committed
Move string concepts out of detail namespace
Given that these are used outside of the string library, and will appear in compilation errors, it makes more sense for the concepts to live in the top-level fly namespace.
1 parent 72c333d commit 70185e7

15 files changed

+223
-201
lines changed

bench/util/table.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "fly/logger/styler.hpp"
66
#include "fly/types/numeric/literals.hpp"
77
#include "fly/types/string/string.hpp"
8+
#include "fly/types/string/string_concepts.hpp"
89

910
#include <array>
1011
#include <cmath>
@@ -357,7 +358,7 @@ auto Table<Args...>::column_widths_for_row(const Row &row) -> RowSizedArray<std:
357358
{
358359
using T = std::decay_t<decltype(value)>;
359360

360-
if constexpr (fly::detail::StandardStringLike<T>)
361+
if constexpr (fly::StandardStringLike<T>)
361362
{
362363
widths[index] = fly::String::size(value);
363364
}

build/win/libfly/libfly.vcxproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,14 @@
240240
<ClInclude Include="..\..\..\fly\types\string\detail\format_specifier.hpp" />
241241
<ClInclude Include="..\..\..\fly\types\string\detail\format_string.hpp" />
242242
<ClInclude Include="..\..\..\fly\types\string\detail\stream_util.hpp" />
243-
<ClInclude Include="..\..\..\fly\types\string\detail\string_concepts.hpp" />
243+
<ClInclude Include="..\..\..\fly\types\string\detail\string_concepts_helpers.hpp" />
244244
<ClInclude Include="..\..\..\fly\types\string\detail\string_traits.hpp" />
245245
<ClInclude Include="..\..\..\fly\types\string\detail\unicode.hpp" />
246246
<ClInclude Include="..\..\..\fly\types\string\formatters.hpp" />
247247
<ClInclude Include="..\..\..\fly\types\string\lexer.hpp" />
248248
<ClInclude Include="..\..\..\fly\types\string\literals.hpp" />
249249
<ClInclude Include="..\..\..\fly\types\string\string.hpp" />
250+
<ClInclude Include="..\..\..\fly\types\string\string_concepts.hpp" />
250251
</ItemGroup>
251252
<ItemGroup>
252253
<ClCompile Include="..\..\..\fly\coders\base64\base64_coder.cpp" />

build/win/libfly/libfly.vcxproj.filters

+4-1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@
298298
<ClInclude Include="..\..\..\fly\types\string\string.hpp">
299299
<Filter>types\string</Filter>
300300
</ClInclude>
301+
<ClInclude Include="..\..\..\fly\types\string\string_concepts.hpp">
302+
<Filter>types\string</Filter>
303+
</ClInclude>
301304
<ClInclude Include="..\..\..\fly\types\string\detail\classifier.hpp">
302305
<Filter>types\string\detail</Filter>
303306
</ClInclude>
@@ -325,7 +328,7 @@
325328
<ClInclude Include="..\..\..\fly\types\string\detail\stream_util.hpp">
326329
<Filter>types\string\detail</Filter>
327330
</ClInclude>
328-
<ClInclude Include="..\..\..\fly\types\string\detail\string_concepts.hpp">
331+
<ClInclude Include="..\..\..\fly\types\string\detail\string_concepts_helpers.hpp">
329332
<Filter>types\string\detail</Filter>
330333
</ClInclude>
331334
<ClInclude Include="..\..\..\fly\types\string\detail\string_traits.hpp">

fly/types/json/json.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "fly/types/json/json_types.hpp"
1010
#include "fly/types/numeric/literals.hpp"
1111
#include "fly/types/string/string.hpp"
12+
#include "fly/types/string/string_concepts.hpp"
1213

1314
#include <concepts>
1415
#include <cstddef>
@@ -2000,7 +2001,7 @@ bool Json::contains(T key) const
20002001
template <JsonStringLike T>
20012002
json_string_type Json::convert_to_string(T value)
20022003
{
2003-
using StringType = BasicString<detail::StandardCharacterType<T>>;
2004+
using StringType = BasicString<fly::StandardCharacterType<T>>;
20042005

20052006
if constexpr (fly::SameAs<typename StringType::string_type, json_string_type>)
20062007
{

fly/types/json/json_concepts.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "fly/concepts/concepts.hpp"
44
#include "fly/types/json/json_types.hpp"
5-
#include "fly/types/string/detail/string_concepts.hpp"
5+
#include "fly/types/string/string_concepts.hpp"
66

77
#include <array>
88
#include <deque>
@@ -57,13 +57,13 @@ concept JsonNull = fly::SameAs<T, json_null_type>;
5757
* Concept that is satisfied when the given type is a supported JSON string type.
5858
*/
5959
template <typename T>
60-
concept JsonString = fly::detail::StandardString<T>;
60+
concept JsonString = fly::StandardString<T>;
6161

6262
/**
6363
* Concept that is satisfied when the given type is a supported JSON string type.
6464
*/
6565
template <typename T>
66-
concept JsonStringLike = fly::detail::StandardStringLike<T>;
66+
concept JsonStringLike = fly::StandardStringLike<T>;
6767

6868
/**
6969
* Concept that is satisfied when the given type is a supported JSON object type.

fly/types/string/detail/classifier.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

3-
#include "fly/types/string/detail/string_concepts.hpp"
43
#include "fly/types/string/detail/string_traits.hpp"
54
#include "fly/types/string/literals.hpp"
5+
#include "fly/types/string/string_concepts.hpp"
66

77
#include <string>
88

@@ -33,7 +33,7 @@ class BasicClassifier
3333
*
3434
* @return The length of the string-like value.
3535
*/
36-
template <StandardStringLike T>
36+
template <fly::StandardStringLike T>
3737
static constexpr size_type size(T &&value);
3838

3939
/**
@@ -187,7 +187,7 @@ class BasicClassifier
187187

188188
//==================================================================================================
189189
template <typename CharType>
190-
template <StandardStringLike T>
190+
template <fly::StandardStringLike T>
191191
constexpr auto BasicClassifier<CharType>::size(T &&value) -> size_type
192192
{
193193
using U = std::remove_cvref_t<T>;

fly/types/string/detail/format_parameter_type.hpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "fly/types/string/detail/string_concepts.hpp"
3+
#include "fly/types/string/string_concepts.hpp"
44

55
#include <cstdint>
66

@@ -30,27 +30,27 @@ enum class ParameterType : std::uint8_t
3030
template <typename T>
3131
constexpr ParameterType infer_parameter_type()
3232
{
33-
if constexpr (StandardCharacter<T>)
33+
if constexpr (fly::StandardCharacter<T>)
3434
{
3535
return ParameterType::Character;
3636
}
37-
else if constexpr (FormattableString<T>)
37+
else if constexpr (fly::FormattableString<T>)
3838
{
3939
return ParameterType::String;
4040
}
41-
else if constexpr (FormattablePointer<T>)
41+
else if constexpr (fly::FormattablePointer<T>)
4242
{
4343
return ParameterType::Pointer;
4444
}
45-
else if constexpr (FormattableIntegral<T>)
45+
else if constexpr (fly::FormattableIntegral<T>)
4646
{
4747
return ParameterType::Integral;
4848
}
49-
else if constexpr (FormattableFloatingPoint<T>)
49+
else if constexpr (fly::FormattableFloatingPoint<T>)
5050
{
5151
return ParameterType::FloatingPoint;
5252
}
53-
else if constexpr (FormattableBoolean<T>)
53+
else if constexpr (fly::FormattableBoolean<T>)
5454
{
5555
return ParameterType::Boolean;
5656
}

fly/types/string/detail/format_parameters.hpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include "fly/types/string/detail/classifier.hpp"
55
#include "fly/types/string/detail/format_parse_context.hpp"
66
#include "fly/types/string/detail/format_specifier.hpp"
7-
#include "fly/types/string/detail/string_concepts.hpp"
87
#include "fly/types/string/formatters.hpp"
8+
#include "fly/types/string/string_concepts.hpp"
99

1010
#include <array>
1111
#include <cstdint>
@@ -152,7 +152,7 @@ class BasicFormatParameter
152152
*
153153
* @param value The user-defined value.
154154
*/
155-
template <FormattableUserDefined T>
155+
template <fly::FormattableUserDefined T>
156156
explicit constexpr BasicFormatParameter(const T &value) noexcept;
157157

158158
/**
@@ -163,7 +163,7 @@ class BasicFormatParameter
163163
*
164164
* @param value The string-like value.
165165
*/
166-
template <FormattableString T>
166+
template <fly::FormattableString T>
167167
explicit constexpr BasicFormatParameter(const T &value) noexcept;
168168

169169
/**
@@ -173,7 +173,7 @@ class BasicFormatParameter
173173
*
174174
* @param value The pointer value.
175175
*/
176-
template <FormattablePointer T>
176+
template <fly::FormattablePointer T>
177177
explicit constexpr BasicFormatParameter(T value) noexcept;
178178

179179
/**
@@ -183,7 +183,7 @@ class BasicFormatParameter
183183
*
184184
* @param value The integral value.
185185
*/
186-
template <FormattableIntegral T>
186+
template <fly::FormattableIntegral T>
187187
explicit constexpr BasicFormatParameter(T value) noexcept;
188188

189189
/**
@@ -193,7 +193,7 @@ class BasicFormatParameter
193193
*
194194
* @param value The floating-point value.
195195
*/
196-
template <FormattableFloatingPoint T>
196+
template <fly::FormattableFloatingPoint T>
197197
explicit constexpr BasicFormatParameter(T value) noexcept;
198198

199199
/**
@@ -203,7 +203,7 @@ class BasicFormatParameter
203203
*
204204
* @param value The boolean value.
205205
*/
206-
template <FormattableBoolean T>
206+
template <fly::FormattableBoolean T>
207207
explicit constexpr BasicFormatParameter(T value) noexcept;
208208

209209
/**
@@ -408,7 +408,7 @@ constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter() noexcept :
408408

409409
//==================================================================================================
410410
template <typename FormatContext>
411-
template <FormattableUserDefined T>
411+
template <fly::FormattableUserDefined T>
412412
constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(const T &value) noexcept :
413413
m_type(Type::UserDefined),
414414
m_value {.m_user_defined {&value, format_user_defined_value<FormatContext, T>}}
@@ -417,13 +417,13 @@ constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(const T &val
417417

418418
//==================================================================================================
419419
template <typename FormatContext>
420-
template <FormattableString T>
420+
template <fly::FormattableString T>
421421
constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(const T &value) noexcept :
422422
m_type(Type::String)
423423
{
424424
using U = std::remove_cvref_t<T>;
425425

426-
using standard_character_type = detail::StandardCharacterType<T>;
426+
using standard_character_type = fly::StandardCharacterType<T>;
427427
using standard_view_type = std::basic_string_view<standard_character_type>;
428428

429429
standard_view_type view;
@@ -445,7 +445,7 @@ constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(const T &val
445445

446446
//==================================================================================================
447447
template <typename FormatContext>
448-
template <FormattablePointer T>
448+
template <fly::FormattablePointer T>
449449
constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(T value) noexcept :
450450
m_type(Type::Pointer),
451451
m_value {.m_standard {.m_pointer {value}, .m_format {format_standard_value<FormatContext, T>}}}
@@ -454,7 +454,7 @@ constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(T value) noe
454454

455455
//==================================================================================================
456456
template <typename FormatContext>
457-
template <FormattableIntegral T>
457+
template <fly::FormattableIntegral T>
458458
constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(T value) noexcept
459459
{
460460
m_value.m_standard.m_format = format_standard_value<FormatContext, T>;
@@ -473,7 +473,7 @@ constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(T value) noe
473473

474474
//==================================================================================================
475475
template <typename FormatContext>
476-
template <FormattableFloatingPoint T>
476+
template <fly::FormattableFloatingPoint T>
477477
constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(T value) noexcept
478478
{
479479
m_value.m_standard.m_format = format_standard_value<FormatContext, T>;
@@ -497,7 +497,7 @@ constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(T value) noe
497497

498498
//==================================================================================================
499499
template <typename FormatContext>
500-
template <FormattableBoolean T>
500+
template <fly::FormattableBoolean T>
501501
constexpr BasicFormatParameter<FormatContext>::BasicFormatParameter(T value) noexcept :
502502
m_type(Type::Bool),
503503
m_value {.m_standard {.m_bool {value}, .m_format {format_standard_value<FormatContext, T>}}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#pragma once
2+
3+
#include "fly/concepts/concepts.hpp"
4+
5+
#include <string>
6+
#include <type_traits>
7+
8+
namespace fly::detail {
9+
10+
/**
11+
* Concept that is satisfied when the given type is like a supported std::basic_string
12+
* specialization. A type is "like" a std::basic_string specialization if it is that specialization
13+
* itself, a C-string equalivent, or a std::basic_string_view specialization.
14+
*/
15+
template <typename T, typename CharType>
16+
concept IsLikeStandardString = fly::SameAsAny<
17+
std::decay_t<T>, // Decay to perform array-to-pointer conversion (e.g. char[] to char*).
18+
CharType *,
19+
CharType const *,
20+
std::basic_string<CharType>,
21+
std::basic_string_view<CharType>>;
22+
23+
/**
24+
* Concept that is satisfied when the given type is like a supported std::basic_string
25+
* specialization. A type is "like" a std::basic_string specialization if it is that specialization
26+
* itself, a C-string equalivent, or a std::basic_string_view specialization.
27+
*/
28+
template <typename T>
29+
struct StandardStringType
30+
{
31+
using string_type = std::conditional_t<
32+
IsLikeStandardString<T, char>,
33+
std::string,
34+
std::conditional_t<
35+
IsLikeStandardString<T, wchar_t>,
36+
std::wstring,
37+
std::conditional_t<
38+
IsLikeStandardString<T, char8_t>,
39+
std::u8string,
40+
std::conditional_t<
41+
IsLikeStandardString<T, char16_t>,
42+
std::u16string,
43+
std::conditional_t<
44+
IsLikeStandardString<T, char32_t>,
45+
std::u32string,
46+
std::false_type>>>>>;
47+
48+
using char_type = std::conditional_t<
49+
fly::SameAs<string_type, std::false_type>,
50+
std::false_type,
51+
typename string_type::value_type>;
52+
};
53+
54+
} // namespace fly::detail

fly/types/string/detail/string_traits.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "fly/types/string/detail/string_concepts.hpp"
3+
#include "fly/types/string/string_concepts.hpp"
44

55
#include <cstdint>
66
#include <string>
@@ -13,7 +13,7 @@ namespace fly::detail {
1313
* @author Timothy Flynn ([email protected])
1414
* @version March 23, 2019
1515
*/
16-
template <StandardCharacter CharType>
16+
template <fly::StandardCharacter CharType>
1717
struct BasicStringTraits
1818
{
1919
using string_type = std::basic_string<CharType>;

0 commit comments

Comments
 (0)