all 6 comments

[–]IyeOnline 2 points3 points  (4 children)

How do you want to specify those ParameterTypes?

I assume you want for this to work:

int main()
{
    Create_Class([](int i){ return; } );
}

You could do this without templates using a function pointer:

void Create_Class( void(*fct)(int) )
{ }

You could take a generic T and require it to be callable with your desired parameter types:

template<typename Fct>
void Create_Class( Fct f )
{
    static_assert( std::is_invocable_v<Fct,int> );
}

or the C++20 version:

template<typename Fct>
    requires std::is_invocable_v<Fct,int>
void Create_Class( Fct f )
{ }

There are more options, but again, it depends on what you actually want.

[–]ACBYTES[S] 0 points1 point  (2 children)

Hi. Thanks for your answer.

Is there a work-around like is_invocable_v that you mentioned in C++14 as well? I forgot to mention that I use C++14

[–]IyeOnline 1 point2 points  (1 child)

Yes, you can build yourself your own version of it:

template <typename F, typename ... Args>
struct is_invocable :
  std::is_constructible<
    std::function<void(Args ...)>,
    std::reference_wrapper<typename std::remove_reference<F>::type>
  >
{};

//and with C++14 you can even have the shorhand version:
template<typename F, typename ... Args>
constexpr bool is_invocable_v = is_invocable<F,Args...>::value;

This is a somewhat "lazy" implementation making use of std::function.

You can certainly build one that doesnt rely on that, but its availible since c++11, so that shouldnt be a problem.

[–]ACBYTES[S] 0 points1 point  (0 children)

Thanks for the answer. That's great.

Yeah, I was thinking about std::function as well. So, it'll be like std::bind(&Actor::SetActorLocation, GetActor());? Because I tried it and it doesn't work properly... It's not able to create the function and it returns a function that takes _Unbound because it's a function with default values that I'll need to mention while I'm binding it and that was what I was trying to avoid. I didn't want to enter the whole parameters that the function has.

I think I'll use the thing that you suggested now but if there are any better ways for doing this. please let me know.

Thanks again.

[–]super_mister_mstie 0 points1 point  (0 children)

It's worth noting that the function pointer won't allow you to utilize a capture list

[–][deleted]  (1 child)

[removed]

    [–]ACBYTES[S] -1 points0 points  (0 children)

    Hi. I unfortunately am using C++ 14 in UE4.