What pattern specialty is used in this code example?

I read the documents on Explicit specialization of class templates and Partial specialization of class templates , but I don’t understand what specialization is used in this example (msdn links are used only because of my current environment, the question is more or less theoretical). I need a name that is used in the C ++ standard and / or documentation links or links to standard C ++ paragraphs. The problem I'm trying to solve is quite difficult to ask directly, but I have an idea how to use a similar aproach for the one used in this example.

template<class T>
struct is_vector {
    static bool const value = false;
};

template<class T>
struct is_vector<std::vector<T>> {
    static bool const value = true;
}; 
+4
source share
2 answers

Defines a template (primary) class is_vector<T>, and then partially specializes in T = std::vector<U>.

The general rule is pretty simple:

The main template:

template <something here> class someName /*no angle barckets here */ { ... }

Partial specialization:

template <something here> class someName<otherThing here> { ... }

Explicit specialization:

template <> class someName<something here> { ... }

There is no short part of the standard for citation, but you can refer to the subsection C++11[temp.class.spec]. There is nothing in this chapter that limits partial specialization to pointers and references. Please note that the MSDN link you provided does not limit their scope; he says “for example” before the examples, which does not mean that there are no other possibilities.

+2
source

This is a partial specialization. Your MSDN link describes two types of partial specialization, and this is the second:

  • , . , .
  • , , , . - , .

? . T. std::vector <int> - .

- MSDN " ... , , ". " " , . , <T> - " ".

+1

Source: https://habr.com/ru/post/1531548/


All Articles