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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:44:13+00:00 2026-06-01T22:44:13+00:00

The SFINAE principle isn’t working for what seems really simple in Visual Studio 2010.

  • 0

The SFINAE principle isn’t working for what seems really simple in Visual Studio 2010.

#include <type_traits>
#include <iostream>

struct MyStruct
{
  int value;
  MyStruct(int value = 42) : value(value) { }
  const int& getInt() const { return value; }
};

template <typename ITER_TYPE>
auto getIteratorInt(ITER_TYPE iter) ->
  typename std::enable_if
  <std::is_pointer<decltype(*iter)>::value, const int&>::type
{
  return (*iter)->getInt();
}

template <typename ITER_TYPE>
auto getIteratorInt(ITER_TYPE iter) ->
  typename std::enable_if
  <!std::is_pointer<decltype(*iter)>::value, const int&>::type
{
  return iter->getInt();
}

int main(void)
{
  MyStruct gloryInt;
  MyStruct* gloryIntPtr = &gloryInt;
  std::cout << getIteratorInt(gloryIntPtr) << std::endl;
  std::cout << getIteratorInt(&gloryIntPtr) << std::endl;
  return 0;
}

My intention is to use std::enable_if to compile the correct template overload based on the SFINAE principle. (The function without the existing return type will be ignored, and the other one will be compiled.) That way, you can use a pointer or a double pointer to an object, and the direct object will still be what is accessed.

I get the following compilation error:

main.cpp(14): error C2039: 'type' : is not a member of 'std::tr1::enable_if<_Test,_Type>'
          with
          [
              _Test=false,
              _Type=const int &
          ]
main.cpp(17): error C3646: 'type' : unknown override specifier

Well, this is a really obvious error to have if SFINAE wasn’t employed.
Is there any way to get the intended functionality in Visual Studio 2010?

  • 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-01T22:44:15+00:00Added an answer on June 1, 2026 at 10:44 pm

    Heh, should have checked your profile page before updating the other answer.

    The type decltype( * iter ) refers to int const *const &, which is a reference to a pointer, not a “bare” pointer. Therefore std::is_pointer returns an unexpected result. There are two ways to solve this:

    • Use std::iterator_traits from C++03, which I prefer:

      typename std::iterator_traits< ITER_TYPE >::value_type
      
    • Use the std::decay metafunction which strips out references decltype might add to reflect the value category of the expression

      typename std::decay< decltype( * iter ) >::type
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some simple point code while trying out Visual Studio 10 (Beta 2),
I was reading the Wikipedia article on SFINAE and encountered following code sample: struct
I wonder if the SFINAE principle/enable_if's can be used to fake the partial specialization
I have a simple SFINAE scenario to distinuish standard containers like std::map : template
I was reading litb's question about SFINAE here and I was wondering exactly what
In C++0x SFINAE rules have been simplified such that any invalid expression or type
What is SFINAE in C++? Can you please explain it in words understandable to
I have an SFINAE test for checking if an class has a function. The
I'm trying to use SFINAE to detect if a class has an overloaded member
After reading the answer to this question , I learned that SFINAE can be

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.