Skip to content

Commit

Permalink
Use string_view for ct_string comparisons cos of better constexpr sup…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
rupertnash committed Dec 19, 2023
1 parent 28023a0 commit e6205c6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Code/util/ct_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <cstddef>
#include <string>
#include <string_view>
#include <type_traits>

namespace hemelb {
Expand All @@ -33,6 +34,9 @@ namespace hemelb {
constexpr std::string str() const {
return {str_, N};
}
constexpr std::string_view view() const {
return {str_, N};
}

constexpr char const *c_str() const {
return str_;
Expand All @@ -45,12 +49,12 @@ namespace hemelb {

template <std::size_t M, std::size_t N>
constexpr auto operator==(const ct_string<M>& left, const ct_string<N>& right) {
return left.str() == right.str();
return left.view() == right.view();
}

template <std::size_t N>
constexpr auto operator==(const ct_string<N>& left, const char* right) {
return left.str() == std::string{right};
return left.view() == std::string_view{right};
}
template <std::size_t N>
constexpr auto operator==(const char* left, const ct_string<N> right) {
Expand Down

0 comments on commit e6205c6

Please sign in to comment.