Skip to content

Commit e691299

Browse files
author
pippocao
committed
Compiling issue fix
1 parent c654c8e commit e691299

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

include/bq_common/types/string_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ namespace bq {
7272
template <typename CHAR_TYPE, typename Allocator>
7373
template <typename S, typename>
7474
inline bq::BQ_STRING_CLS_NAME<CHAR_TYPE, Allocator>::BQ_STRING_CLS_NAME(const S& rhs)
75-
: BQ_STRING_CLS_NAME(rhs.size() > 0 ? nullptr : nullptr, rhs.size())
75+
: BQ_STRING_CLS_NAME(rhs.size() > 0 ? string_tools::__bq_string_compatible_class_get_data(rhs) : nullptr, rhs.size())
7676
{
7777
}
7878

@@ -114,7 +114,7 @@ namespace bq {
114114
template <typename S, typename>
115115
BQ_STRING_INLINE BQ_STRING_CLS_NAME<CHAR_TYPE, Allocator>& BQ_STRING_CLS_NAME<CHAR_TYPE, Allocator>::operator=(const S& rhs)
116116
{
117-
this->operator=(nullptr);
117+
this->operator=(string_tools::__bq_string_compatible_class_get_data(rhs));
118118
return *this;
119119
}
120120

include/bq_common/types/string_tools.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,35 @@
2626

2727
namespace bq {
2828
namespace string_tools {
29+
template <typename T, typename = void>
30+
struct __has_value_type : bq::false_type {};
31+
32+
template <typename T>
33+
struct __has_value_type<T, bq::void_t<typename T::value_type>> : bq::true_type {};
34+
35+
template <typename T>
36+
struct is_c_str_compatible : bq::bool_type<bq::string::template is_std_string_compatible<T>::value ||
37+
bq::u16string::template is_std_string_compatible<T>::value ||
38+
bq::u32string::template is_std_string_compatible<T>::value> {
39+
};
40+
41+
template <typename T>
42+
struct is_data_compatible : bq::bool_type<bq::string::template is_std_string_view_compatible<T>::value ||
43+
bq::u16string::template is_std_string_view_compatible<T>::value ||
44+
bq::u32string::template is_std_string_view_compatible<T>::value> {
45+
};
46+
47+
template <typename T>
48+
inline auto __bq_string_compatible_class_get_data(const T& str) -> bq::enable_if_t<is_c_str_compatible<T>::value, const typename T::value_type*>
49+
{
50+
return str.c_str();
51+
}
52+
53+
template <typename T>
54+
inline auto __bq_string_compatible_class_get_data(const T& str) -> bq::enable_if_t<is_data_compatible<T>::value, const typename T::value_type*>
55+
{
56+
return str.data();
57+
}
2958

3059
/**
3160
* @brief Fallback loop for compile-time constant evaluation.

0 commit comments

Comments
 (0)