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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:15:00+00:00 2026-06-05T13:15:00+00:00

I have a class template Z that I would like specialize when passed a

  • 0

I have a class template Z that I would like specialize when passed a type that is an any instantiation of a particular template N:

struct L {
    template <typename S> void foo(S &) {/*...*/}
};

template <class T>
struct M {
    template <typename S> void foo(S &) {/*...*/}
};

template <class T>
struct N {
    template <typename S> void foo(S &) {/*...*/}
};

// I'd like to specialize this for TY==N<anything>
template <typename TX, typename TY>
struct Z {
    void bar(TX &tx) { /*...*/ ty->foo(tx); /*...*/ }
    TY *ty;
};

Since Z<int, L> and Z<int, N<int>> and Z<int, M<int>> are all valid use cases, I can’t do anything along the lines of turning Z into a template template, and there is a compelling complexity reduction possible in Z<TX, TY>::bar(TX &) when TY is a class built from N. Is there a way to achieve this?

  • 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-05T13:15:02+00:00Added an answer on June 5, 2026 at 1:15 pm

    This should effect the specialization you desire:

    template <typename TX, typename ANY>
    struct Z< TX, N<ANY> > {
        // ...
    };
    

    Z gets specialized when the first parameter is TX, and the second parameter is N<ANY>. A quick illustration:

    template <typename A> struct N { A a; };
    
    template <typename TX, typename TY>
    struct Z { Z () { std::cout << "not special" << std::endl; } };
    
    template <typename TX, typename ANY>
    struct Z< TX, N<ANY> > { Z () { std::cout << "special" << std::endl; } };
    
    int main ()
    {
        Z<int, int> z1;
        Z<int, N<int> > z2;
    }
    

    Results in the output:

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

Sidebar

Related Questions

So I have a template class that I would like to accept an std::map
I have a class with several template member functions that I would like to
I want to have a template class that looks something like what I have
I have a templated container class that looks something like this: template <class ItemType>
I have code that looks like this: template<class T> class list { public: class
I have a xml that looks like below <xsl:template match=//xml> <xsl:for-each select=//z:row> <ul class
I have a class like template <class T> struct A{ template <class U> A(U
I have a class that looks roughly like this: template<std::size_t dim> class Foo {
I have a class that contains some data, and I would like to add
I would like to design a class template which takes an allocator type (as

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.