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

  • Home
  • SEARCH
  • 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 6373539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:22:36+00:00 2026-05-25T01:22:36+00:00

I have an indexer function, and was attempting to specialize it for the standard

  • 0

I have an indexer function, and was attempting to specialize it for the standard container types, but get errors. I’m sure it’s either simple or impossible, but I can’t recall which. I would prefer these as a function-object, but I wasn’t able to make that work either. Is it possible to specialize a template function for a template class

namespace std { //declarations of predefined indexable types
    template <class T, class A> class vector;
    //others are here too, but all have the same issue 
}
//default indexer
template <class T>
double indexer(const T& b) { //this seems to work fine
    return b.getIndex();
}
// base types
template<> double indexer<char>(const char& b) { return double(b); }
//other primitives are here too, and work fine
// standard library
template<class T, class A> 
double indexer<std::vector<T,A>>(const std::vector<T,A>& b) 
{ return b.empty() ? 0 : indexer(*b.cbegin()); } //line with error

error message:

error C2768: 'indexer' : illegal use of explicit template arguments

I would like for this to be specialization vs overloading, because I have a function A that takes a function object/pointer template parameter, and overloaded function A that calls the first A with a defaulted indexer.

template<class T, class function>
double A(T a, function F) { return F(a);} //complicated
template<class T>
double A(T a) {return A(a, indexer<T>);} //default wrapper

It seems highly likely this is a duplicate question, but I cannot seem to find one.

  • 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-25T01:22:37+00:00Added an answer on May 25, 2026 at 1:22 am

    Since functions cannot be partially specialized, I can replace the indexer functions with function objects. This seems to work fine, and solves all my problems.

    namespace std { //declarations of predefined indexable types
        template <class T, class A> class vector;
    }
    template <class T>
    struct indexer { 
        double operator()(const T& b) const 
        { return b.getIndex(); } 
    };
    template<> struct indexer<char> { 
        double operator()(const char& b) const 
        { return double(b); } 
    };
    template<class T, class A> struct indexer<std::vector<T,A>> { 
        double operator()(const std::vector<T,A>& b) const 
        { return b.empty() ? 0 : indexer(*b.cbegin()); } 
    };
    
    template<class T, class function>
    double A(T a, function F) { return F(a);} //complicated
    template<class T>
    double A(T a) {return A(a, indexer<T>());} //default wrapper
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the simple function below which swap two characters of an array of
I have simple function consist of one sql query CREATE FUNCTION `GetProductIDFunc`( in_title char
I have a database table which is full-text indexed and i use the CONTAINS-function
I have a class with a custom indexer like so public string this[VehicleProperty property]
I have been set a challenge to create an indexer that takes all words
I have a function eventIterable() in six different classes, each with different names. These
I have the following array: var example = [ function() { /* hello */
I am porting Excel VBA to VB.NET. I have a function that takes a
I have classes that store data, and methods to go get data for individual
Say I have a function that returns an array like this... array( 0 =>

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.