Template class with template method specialized for itself

ignorant

Lets say I have template class with template function. Example:

template<typename T>
class example
{
    T some_member;

    template<typename X>
    example& foo(X& val)
    {
        /* general stuff */
        return *this;
    }

    // rest of class
};

What I'm failing to achieve is to make specialization for this method which takes as argument object of type example < T > (same type as caller's). Little example to show how it suppose to work:

example<int> exampleObj;
example<int> sameTypeObj;
int diffrentType1;
example<double> diffrentType2;

exampleObj.foo(diffrentType1); // general template used
exampleObj.foo(diffrentType2); // general template used
exampleObj.foo(sameTypeObj); // specialization used
ForEveR

You can overload, but you cannot specialize, since there is no partial template function specialization.

example& foo(example&)
{
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Template class with template method specialized for itself

From Dev

template class with a single method specialized in C++

From Dev

Specialized constructors for a template class

From Dev

Template specialization within template specialized class

From Dev

Use generalized template class in specialized template functions

From Dev

Use generalized template class in specialized template functions

From Dev

Using a partial template class as a specialized template function

From Dev

why Specialized template class need forward declaration?

From Dev

using declaration of a specialized variadic template class

From Dev

using declaration of a specialized variadic template class

From Dev

Defining conversion operator for specialized template class only

From Dev

Disable construction of non fully specialized template class

From Dev

Explicit specialization of a function template for a fully specialized class template

From Dev

Overload template method in template class

From Dev

Instantiate a method template of a class template

From Dev

Template specialization on a non template method in a template class

From Dev

Template specialization on a non template method in a template class

From Dev

Out-of-class definition of function of specialized inner class template?

From Dev

Passing a derived class to a template function specialized with base class

From Dev

Passing a derived class to a template function specialized with base class

From Dev

Specialized template function vs specialized template function without template keyword

From Dev

Fully specialized overloaded method is not called when used as template default parameter

From Dev

C++ specialized template class for a given type list

From Dev

C++ template class referring to itself

From Dev

Class Method with specialized Parameter

From Dev

template method overload resolution rule of class template

From Dev

Force template method in non-template class

From Dev

Conditional template specialization on method of a non template class

From Dev

Template class with method depending on template parameter

Related Related

  1. 1

    Template class with template method specialized for itself

  2. 2

    template class with a single method specialized in C++

  3. 3

    Specialized constructors for a template class

  4. 4

    Template specialization within template specialized class

  5. 5

    Use generalized template class in specialized template functions

  6. 6

    Use generalized template class in specialized template functions

  7. 7

    Using a partial template class as a specialized template function

  8. 8

    why Specialized template class need forward declaration?

  9. 9

    using declaration of a specialized variadic template class

  10. 10

    using declaration of a specialized variadic template class

  11. 11

    Defining conversion operator for specialized template class only

  12. 12

    Disable construction of non fully specialized template class

  13. 13

    Explicit specialization of a function template for a fully specialized class template

  14. 14

    Overload template method in template class

  15. 15

    Instantiate a method template of a class template

  16. 16

    Template specialization on a non template method in a template class

  17. 17

    Template specialization on a non template method in a template class

  18. 18

    Out-of-class definition of function of specialized inner class template?

  19. 19

    Passing a derived class to a template function specialized with base class

  20. 20

    Passing a derived class to a template function specialized with base class

  21. 21

    Specialized template function vs specialized template function without template keyword

  22. 22

    Fully specialized overloaded method is not called when used as template default parameter

  23. 23

    C++ specialized template class for a given type list

  24. 24

    C++ template class referring to itself

  25. 25

    Class Method with specialized Parameter

  26. 26

    template method overload resolution rule of class template

  27. 27

    Force template method in non-template class

  28. 28

    Conditional template specialization on method of a non template class

  29. 29

    Template class with method depending on template parameter

HotTag

Archive