Skip to content

Commit

Permalink
test existing functionality related to function pointers
Browse files Browse the repository at this point in the history
Signed-off-by: Valentyn Yukhymenko <valentin.yukhymenko@gmail.com>
  • Loading branch information
BaLiKfromUA committed Aug 27, 2024
1 parent 7a47147 commit 10fff74
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions libcxx/test/std/experimental/reflection/reflect-invoke.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,36 @@ static_assert(std::meta::reflect_value(true) ==

} // namespace non_static_member_functions

namespace function_pointer {
// pointer to simple function
constexpr int foo(int a) {
return a + 42;
}

constexpr int (*foo_pointer)(int) = &foo;
static_assert(reflect_invoke(^^foo_pointer, {std::meta::reflect_value(1)})
== std::meta::reflect_value(43));

// pointer to template function
template <typename T>
constexpr T bar(T a) {
return a + 42;
}

constexpr int (*bar_pointer)(int) = &bar<int>;
static_assert(reflect_invoke(^^bar_pointer, {std::meta::reflect_value(1)})
== std::meta::reflect_value(43));

// pointer to methods
struct Cls {
static constexpr int fn(int p) { return p * p; }
};

// pointer to static method
constexpr int (*fn_pointer)(int) = &Cls::fn;
static_assert(reflect_invoke(^^fn_pointer, {std::meta::reflect_value(2)})
== std::meta::reflect_value(4));

} // namespace function_pointer

int main() { }

0 comments on commit 10fff74

Please sign in to comment.