- Debugged more PrettyPrinters, all implemented thus far work in testing

- Fixed implementation of tuple.h, TODO: Still need to complete
 - Wrote a PrettyPrinter for tuple.h
This commit is contained in:
2025-08-10 23:46:36 -04:00
parent 9f96155856
commit b9de039a10
12 changed files with 170 additions and 44 deletions

View File

@@ -24,34 +24,28 @@
namespace fennec::detail
{
// leaves
template<size_t i, typename T>
struct _tuple_leaf {
T value;
template<typename...ArgsT>
_tuple_leaf(ArgsT&&...args) : value(args...) {
}
template <std::size_t I, typename T>
struct _tuple_leaf
{
template <typename ArgT>
_tuple_leaf(ArgT&& arg) : value(fennec::forward<ArgT>(arg)) {}
constexpr operator T&() {
return value;
}
~_tuple_leaf() = default;
constexpr operator const T&() const {
return value;
}
T value;
};
// proxy
template<typename, typename...TypesT>
template <typename, typename...>
struct _tuple;
template<size_t...i, typename...TypesT>
struct _tuple<index_sequence<i...>, TypesT...> : _tuple_leaf<i, TypesT>... {
template <size_t...IndicesV, typename...TypesT>
struct _tuple<index_sequence<IndicesV...>, TypesT...> : _tuple_leaf<IndicesV, TypesT>...
{
template <typename...ArgsT>
_tuple(ArgsT&&... args) : _tuple_leaf<IndicesV, TypesT>(fennec::forward<ArgsT>(args))... {}
template<typename...ArgsT>
_tuple(ArgsT&&...args) : _tuple_leaf<i, TypesT>(args)... {
}
~_tuple() = default;
};
}

View File

@@ -36,32 +36,44 @@ template<typename...TypesT> struct tuple;
template<size_t i, typename...TypesT>
constexpr typename tuple<TypesT...>::template elem_t<i>& get(tuple<TypesT...>& x) {
using elem_t = typename tuple<TypesT...>::template elem_t<i>;
auto& it = static_cast<detail::_tuple_leaf<i, elem_t>>(x);
return it;
auto& it = *static_cast<detail::_tuple_leaf<i, elem_t>*>(&x);
return it.value;
}
template<size_t i, typename...TypesT>
constexpr const typename tuple<TypesT...>::template elem_t<i>& get(tuple<TypesT...>& x) {
constexpr const typename tuple<TypesT...>::template elem_t<i>& get(const tuple<TypesT...>& x) {
using elem_t = typename tuple<TypesT...>::template elem_t<i>;
auto& it = static_cast<detail::_tuple_leaf<i, elem_t>>(x);
return it;
const auto& it = *static_cast<const detail::_tuple_leaf<i, elem_t>*>(&x);
return it.value;
}
template<typename...TypesT>
struct tuple : detail::_tuple<make_index_sequence<sizeof...(TypesT)>, TypesT...> {
public:
using base_t = detail::_tuple<make_index_sequence<sizeof...(TypesT)>, TypesT...>;
template<typename ...TypesT>
struct tuple : public detail::_tuple<make_index_sequence_t<sizeof...(TypesT)>, TypesT...>
{
using base_t = detail::_tuple<make_index_sequence_t<sizeof...(TypesT)>, TypesT...>;
template<size_t i>
using elem_t = nth_element<i, TypesT...>;
using elem_t = typename nth_element<i, TypesT...>::type;
template<typename...ArgsT>
constexpr tuple(ArgsT&&...args) : base_t(args...) {
tuple(ArgsT&&...args)
: base_t(fennec::forward<ArgsT>(args)...) {
}
tuple(const tuple& cpy)
: base_t(cpy) {
}
tuple(tuple&& cpy)
: base_t(cpy) {
}
};
// This is needed for
template<typename...TypesT>
tuple(TypesT...) -> tuple<TypesT...>;
}
#endif // FENNEC_CONTAINERS_TUPLE_H

View File

@@ -32,8 +32,8 @@ namespace fennec::detail
template<size_t n, size_t i, typename HeadT, typename...RestT>
struct _nth_element<n, i, HeadT, RestT...> : conditional<
n == i, type_identity<HeadT>,
_nth_element<n, i + 1, RestT...>
n == i, HeadT,
typename _nth_element<n, i + 1, RestT...>::type
> {};
}

View File

@@ -86,10 +86,10 @@ public:
///
/// \details adds additional character for null termination. Ignores whether str is null-terminated.
/// This constructor makes the assumption that `n` is the intended number of characters.
constexpr _string(const char* str, size_t n)
: _str(n + 1) {
constexpr _string(char* str, size_t n)
: _str(str[n - 1] == '\0' ? n : n + 1) {
fennec::memcpy(_str.data(), str, n);
_str[n] = '\0';
if (str[n - 1] != '\0') _str[n] = '\0';
}
///
@@ -97,7 +97,30 @@ public:
/// \param str the buffer to wrap
/// \tparam n the number of characters in the buffer plus the null terminator
template<size_t n>
constexpr _string(char(&str)[n])
explicit constexpr _string(char(&str)[n])
: _str(str, n) {
assert(_str[n - 1] == '\0', "Invalid NTBS.");
}
///
/// \brief Buffer Copy Constructor
/// \param str the buffer to copy
/// \param n number of characters in the buffer
///
/// \details adds additional character for null termination. Ignores whether str is null-terminated.
/// This constructor makes the assumption that `n` is the intended number of characters.
constexpr _string(const char* str, size_t n)
: _str(str[n - 1] == '\0' ? n : n + 1) {
fennec::memcpy(_str.data(), str, n);
if (str[n - 1] != '\0') _str[n] = '\0';
}
///
/// \brief Buffer Constructor, wraps the provided C-Style string
/// \param str the buffer to wrap
/// \tparam n the number of characters in the buffer plus the null terminator
template<size_t n>
explicit constexpr _string(const char(&str)[n])
: _str(str, n) {
assert(_str[n - 1] == '\0', "Invalid NTBS.");
}
@@ -385,7 +408,7 @@ public:
/// \returns
constexpr _string operator+(char c) const {
// Copy contents with one additional byte.
_string res(_str.data(), _str.size());
_string res(_str.data(), _str.size() + 1);
res[size()] = c; // Set the last character to c
return res;
}