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 8596899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:47:27+00:00 2026-06-12T00:47:27+00:00

I am refactoring some old code that used its own type handling system which

  • 0

I am refactoring some old code that used its own type handling system which provided a special macro for a type to be used as an argument:

x = function(TYPE(double), y);

After the refactoring, the above is written as

x = function<double>(y);

Is there any way (using a macro or an overloaded function) to keep the old style working as well, providing the backward compatibility? I tried something like this:

#define TYPE(x) (x)
#define function(x, y) function<x>(y)

hoping that the macro will be used only when the actual number of arguments matches its definition, but this leads to compilation errors.

  • 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-12T00:47:28+00:00Added an answer on June 12, 2026 at 12:47 am
    template< class Type >
    void function( int x ) {}
    
    #define TYPE( t ) t()
    template< class Type >
    void function( Type, int x ) { function< Type >( x ); }
    

    EDIT: more generally, e.g. if you want to support void, you can do …

    template< class Type >
    void function( int ) {}
    
    template< class Type >
    struct TypeCarrier {};
    
    #define TYPE( t ) TypeCarrier< t >()
    template< class Type >
    void function( TypeCarrier< Type >, int x ) { function< Type >( x ); }
    
    int main()
    {
        function( TYPE( double ), 1 );
        function( TYPE( void ), 2 );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently refactoring some of my old code that is pretty terrible. I
I have some old code (pre Java 1.5) that uses classes to implement type
I'm currently refactoring/tidying up some old C code used in a C++ project, and
Whilst refactoring some old code I realised that a particular header file was full
Okay, strange question time! I'm refactoring some old C++ code that declares a bunch
I was refactoring some code and found there are two places that can be
I have been tasked with refactoring some components that used xmlbeans to now make
I unfortunately was doing a little code archeology today (while refactoring out some old
I am currently refactoring some old code. I am looking for directions on the
I'm refactoring some code in C++, and I want to deprecate some old methods.

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.