iterator: added utility input_iterator_proxy
This commit is contained in:
43
src/entt/core/iterator.hpp
Normal file
43
src/entt/core/iterator.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef ENTT_CORE_ITERATOR_HPP
|
||||
#define ENTT_CORE_ITERATOR_HPP
|
||||
|
||||
#include <memory>
|
||||
#include "../config/config.h"
|
||||
|
||||
namespace entt {
|
||||
|
||||
/**
|
||||
* @brief Helper type to use as pointer with input iterators.
|
||||
* @tparam Type of wrapped value.
|
||||
*/
|
||||
template<typename Type>
|
||||
struct input_iterator_proxy {
|
||||
/**
|
||||
* @brief Constructs a proxy object from a given value.
|
||||
* @param val Value to use to initialize the proxy object.
|
||||
*/
|
||||
input_iterator_proxy(Type &&val)
|
||||
: value{std::forward<Type>(val)} {}
|
||||
|
||||
/**
|
||||
* @brief Access operator for accessing wrapped values.
|
||||
* @return A pointer to the wrapped value.
|
||||
*/
|
||||
Type *operator->() ENTT_NOEXCEPT {
|
||||
return std::addressof(value);
|
||||
}
|
||||
|
||||
private:
|
||||
Type value;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Deduction guide.
|
||||
* @tparam Type Type of wrapped value.
|
||||
*/
|
||||
template<typename Type>
|
||||
input_iterator_proxy(Type &&) -> input_iterator_proxy<Type>;
|
||||
|
||||
} // namespace entt
|
||||
|
||||
#endif
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "core/family.hpp"
|
||||
#include "core/hashed_string.hpp"
|
||||
#include "core/ident.hpp"
|
||||
#include "core/iterator.hpp"
|
||||
#include "core/memory.hpp"
|
||||
#include "core/monostate.hpp"
|
||||
#include "core/tuple.hpp"
|
||||
|
||||
@@ -168,6 +168,7 @@ SETUP_BASIC_TEST(enum entt/core/enum.cpp)
|
||||
SETUP_BASIC_TEST(family entt/core/family.cpp)
|
||||
SETUP_BASIC_TEST(hashed_string entt/core/hashed_string.cpp)
|
||||
SETUP_BASIC_TEST(ident entt/core/ident.cpp)
|
||||
SETUP_BASIC_TEST(iterator entt/core/iterator.cpp)
|
||||
SETUP_BASIC_TEST(memory entt/core/memory.cpp)
|
||||
SETUP_BASIC_TEST(monostate entt/core/monostate.cpp)
|
||||
SETUP_BASIC_TEST(tuple entt/core/tuple.cpp)
|
||||
|
||||
13
test/entt/core/iterator.cpp
Normal file
13
test/entt/core/iterator.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/core/iterator.hpp>
|
||||
|
||||
struct clazz {
|
||||
int value{0};
|
||||
};
|
||||
|
||||
TEST(Iterator, InputIteratorProxy) {
|
||||
entt::input_iterator_proxy proxy{clazz{}};
|
||||
proxy->value = 42;
|
||||
|
||||
ASSERT_EQ(proxy->value, 42);
|
||||
}
|
||||
Reference in New Issue
Block a user