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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:47:26+00:00 2026-05-24T18:47:26+00:00

Can this solution be turned into a macro so that I call something along

  • 0

Can this solution be turned into a macro so that I call something along the lines of:

CALL_CONST_FUNC(objToReturn, thisPtr)->SomeConstFunc();

For functions that return a value and another for functions that don’t. My macro token skills are not that great so I thought maybe someone here can come up with one (or tell me that it is not possible). Ultimately the goal is to avoid writing the ugly one-liner and replace it with something that is easy on the eyes and not error prone.

  • 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-05-24T18:47:27+00:00Added an answer on May 24, 2026 at 6:47 pm

    If a function doesn’t return a value (reference or pointer), do you need const overloads in the first place? It seems that the only reason to have two is to get a const or non-const reference out of the class. Otherwise the const version alone should be enough.

    As to making the idiom sweeter, how about a few template helpers instead to do type deduction for you:

    template <class T>
    const T& add_const(T& t) { return t; }
    
    template <class T>
    T& remove_const(const T& t) { return const_cast<T&>(t); }
    
    class Foo
    {
        int foo;
    public:
        const int& get() const
        {
            //non-trivial work
            return foo;
        }
    
        int& get()
        {
            return remove_const(add_const(*this).get());
        }
    };
    

    The benefit is greater if the type names are longer.

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

Sidebar

Related Questions

Can someone please help me out with a JavaScript/jQuery solution for this arithmetic problem:
I found the solution for this question in C# , but I can't translate
Before I embark on writing my own solution to this issue, can anyone point
Edited to Add * I haven't found a solution for this one yet, can
This is probably a simple question but I can't seem to find the solution.
This is blowing my mind because it's probably an easy solution, but I can't
I've been searching for a solution on the internet for this, and can not
I've searched everywhere for this, but I can't seem to find a solution. Perhaps
I'm facing this problem again and again, but can't find any solution (except mine,
Can this be done by setting a property? I'd prefer that approach then to

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.