简体   繁体   中英

C++ - typedef/using for function template

I've got a following function template:

template<class A, class C, class B>
A doFoo(const B &val)
{
  //do something with C
}

Within my cpp file, all doFoo function will be used with one type for C . Is it possible to do such kind of typedef:

typedef myDoFoo<A, B> doFoo<A, ParticularC, B>

If it is - what is a correct syntax to do this?

Just define another template function:

template<class A, class B>
A myDoFoo(const B &val)
{
  return doFoo<A,ParticularC,B>( val );
}

You may write a function:

template<class A, class B>
A myDoFoo(const B &val)
{
    return doFoo<A, ParticularC, B>(val);
}

Using variable templates (available in GCC since version 5), you can define a reference to your function:

template<class A, class B> auto &myDoFoo = doFoo<A, ParticularC, B>;

or more explicitly

template<class A, class B> A (&myDoFoo)(const B &) = doFoo<A, ParticularC, B>;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM