Skip to content

Commit

Permalink
feat: basic_fixed_string contructor now can take a list of arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Jan 18, 2024
1 parent 5183a5c commit 40dcc9d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/core/include/mp-units/bits/external/fixed_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ struct basic_fixed_string {
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;

constexpr explicit basic_fixed_string(CharT ch) noexcept
requires(N == 1)
{
data_[0] = ch;
}

constexpr explicit(false) basic_fixed_string(const CharT (&txt)[N + 1]) noexcept
{
if constexpr (N != 0)
for (std::size_t i = 0; i < N; ++i) data_[i] = txt[i];
}

template<std::convertible_to<CharT>... Rest>
requires(1 + sizeof...(Rest) == N)
constexpr explicit basic_fixed_string(CharT first, Rest... rest) noexcept : data_{first, rest..., CharT('\0')}
{
}

constexpr basic_fixed_string(const CharT* ptr, std::integral_constant<std::size_t, N>) noexcept
{
if constexpr (N != 0)
Expand Down Expand Up @@ -131,12 +131,12 @@ struct basic_fixed_string {
}
};

template<typename CharT>
basic_fixed_string(CharT) -> basic_fixed_string<CharT, 1>;

template<typename CharT, std::size_t N>
basic_fixed_string(const CharT (&str)[N]) -> basic_fixed_string<CharT, N - 1>;

template<typename CharT, std::convertible_to<CharT>... Rest>
basic_fixed_string(CharT, Rest...) -> basic_fixed_string<CharT, 1 + sizeof...(Rest)>;

template<typename CharT, std::size_t N>
basic_fixed_string(const CharT* ptr, std::integral_constant<std::size_t, N>) -> basic_fixed_string<CharT, N>;

Expand Down

0 comments on commit 40dcc9d

Please sign in to comment.