stl: functional.hpp for identity
This commit is contained in:
@@ -194,6 +194,7 @@ if(ENTT_INCLUDE_HEADERS)
|
||||
signal/emitter.hpp
|
||||
signal/fwd.hpp
|
||||
signal/sigh.hpp
|
||||
stl/functional.hpp
|
||||
stl/memory.hpp
|
||||
tools/davey.hpp
|
||||
entt.hpp
|
||||
|
||||
@@ -65,5 +65,6 @@ namespace entt {}
|
||||
#include "signal/dispatcher.hpp"
|
||||
#include "signal/emitter.hpp"
|
||||
#include "signal/sigh.hpp"
|
||||
#include "stl/functional.hpp"
|
||||
#include "stl/memory.hpp"
|
||||
// IWYU pragma: end_exports
|
||||
|
||||
35
src/entt/stl/functional.hpp
Normal file
35
src/entt/stl/functional.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef ENTT_STL_FUNCTIONAL_HPP
|
||||
#define ENTT_STL_FUNCTIONAL_HPP
|
||||
|
||||
#include "../config/config.h"
|
||||
|
||||
namespace entt::stl {
|
||||
|
||||
#ifndef ENTT_FORCE_STL
|
||||
# if __has_include(<version>)
|
||||
# include <version>
|
||||
#
|
||||
# if defined(__cpp_lib_ranges)
|
||||
# define ENTT_HAS_IDENTITY
|
||||
# include <functional>
|
||||
using std::identity;
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef ENTT_HAS_IDENTITY
|
||||
# include <utility>
|
||||
|
||||
struct identity {
|
||||
using is_transparent = void;
|
||||
|
||||
template<typename Type>
|
||||
[[nodiscard]] constexpr Type &&operator()(Type &&value) const noexcept {
|
||||
return std::forward<Type>(value);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace entt::stl
|
||||
|
||||
#endif
|
||||
@@ -304,4 +304,5 @@ SETUP_BASIC_TEST(sigh entt/signal/sigh.cpp)
|
||||
|
||||
# Test stl
|
||||
|
||||
SETUP_BASIC_TEST(stl_functional entt/stl/functional.cpp ENTT_USE_STL)
|
||||
SETUP_BASIC_TEST(stl_memory entt/stl/memory.cpp ENTT_USE_STL)
|
||||
|
||||
13
test/entt/stl/functional.cpp
Normal file
13
test/entt/stl/functional.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <memory>
|
||||
#include <gtest/gtest.h>
|
||||
#include <entt/core/type_traits.hpp>
|
||||
#include <entt/stl/functional.hpp>
|
||||
|
||||
TEST(Identity, Functionalities) {
|
||||
const entt::stl::identity identity;
|
||||
int value = 2;
|
||||
|
||||
ASSERT_TRUE(entt::is_transparent_v<entt::stl::identity>);
|
||||
ASSERT_EQ(identity(value), value);
|
||||
ASSERT_EQ(&identity(value), &value);
|
||||
}
|
||||
Reference in New Issue
Block a user