Add helpers to ReversedSizedArray.
This commit is contained in:
parent
ab74f8ab3a
commit
14954a3816
3 changed files with 70 additions and 35 deletions
|
@ -21,6 +21,11 @@
|
|||
#include <array>
|
||||
#include <type_traits>
|
||||
#include <stdexcept>
|
||||
#if !defined(INT_CONV_WITHOUT_HELPERS)
|
||||
# include <string_view>
|
||||
# include <string>
|
||||
# include <sstream>
|
||||
#endif
|
||||
|
||||
namespace dhandy {
|
||||
template <typename T, std::size_t S>
|
||||
|
@ -41,10 +46,28 @@ namespace dhandy {
|
|||
constexpr iterator begin() { return m_data.begin() + m_curr + 1; }
|
||||
constexpr iterator end() { return m_data.end(); }
|
||||
|
||||
#if !defined(INT_CONV_WITHOUT_HELPERS)
|
||||
constexpr std::string_view to_string_view() const { return std::string_view(data(), size() - 1); }
|
||||
bool operator== (const std::string_view& other) const { return to_string_view() == other; }
|
||||
bool operator!= (const std::string_view& other) const { return not operator==(other); }
|
||||
bool operator== (const std::string& other) const { return to_string_view() == other; }
|
||||
bool operator!= (const std::string& other) const { return not operator==(other); }
|
||||
bool operator== (const char* other) const { return to_string_view() == std::string_view(other); }
|
||||
bool operator!= (const char* other) const { return not operator==(other); }
|
||||
#endif
|
||||
|
||||
private:
|
||||
std::array<T, S> m_data {};
|
||||
std::size_t m_curr {S - 1};
|
||||
};
|
||||
|
||||
#if !defined(INT_CONV_WITHOUT_HELPERS)
|
||||
template <typename T, std::size_t S>
|
||||
std::basic_ostream<T>& operator<< (std::basic_ostream<T>& stream, const ReversedSizedArray<T, S>& arr) {
|
||||
stream << arr.to_string_view();
|
||||
return stream;
|
||||
}
|
||||
#endif
|
||||
} //namespace dhandy
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
#if defined(__SSE4_1__)
|
||||
# include <smmintrin.h>
|
||||
#endif
|
||||
#if !defined(INT_CONV_WITHOUT_HELPERS)
|
||||
# include <string_view>
|
||||
# include <string>
|
||||
#endif
|
||||
|
||||
namespace dhandy {
|
||||
namespace implem {
|
||||
|
@ -286,6 +290,13 @@ namespace dhandy {
|
|||
inline R ary_to_int (C* beg, C* end) {
|
||||
return implem::AryConversion<R, Base, Tr>::from_ary(beg, end);
|
||||
}
|
||||
|
||||
#if !defined(INT_CONV_WITHOUT_HELPERS)
|
||||
template <typename I>
|
||||
std::string to_string (I num) {
|
||||
return std::string(int_to_ary(num).to_string_view());
|
||||
}
|
||||
#endif
|
||||
} //namespace dhandy
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue