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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:40:54+00:00 2026-06-04T21:40:54+00:00

I have a simple SFINAE scenario to distinuish standard containers like std::map : template

  • 0

I have a simple SFINAE scenario to distinuish standard containers like std::map:

 template <typename Container> struct HasKeyType : sfinae_test { // (C)
   template <typename U> static Yes test(typename Container::key_type*); // (A)
   template <typename U> static No test(...);
   enum {value = (sizeof(test(null)) == sizeof(Yes))}; // (B)
 };

With

 struct sfinae_test {
   typedef char Yes;
   typedef long No;
   static void* const null;
 };

When I instantiate this with HasKeyType<std::vector<int> >::value, I get

(A) error: no type named ‘key_type’ in ‘class std::vector<int>’
(B) error: invalid use of incomplete type ‘struct HasKeyType<std::vector<int> >’
(C) error: declaration of ‘struct HasKeyType<std::vector<int> >’

I’m completely stumped at this. Why is HasKeyType incomplete, and why doesn’t SFINAE work?

I get similar errors to (B) and (C) as well if I instantiate HasKeyType<std::map<int,float> > which in fact has a key type (int).

g++ version: 4.5.2 (yes, I know it’s old)

  • 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-04T21:40:54+00:00Added an answer on June 4, 2026 at 9:40 pm

    You are not using the template U in your test method:

    template <typename Container> struct HasKeyType : sfinae_test { // C
      template <typename U> static Yes test(typename U::key_type* ); // A
      template <typename U> static No test(U*);
      enum {value = (sizeof(test<Container>(0)) == sizeof(Yes))}; // B
    };
    

    Note that I changed the test(null) for a test<Container>(0). If your compiler supports it(well, gcc 4.5 doesn’t…), you could use nullptr instead of 0.

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

Sidebar

Related Questions

I have simple WebView code like this: WebView wv = (WebView) findViewById(R.id.webview1); wv.loadUrl(http://en.wikipedia.org/wiki/Book); But
I have simple Hello World C++ program (main.cpp): #include <iostream> using namespace std; int
I have simple form set up like the following: <form> <input type=text name=first_number id=first_number
I have simple view in my Ember.js application, like this. Each content element consists
I have simple ascii text file like this: Madonna is a celebrity No she's
I have simple custom control that shows a message to user (something like browser's
I have simple function that act like a client . It sents an event
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I have simple class with width and height member fields which define number of
I have simple php validation form that is halfway working. If you leave the

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.