Browse Source

type_traits: lambda support for nth_argument - close #1127

Michele Caini 2 years ago
parent
commit
56edea562a
2 changed files with 11 additions and 3 deletions
  1. 6 3
      src/entt/core/type_traits.hpp
  2. 5 0
      test/entt/core/type_traits.cpp

+ 6 - 3
src/entt/core/type_traits.hpp

@@ -873,9 +873,9 @@ template<typename Member>
 using member_class_t = typename member_class<Member>::type;
 
 /**
- * @brief Extracts the n-th argument of a given function or member function.
+ * @brief Extracts the n-th argument of a _callable_ type.
  * @tparam Index The index of the argument to extract.
- * @tparam Candidate A valid function, member function or data member type.
+ * @tparam Candidate A valid _callable_ type.
  */
 template<std::size_t Index, typename Candidate>
 class nth_argument {
@@ -891,8 +891,11 @@ class nth_argument {
     template<typename Type, typename Class>
     static constexpr type_list<Type> pick_up(Type Class ::*);
 
+    template<typename Type>
+    static constexpr decltype(pick_up(&Type::operator())) pick_up(Type &&);
+
 public:
-    /*! @brief N-th argument of the given function or member function. */
+    /*! @brief N-th argument of the _callable_ type. */
     using type = type_list_element_t<Index, decltype(pick_up(std::declval<Candidate>()))>;
 };
 

+ 5 - 0
test/entt/core/type_traits.cpp

@@ -265,6 +265,11 @@ TEST(NthArgument, Functionalities) {
     testing::StaticAssertTypeEq<entt::nth_argument_t<0u, decltype(&clazz::quux)>, bool>();
 
     ASSERT_EQ(free_function(entt::nth_argument_t<0u, decltype(&free_function)>{}, entt::nth_argument_t<1u, decltype(&free_function)>{}), 64);
+
+    [[maybe_unused]] auto lambda = [value = 0u](int, float &) { return value; };
+
+    testing::StaticAssertTypeEq<entt::nth_argument_t<0u, decltype(lambda)>, int>();
+    testing::StaticAssertTypeEq<entt::nth_argument_t<1u, decltype(lambda)>, float &>();
 }
 
 TEST(Tag, Functionalities) {