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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:57:02+00:00 2026-05-21T15:57:02+00:00

template<typename U> struct CheckSignature { enum {SizeTrue = 1, SizeFalse = 2}; typedef char

  • 0
template<typename U> struct CheckSignature {
    enum {SizeTrue = 1, SizeFalse = 2};
    typedef char ReturnTrue[SizeTrue];
    typedef char ReturnFalse[SizeFalse];
    typedef typename U::iterator (U::*InsertSig)(typename U::iterator, typename const U::value_type &);
    static ReturnTrue &CheckInsert(InsertSig);
    static ReturnFalse &CheckInsert(...);
    static const bool value = (sizeof(CheckInsert(&U::insert)) == sizeof(ReturnTrue));
};

int main() {
    CheckSignature<std::string >::value; //compile error
    CheckSignature<std::vector<int> >::value; // OK
    return 0;
}

This code generates a compile error for the string class saying that none of the 2 overloads could convert all argument types. However, for vector it compiles fine. Shouldn’t overload resolution choose CheckInsert(…) whenever the parameter isn’t of type InsertSig?

  • 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-21T15:57:02+00:00Added an answer on May 21, 2026 at 3:57 pm

    Try this instead:

    #include <string>
    #include <vector>
    #include <iostream>
    
    template<typename U> struct CheckSignature {
        enum {SizeTrue = 1, SizeFalse = 2};
        typedef char ReturnTrue[SizeTrue];
        typedef char ReturnFalse[SizeFalse];
        typedef typename U::iterator (U::*InsertSig)(typename U::iterator, typename U::value_type const &);
        template <InsertSig f> struct dummy_type { };
        template <typename T>
        static ReturnTrue &CheckInsert(T*, dummy_type<&T::insert> dummy = dummy_type<&T::insert>());
        static ReturnFalse &CheckInsert(...);
        static const bool value = (sizeof(CheckInsert(((U*)0))) == sizeof(ReturnTrue));
    };
    
    int main() {
        if(CheckSignature<std::string >::value) {
          std::cout << "String class has proper insert function" << std::endl;
        }; //OK, does not print, as expected.
        if(CheckSignature<std::vector<int> >::value) {
          std::cout << "Vector class has proper insert function" << std::endl;
        }; //OK, does print, as expected.
        return 0;
    }
    

    The reason why it doesn’t work is because, in your version, taking the address of the insert function will fail at the call site, not at the substitution (which is not an error). The above will make sure that if the type U (templated to T) cannot be used to obtain a member function pointer to insert which is convertable to the given signature, it will fail to substitute for the dummy parameter, and thus, revert to the ellipsis version.

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

Sidebar

Related Questions

Consider the following code template<typename T, int N> struct A { typedef T value_type;
struct Messages { template <typename V> static const char* message() {return test mesage;} };
#include <iostream> template<typename T, int = 0> struct test { typedef char type[3]; };
template struct A{ typedef float atype; typedef typename tB::btype typeB; }; template struct B{
I have two structs: template <typename T> struct Odp { T m_t; T operator=(const
I have a struct like template<typename T> struct S { T value; void Set(const
I'm having some trouble with a template struct. template<typename T> struct A{ const int
There is a structure TA template <typename T> struct TA { typedef std::vector <T>
template<typename T> struct A { A<T> operator%( const T& x); }; template<typename T> A<T>
template<typename T> struct function { typedef T type; template<typename U> static void f() {}

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.