Skip to content

Commit

Permalink
api: all nullptr compatible types (except slice) writes <nil> to std:…
Browse files Browse the repository at this point in the history
…:ostream if it is nil
  • Loading branch information
mertcandav committed Mar 27, 2024
1 parent 1d5430e commit f5986ef
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/any.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ namespace jule
if (src.operator!=(nullptr))
stream << src.type->to_str(src.data);
else
stream << 0;
stream << "<nil>";
return stream;
}
};
Expand Down
8 changes: 5 additions & 3 deletions api/fn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ namespace jule
return this->_addr;
}

inline Fn<Function>& operator=(std::nullptr_t) noexcept
inline Fn<Function> &operator=(std::nullptr_t) noexcept
{
this->buffer = nullptr;
return *this;
}

inline Fn<Function>& operator=(const std::function<Function> &function)
inline Fn<Function> &operator=(const std::function<Function> &function)
{
this->buffer = function;
return *this;
}

inline Fn<Function>& operator=(const Function &function)
inline Fn<Function> &operator=(const Function &function)
{
this->buffer = function;
return *this;
Expand Down Expand Up @@ -130,6 +130,8 @@ namespace jule
friend std::ostream &operator<<(std::ostream &stream,
const Fn<Function> &src) noexcept
{
if (src == nullptr)
return (stream << "<nil>");
return (stream << (void *)src._addr);
}
};
Expand Down
2 changes: 1 addition & 1 deletion api/ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ namespace jule
const jule::Ptr<T> &ref) noexcept
{
if (ref == nullptr)
stream << "nil";
stream << "<nil>";
else
stream << ref.alloc;
return stream;
Expand Down
2 changes: 2 additions & 0 deletions api/trait.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ namespace jule
friend inline std::ostream &operator<<(std::ostream &stream,
const jule::Trait<Mask> &src) noexcept
{
if (src == nullptr)
return stream << "<nil>";
return stream << (void *)src.data.alloc;
}
};
Expand Down

0 comments on commit f5986ef

Please sign in to comment.