mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-12 14:54:10 +00:00
add string_ref user-defined literals
This commit is contained in:
parent
2fce5bd7f9
commit
5bdb045730
7 changed files with 398 additions and 199 deletions
|
@ -77,6 +77,23 @@ namespace sprout {
|
|||
)...
|
||||
);
|
||||
}
|
||||
template<typename T, std::size_t N, typename Traits, sprout::index_t... Indexes>
|
||||
inline SPROUT_INITIALIZER_LIST_CONSTEXPR sprout::basic_string<T, N, Traits>
|
||||
string_rshift(
|
||||
sprout::basic_string<T, N, Traits> const& lhs, std::size_t lsize,
|
||||
std::initializer_list<T> rhs, std::size_t rsize,
|
||||
sprout::index_tuple<Indexes...>
|
||||
)
|
||||
{
|
||||
typedef sprout::detail::string_construct_access<T, N, Traits> access_type;
|
||||
return access_type::raw_construct(
|
||||
sprout::detail::checked_length<N>(lsize + rsize),
|
||||
(Indexes < lsize ? lhs[Indexes]
|
||||
: Indexes < lsize + rsize ? rhs.begin()[Indexes - lsize]
|
||||
: T()
|
||||
)...
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// operator<<
|
||||
|
@ -108,6 +125,15 @@ namespace sprout {
|
|||
sprout::make_index_tuple<N1>::make()
|
||||
);
|
||||
}
|
||||
template<typename T, std::size_t N, typename Traits>
|
||||
inline SPROUT_INITIALIZER_LIST_CONSTEXPR sprout::basic_string<T, N, Traits>
|
||||
operator<<(sprout::basic_string<T, N, Traits> const& lhs, std::initializer_list<T> rhs) {
|
||||
return sprout::detail::string_rshift(
|
||||
lhs, lhs.size(),
|
||||
rhs, rhs.size(),
|
||||
sprout::make_index_tuple<N>::make()
|
||||
);
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template<typename T, std::size_t N, typename Traits, sprout::index_t... Indexes>
|
||||
|
@ -161,6 +187,23 @@ namespace sprout {
|
|||
)...
|
||||
);
|
||||
}
|
||||
template<typename T, std::size_t N, typename Traits, sprout::index_t... Indexes>
|
||||
inline SPROUT_INITIALIZER_LIST_CONSTEXPR sprout::basic_string<T, N, Traits>
|
||||
string_lshift(
|
||||
sprout::basic_string<T, N, Traits> const& lhs, std::size_t lsize,
|
||||
std::initializer_list<T> rhs, std::size_t rsize,
|
||||
sprout::index_tuple<Indexes...>
|
||||
)
|
||||
{
|
||||
typedef sprout::detail::string_construct_access<T, N, Traits> access_type;
|
||||
return access_type::raw_construct(
|
||||
sprout::detail::checked_length<N>(rsize + lsize),
|
||||
(Indexes < rsize ? rhs.begin()[Indexes]
|
||||
: Indexes < rsize + lsize ? lhs[Indexes - rsize]
|
||||
: T()
|
||||
)...
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// operator>>
|
||||
|
@ -192,6 +235,15 @@ namespace sprout {
|
|||
sprout::make_index_tuple<N1>::make()
|
||||
);
|
||||
}
|
||||
template<typename T, std::size_t N, typename Traits>
|
||||
inline SPROUT_INITIALIZER_LIST_CONSTEXPR sprout::basic_string<T, N, Traits>
|
||||
operator>>(sprout::basic_string<T, N, Traits> const& lhs, std::initializer_list<T> rhs) {
|
||||
return sprout::detail::string_lshift(
|
||||
lhs, lhs.size(),
|
||||
rhs, rhs.size(),
|
||||
sprout::make_index_tuple<N>::make()
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_STRING_SHIFT_CONCAT_HPP
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue