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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:08:40+00:00 2026-05-21T18:08:40+00:00

The std::vector<T> class is a model of the STL Container concept, and as such

  • 0

The std::vector<T> class is a model of the STL Container concept, and as such any proper implementation of vector has to include a nested typedef value_type as well as reference. This should be detectable using SFINAE. However, in my own tests, I can use SFINAE to detect a nested value_type typedef, but for some reason I can’t detect reference.

template <class T> 
typename T::value_type* test(T)
{
    cout << "Has nested typedef!" << endl;
}

template <class T> 
void test(...)
{
    cout << "Doesn't have nested typedef!" << endl;
}

int main()
{
    test(std::vector<int>());
}

This outputs: Has nested typedef!

However, if I replace value_type with reference, like:

template <class T> 
typename T::reference* test(T)
{
    cout << "Has nested typedef!" << endl;
}

template <class T> 
void test(...)
{
    cout << "Doesn't have nested typedef!" << endl;
}

int main()
{
    test(std::vector<int>());
}

…the program fails to compile at all, giving the error: error: no matching function for call to test(std::vector<int, std::allocator<int> >)

Why does the SFINAE technique work with T::value_type but not with T::reference?

  • 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-21T18:08:41+00:00Added an answer on May 21, 2026 at 6:08 pm

    What’s a pointer to a reference?

    A: Impossible. Pointers to references cannot exist, so neither of your functions can exist. This is in contrast to your first case, where at least one of the functions can exist (and thus you get compilation, linkage and output).

    Interestingly, SFINAE is working here, as the function definition is not causing the compilation error. It’s attempting to call a function that, because of impossibility+SFINAE, doesn’t exist, that’s causing the error. 🙂

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

Sidebar

Related Questions

I have a class that adapts std::vector to model a container of domain-specific objects.
When compiling : #include <vector> template<class T> class foo { void bar() { std::vector<T>
#include <iostream> using namespace std; // This first class contains a vector and a
#include <stdlib.h> #include <iostream> #include <vector> #include <string> class A { public: std::string s;
#include iostream #include vector class ABC { }; class VecTest { std::vector<ABC> vec; public:
#include <vector> using std::vector; class A { public: A() { buf.push_back(65); buf.push_back(66); buf.push_back(67); }
I have a static std::vector in a class. When I use Microsoft's memory leak
Given: class example { public: std::vector<std::vector<int>> a; int b; } func() { example e;
If I have a class called Test :: class Test { static std::vector<int> staticVector;
Let's say i have 2 classes: class Class1 { public: std::vector<CustomClass3*> mVec; public: Class1();

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.