Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8421869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:16:14+00:00 2026-06-10T03:16:14+00:00

Why do we still use structures and typedef s (or using s) for metaprogramming?

  • 0

Why do we still use structures and typedefs (or usings) for metaprogramming?

Look at the code in this question – Inferring the call signature of a lambda or arbitrary callable for "make_function" :

template<typename T> struct remove_class { };
template<typename C, typename R, typename... A>
struct remove_class<R(C::*)(A...)> { using type = R(A...); };

template<typename T, bool> struct get_signature_impl { };
template<typename R, typename... A>
struct get_signature_impl<R(A...), true> { using type = R(A...); };
template<typename R, typename... A>
struct get_signature_impl<R(*)(A...), true> { using type = R(A...); };
template<typename T>
struct get_signature_impl<T, true> { using type = typename remove_class<
    decltype(&std::remove_reference<T>::type::operator())>::type; };

There is a lot of weird tricks like that bool, noisy keywords like typename, redundant stuff like struct get_signature_impl;.
It’s great that we got the using keyword in C++11, but it doesn’t make much difference.

In C++11 we have decltype and trailing-return-type. With this power, we can drop all the ugly metastructures, and write beautiful metafunctions.
So, we can rewrite the code above:

template<typename C, typename R, typename... A> auto make_function_aux(R(C::*)(A...)) -> std::function<R(A...)>;
template<typename C, typename R, typename... A> auto make_function_aux(R(C::*)(A...) const) -> std::function<R(A...)>;
template<typename R, typename... A> auto make_function_aux(R(A...)) -> std::function<R(A...)>;
template<typename R, typename... A> auto make_function_aux(R(*)(A...)) -> std::function<R(A...)>;
template<typename T> auto make_function_aux(const T&) -> decltype(make_function_aux(&T::operator()));

template<typename F> auto make_function(F&& f) -> decltype(make_function_aux(f)) { return decltype(make_function_aux(f))(std::forward<F>(f)); }

Are there any situations where template partial specialisation is better than function overloading with decltype for matching template arguments, or is this just a case of programmer inertia?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:16:16+00:00Added an answer on June 10, 2026 at 3:16 am

    I can think of a few issues with using function overloading:

    Different matching rules; a list of template specialisations will only match exactly, while function overloads will match if the arguments are convertible to the parameter types. This can usually be worked around, but it could lead to more complicated metacode in some cases.

    Restriction on return types; functions can’t return some types e.g. functions (not function pointers), abstract classes, noncopyable types (I think), arrays-of-unknown-bound (possibly). This can be worked around by encapsulating the type in a template struct.

    In general you’re likely to see a tradeoff between on one side the use of typename and using, and on the other side the use of decltype and wrapper templates.

    I’d agree though that your above code is an improvement on the original, for the elimination of the bool trick alone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a recent question I was encouraged to try using some basic data structures
Code-wise this seems so simple, but I still get stuck on a #VALUE. I
We still use CVS, I use git and hg for my personal use though
I've used ( and still use ) mercurial and git. I have some repos
I use version control extensively. When I'm working by myself, I still use it,
Is there a way to prevent a user viewing an file but still use
Is there a way to group a bunch of DLL's and still use them
Is there any way to write a MIDlet, but still use BlackBerry API classes
I was wondering would I still need to use a basic game loop for
I am still unclear about which adapter to use in a situation that doesn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.