Added operators to BoxedObject, fixed MappintIterator for reference types and fixed signature of custom assertion and error handlers.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
#include <variant>
|
||||
#include "../container/optional.hpp"
|
||||
|
||||
namespace mijin
|
||||
{
|
||||
@@ -277,7 +278,7 @@ struct MappingIterator
|
||||
{
|
||||
using orig_value_type = typename std::iterator_traits<TIterator>::value_type;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using value_type = std::invoke_result_t<TFunctor, orig_value_type>;
|
||||
using value_type = std::invoke_result_t<TFunctor, orig_value_type&>;
|
||||
using reference = value_type&;
|
||||
using iterator_category = std::bidirectional_iterator_tag; // TODO?
|
||||
|
||||
@@ -285,7 +286,7 @@ struct MappingIterator
|
||||
|
||||
TIterator base;
|
||||
TFunctor functor;
|
||||
mutable std::optional<value_type> result;
|
||||
mutable Optional<value_type> result;
|
||||
|
||||
MappingIterator(TIterator base_, TFunctor functor_) noexcept : base(base_), functor(std::move(functor_)) {}
|
||||
MappingIterator(const MappingIterator&) noexcept = default;
|
||||
@@ -296,8 +297,8 @@ struct MappingIterator
|
||||
|
||||
reference operator*() const noexcept
|
||||
{
|
||||
if (!result.has_value()) {
|
||||
result = functor(*base);
|
||||
if (result.empty()) {
|
||||
result = std::invoke(functor, *base);
|
||||
}
|
||||
return *result;
|
||||
}
|
||||
@@ -305,7 +306,7 @@ struct MappingIterator
|
||||
MappingIterator& operator++() noexcept
|
||||
{
|
||||
++base;
|
||||
result = std::nullopt;
|
||||
result.reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -319,7 +320,7 @@ struct MappingIterator
|
||||
MappingIterator& operator--() noexcept
|
||||
{
|
||||
--base;
|
||||
result = std::nullopt;
|
||||
result.reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user