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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:18:15+00:00 2026-06-12T18:18:15+00:00

I have to implement a non-member function isHomogenous(Triple triple) for a template class defined

  • 0

I have to implement a non-member function isHomogenous(Triple triple) for a template class defined as:

template <typename T1, typename T2, typename T3>
    class Triple
{
public:
    Triple()
    { }
    Triple(const T1 &a, const T2 &b, const T3 &c) : a(a), b(b), c(c)
    { }
...

The isHomogenous function should return a bool value indicating whether all of the three values in the parameter triple are of the same type. I have tried:

template <typename T> bool isHomogenous(Triple<T, T, T> triple) {
    return true;
}

template <typename T1, typename T2, typename T3> bool isHomogenous(Triple<T1, T2, T3> triple) {
    return false;
}

This doesn’t work, can you hint me on a solution?

  • 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-12T18:18:16+00:00Added an answer on June 12, 2026 at 6:18 pm

    A function template cannot be partially specialized.

    One alternative is to define it as a static member function (or in your case just a value!) of a class template, and then just provide an ordinary function template wrapper, like …

    #include <type_traits>
    
    template< class T1, class T2, class T3 >
    struct Blah {};
    
    namespace detail {
        template< class T1, class T2, class T3 >
        struct IsHomogenous { static bool const yes = false; };
    
        template< class T >
        struct IsHomogenous< T, T, T > { static bool const yes = true; };
    }  // namespace detail
    
    template< class T1, class T2, class T3 >
    bool isHomogenous( Blah< T1, T2, T3 > )
    {
        return detail::IsHomogenous< T1, T2, T3 >::yes;
    }
    
    #include <iostream>
    int main()
    {
        using namespace std;
        wcout << boolalpha
            << isHomogenous( Blah< double, char, void >() ) << " "
            << isHomogenous( Blah< int, int, int >() )
            << endl;
    }
    

    and another way is to use C++11 std::is_same:

    #include <type_traits>
    
    template< class T1, class T2, class T3 >
    struct Blah {};
    
    template< class T1, class T2, class T3 >
    bool isHomogenous( Blah< T1, T2, T3 > )
    {
        using std::is_same;
        return is_same< T1, T2 >::value && is_same< T2, T3 >::value;
    }
    
    #include <iostream>
    int main()
    {
        using namespace std;
        wcout << boolalpha
            << isHomogenous( Blah< double, char, void >() ) << " "
            << isHomogenous( Blah< int, int, int >() )
            << endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class template Foo<T> . I'd like to implement a non-member function
Suppose you have the following non-static member function: // .h struct C { void
I have a final non-static member: private final HashMap<String,String> myMap; I would like to
Suppose I have this class: template</*some other parameters here */class toggle> class Foo {
I have a class which looks like this: public class NumericalRange:IEquatable<NumericalRange> { public double
I have the following class template: template<class T, unsigned N> class MyClass; where T
I have following class: public class PairOfDice { private Dice d1,d2; public int Value
My problem is this (In PHP): I have three classes, Class cls1 { public
Possible Duplicate: Where and why do I have to put the “template” and “typename”
Possible Duplicate: Non Public Members for C# Interfaces Suppose I have internal interface IInterface

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.