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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:39:25+00:00 2026-05-16T22:39:25+00:00

__if_exists is a microsoft specific keyword for testing existence of identifiers at compile time:

  • 0

__if_exists is a microsoft specific keyword for testing existence of identifiers at compile time:

msdn:__if_exists

It can come in very handy at “faked” template specialization as in some cases it provides a really much more simple, readable and better performing way than other methods like “real” specialization or overloading or whatever.

But now I have to port a big project to gnu c++ and I think I would start a little bit of crying if I would have to find other ways for the (admittedly few) occasions I used it

  • 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-16T22:39:26+00:00Added an answer on May 16, 2026 at 10:39 pm

    That’s a crappy keyword in my opinion…

    Unfortunately, it doesn’t exist in gcc as far as I know, but then I may simply not know about it.

    The proper C++ way to handle this is through the use of Concepts, ie adapt the operations carried on the type depending on some requirements.

    Usually, it’s carried out with traits rather than real concepts, because it’s easier to put in place:

    template <typename T>
    struct has_dump: boost::mpl::false_ {};
    

    And then you dump-enable your types by specializing the has_dump structure.

    The simplest is to define 3 methods, one to route, the two others to execute the different branches:

    template <typename T>
    void dump(T& t, boost::mpl::true_ const& dummy)
    {
      t.Dump();
    }
    
    template <typename T>
    void dump(T& t, boost::mpl::false_ const& dummy)
    {
      std::cout << typeid(T).name() << " does not have Dump\n";
    }
    
    template <typename T>
    void dump(T& t) { dump(t, has_dump<T>()); }
    

    Another use of the type traits would be in conjunction with the enable_if facilities:

    template <typename T>
    typename boost::enable_if< has_dump<T> >::type dump(T& t)
    {
      t.Dump();
    }
    
    // disable_if exists too...
    

    Here, instead of a runtime error message, you can get a compile-time error if the type does not have has_dump enabled, not sure if that’s you want.

    However both those methods are quite cumbersome, since the detection isn’t automated. That is why there is the Boost.Concept library.

    The idea is that the check will be performed by a Concept object, created to test the requirements, and thus you don’t have to specialize traits any longer, which make easier on the development. However I have always found the documentation of Boost.Concept to be somewhat lacking.

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

Sidebar

Related Questions

Using techniques as hinted at in: http://msdn.microsoft.com/en-us/library/system.servicemodel.servicecontractattribute.callbackcontract.aspx I am implementing a ServerPush setup for
I can drop a table if it exists using the following code but do
How can I drop sql server agent jobs, if (and only if) it exists?
I want to use Microsoft.Office.Interop.Excel dll to write the data into excel sheet. I
I have code that saves an excel file to a specific location and filename
When creating a child process in C++ using Windows API, one can allow inheritance
I'm having trouble calling the Microsoft Cabinet Maker utility (makecab) from a batch script
Is there a way I can get the names of the areas in an
The application I'm working on is almost finished but we've come to a crossroads.
Can someone give me a simple example on how to user user-settings instead of

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.