mardi 24 juillet 2018

Shortening the std::function

I want to shorten the typing of std::function<bool(int)> to just func<bool(int)> in my own namespace. It's just a personal preference.

I tried the following code below but I'm encountering syntax errors.

//MyHeader.hpp
template<typename S> struct func; //signature

template<typename R, typename ...Args>
struct func<R(Args...)>;

template<typename R, typename ...Args>
//typename typedef std::function<R(Args...)> func; // <R(Args...)>;
using func = std::function<R(Args...)>;  //<---closes to solve.


//SomeClass.cpp
func<bool(int)> f;
func<void()> g = [] {
    //some code here...
}

How can I achieve this?

Aucun commentaire:

Enregistrer un commentaire