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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:28:23+00:00 2026-05-26T06:28:23+00:00

I tried to implement an SFINAE using bool (unlike popular void_ trick ): template<typename

  • 0

I tried to implement an SFINAE using bool (unlike popular void_ trick):

  template<typename T, bool = true>
  struct Resolve
  {
    static const bool value = false;
  };

  template<typename T>
  struct Resolve<T, T::my_value>
  {
    static const bool value = true;
  };

The goal is to specialize, the classes which have static const bool my_value = true; defined inside it. If they are defined false or not defined then don’t specialize it. i.e.

struct B1 {  // specialize Resolve for this case
  static const bool my_value = true;
};
struct B2 {  // don't specialize
  static const bool my_value = false;
};
struct B3 {};  // don't specialize

When applying the above trick on B1 it gives the compilation error:

Resolve<B1>::value;

error: template argument ‘T::my_value’ involves template parameter(s)

I am aware that this can be achieved with alternate ways. However, I am interested in knowing, why it gives compiler error here and can it be solved in this code itself ?

  • 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-26T06:28:24+00:00Added an answer on May 26, 2026 at 6:28 am

    Actually what you’re doing is forbidden by section §14.5.4/9 which says,

    A partially specialized non-type argument expression shall not involve a template parameter of the partial specialization except when the argument expression is a simple identifier.

    The trick could be using a type for second template parameter as well, encapsulating the non-type value, as described below:

    template<bool b> struct booltype {};
    
    template<typename T, typename B = booltype<true> >
    struct Resolve
    {
      static const bool value = false;
    };
    
    template<typename T>
    struct Resolve<T, booltype<T::my_value> >
    {
      static const bool value = true;
    };
    

    Now it compile fines.

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

Sidebar

Related Questions

I tried to implement the following in less: nav > ul > li:first-child using:
I tried to implement a date selection using three ComboBox as shown below. contents
I have tried to implement progress reporting using a soap extension as described at
Anyone who has tried to implement RoutedCommands in WPF using M-V-VM has undoubtedly run
In response to Python regular expression I tried to implement an HTML parser using
I tried to implement CountDownLatch using boost mutexes and condition variable. Below is the
I'm tried to implement SSO for SalesForce using OpenSAML. My code generates valid SAML
I tried to implement a simple webservice using ServiceStack and Sitefinity V3.7sp3 net35. I
I tried to implement this: UICRouteOverlayMapView .h file @protocol DrawingDataDelegate <NSObject> @required -(void) drawingSuccessful:(BOOL)done;
I tried to implement bessel function using that formula, this is the code: function

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.