Partial specialization of nested template template class The Next CEO of Stack OverflowUse 'class' or 'typename' for template parameters?Why can templates only be implemented in the header file?Where and why do I have to put the “template” and “typename” keywords?Partial template specialization of free functions - best practicesQuery about C++ template specialization and partial template specializationC++ function template partial specialization?Partial specialization of variadic templatesC++: Manual disambiguation of partial specialization (with SFINAE)Template metaprogramming within the body of a template classHow to adjust my function templates so that they can be “partially specialized”?

Do I need to enable Dev Hub in my PROD Org?

Inappropriate reference requests from Journal reviewers

Complex fractions

Elegant way to replace substring in a regex with optional groups in Python?

Would a galaxy be visible from outside, but nearby?

Is micro rebar a better way to reinforce concrete than rebar?

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

What happened in Rome, when the western empire "fell"?

Indicator light circuit

Why does standard notation not preserve intervals (visually)

Non-deterministic sum of floats

How do I go from 300 unfinished/half written blog posts, to published posts?

Is it ever safe to open a suspicious html file (e.g. email attachment)?

What expression will give age in years in QGIS?

What happens if you roll doubles 3 times then land on "Go to jail?"

Is it professional to write unrelated content in an almost-empty email?

What is the result of assigning to std::vector<T>::begin()?

Can I equip Skullclamp on a creature I am sacrificing?

Between two walls

In excess I'm lethal

Sending manuscript to multiple publishers

If the heap is initialized for security, then why is the stack uninitialized?

How to count occurrences of text in a file?

Novel about a guy who is possessed by the divine essence and the world ends?



Partial specialization of nested template template class



The Next CEO of Stack OverflowUse 'class' or 'typename' for template parameters?Why can templates only be implemented in the header file?Where and why do I have to put the “template” and “typename” keywords?Partial template specialization of free functions - best practicesQuery about C++ template specialization and partial template specializationC++ function template partial specialization?Partial specialization of variadic templatesC++: Manual disambiguation of partial specialization (with SFINAE)Template metaprogramming within the body of a template classHow to adjust my function templates so that they can be “partially specialized”?










0















I am currently struggeling with partial template specialization of a template template (template ) class. I know we can realize the following problem with inheritance but the goal is to use only templates and template specialization.



Let's consider this piece of code:



template< typename T >
struct V4;
template< >
struct V4< float >
using point_type = std::array< float, 4 >;
;
template< typename T >
struct V12;
template< >
struct V12< int >
using point_type = std::array< int, 12 >;
;

template< typename T, template< typename = T > class IM >
struct Rectangle;
template< template< typename > class IM >
struct Rectangle< float, IM >
float get( size_t i ) /*...*/
;

template< typename T, template< typename = T > class IM >
struct Polygon;
template< template< typename > class IM >
struct Polygon< int, IM >
float get( size_t i ) /*...*/
;


The classes V2 and V12 can be considered as some kind of a wrapper classes for builtin-types or aggregates. The classes Rectangle and Polygon uses V2 or V12 and are partial specialized.
So far so good. We can use this like the following:



Rectangle< float, V4 > a;
std::cout << a.get(1) << "n";


Now what we want to achieve is a class which encapsulates some calculations on the introduces structs for instance. It should be called like this:



std::cout << CalculateSomething< Rectangle< float, V4 > >::doIt( ) << "n";


CalculateSomething should be partial specializable regarding to wether it works with an Rectangle or an Polygon. So a possible specialization should look like this:



template< typename T >
struct CalculateCenter< Rectangle< T, V2 >, T >
static T doIt( )
/*...*/

;
template< typename T >
struct CalculateCenter< Polygon< T, V12 >, T >
static T doIt( )
/*...*/

;


The question now is: How to declare the template class CalculateCenter?



Thanks in advance










share|improve this question
























  • "We can use this like the following: Rectangle< int, V4 > a;" No we cannot - there is no definition for Rectangle<T> where T is not float

    – Igor Tandetnik
    Mar 7 at 15:33











  • Changed the code. now it should work

    – Hymir
    Mar 7 at 15:38











  • You may want to change one of your tags to [c++] per the request on the c++14 tag wiki, you will likely get more visibility.

    – jaggedSpire
    Mar 18 at 18:08















0















I am currently struggeling with partial template specialization of a template template (template ) class. I know we can realize the following problem with inheritance but the goal is to use only templates and template specialization.



Let's consider this piece of code:



template< typename T >
struct V4;
template< >
struct V4< float >
using point_type = std::array< float, 4 >;
;
template< typename T >
struct V12;
template< >
struct V12< int >
using point_type = std::array< int, 12 >;
;

template< typename T, template< typename = T > class IM >
struct Rectangle;
template< template< typename > class IM >
struct Rectangle< float, IM >
float get( size_t i ) /*...*/
;

template< typename T, template< typename = T > class IM >
struct Polygon;
template< template< typename > class IM >
struct Polygon< int, IM >
float get( size_t i ) /*...*/
;


The classes V2 and V12 can be considered as some kind of a wrapper classes for builtin-types or aggregates. The classes Rectangle and Polygon uses V2 or V12 and are partial specialized.
So far so good. We can use this like the following:



Rectangle< float, V4 > a;
std::cout << a.get(1) << "n";


Now what we want to achieve is a class which encapsulates some calculations on the introduces structs for instance. It should be called like this:



std::cout << CalculateSomething< Rectangle< float, V4 > >::doIt( ) << "n";


CalculateSomething should be partial specializable regarding to wether it works with an Rectangle or an Polygon. So a possible specialization should look like this:



template< typename T >
struct CalculateCenter< Rectangle< T, V2 >, T >
static T doIt( )
/*...*/

;
template< typename T >
struct CalculateCenter< Polygon< T, V12 >, T >
static T doIt( )
/*...*/

;


The question now is: How to declare the template class CalculateCenter?



Thanks in advance










share|improve this question
























  • "We can use this like the following: Rectangle< int, V4 > a;" No we cannot - there is no definition for Rectangle<T> where T is not float

    – Igor Tandetnik
    Mar 7 at 15:33











  • Changed the code. now it should work

    – Hymir
    Mar 7 at 15:38











  • You may want to change one of your tags to [c++] per the request on the c++14 tag wiki, you will likely get more visibility.

    – jaggedSpire
    Mar 18 at 18:08













0












0








0








I am currently struggeling with partial template specialization of a template template (template ) class. I know we can realize the following problem with inheritance but the goal is to use only templates and template specialization.



Let's consider this piece of code:



template< typename T >
struct V4;
template< >
struct V4< float >
using point_type = std::array< float, 4 >;
;
template< typename T >
struct V12;
template< >
struct V12< int >
using point_type = std::array< int, 12 >;
;

template< typename T, template< typename = T > class IM >
struct Rectangle;
template< template< typename > class IM >
struct Rectangle< float, IM >
float get( size_t i ) /*...*/
;

template< typename T, template< typename = T > class IM >
struct Polygon;
template< template< typename > class IM >
struct Polygon< int, IM >
float get( size_t i ) /*...*/
;


The classes V2 and V12 can be considered as some kind of a wrapper classes for builtin-types or aggregates. The classes Rectangle and Polygon uses V2 or V12 and are partial specialized.
So far so good. We can use this like the following:



Rectangle< float, V4 > a;
std::cout << a.get(1) << "n";


Now what we want to achieve is a class which encapsulates some calculations on the introduces structs for instance. It should be called like this:



std::cout << CalculateSomething< Rectangle< float, V4 > >::doIt( ) << "n";


CalculateSomething should be partial specializable regarding to wether it works with an Rectangle or an Polygon. So a possible specialization should look like this:



template< typename T >
struct CalculateCenter< Rectangle< T, V2 >, T >
static T doIt( )
/*...*/

;
template< typename T >
struct CalculateCenter< Polygon< T, V12 >, T >
static T doIt( )
/*...*/

;


The question now is: How to declare the template class CalculateCenter?



Thanks in advance










share|improve this question
















I am currently struggeling with partial template specialization of a template template (template ) class. I know we can realize the following problem with inheritance but the goal is to use only templates and template specialization.



Let's consider this piece of code:



template< typename T >
struct V4;
template< >
struct V4< float >
using point_type = std::array< float, 4 >;
;
template< typename T >
struct V12;
template< >
struct V12< int >
using point_type = std::array< int, 12 >;
;

template< typename T, template< typename = T > class IM >
struct Rectangle;
template< template< typename > class IM >
struct Rectangle< float, IM >
float get( size_t i ) /*...*/
;

template< typename T, template< typename = T > class IM >
struct Polygon;
template< template< typename > class IM >
struct Polygon< int, IM >
float get( size_t i ) /*...*/
;


The classes V2 and V12 can be considered as some kind of a wrapper classes for builtin-types or aggregates. The classes Rectangle and Polygon uses V2 or V12 and are partial specialized.
So far so good. We can use this like the following:



Rectangle< float, V4 > a;
std::cout << a.get(1) << "n";


Now what we want to achieve is a class which encapsulates some calculations on the introduces structs for instance. It should be called like this:



std::cout << CalculateSomething< Rectangle< float, V4 > >::doIt( ) << "n";


CalculateSomething should be partial specializable regarding to wether it works with an Rectangle or an Polygon. So a possible specialization should look like this:



template< typename T >
struct CalculateCenter< Rectangle< T, V2 >, T >
static T doIt( )
/*...*/

;
template< typename T >
struct CalculateCenter< Polygon< T, V12 >, T >
static T doIt( )
/*...*/

;


The question now is: How to declare the template class CalculateCenter?



Thanks in advance







c++11 templates c++14 template-specialization partial-specialization






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 15:37







Hymir

















asked Mar 7 at 15:22









HymirHymir

2481310




2481310












  • "We can use this like the following: Rectangle< int, V4 > a;" No we cannot - there is no definition for Rectangle<T> where T is not float

    – Igor Tandetnik
    Mar 7 at 15:33











  • Changed the code. now it should work

    – Hymir
    Mar 7 at 15:38











  • You may want to change one of your tags to [c++] per the request on the c++14 tag wiki, you will likely get more visibility.

    – jaggedSpire
    Mar 18 at 18:08

















  • "We can use this like the following: Rectangle< int, V4 > a;" No we cannot - there is no definition for Rectangle<T> where T is not float

    – Igor Tandetnik
    Mar 7 at 15:33











  • Changed the code. now it should work

    – Hymir
    Mar 7 at 15:38











  • You may want to change one of your tags to [c++] per the request on the c++14 tag wiki, you will likely get more visibility.

    – jaggedSpire
    Mar 18 at 18:08
















"We can use this like the following: Rectangle< int, V4 > a;" No we cannot - there is no definition for Rectangle<T> where T is not float

– Igor Tandetnik
Mar 7 at 15:33





"We can use this like the following: Rectangle< int, V4 > a;" No we cannot - there is no definition for Rectangle<T> where T is not float

– Igor Tandetnik
Mar 7 at 15:33













Changed the code. now it should work

– Hymir
Mar 7 at 15:38





Changed the code. now it should work

– Hymir
Mar 7 at 15:38













You may want to change one of your tags to [c++] per the request on the c++14 tag wiki, you will likely get more visibility.

– jaggedSpire
Mar 18 at 18:08





You may want to change one of your tags to [c++] per the request on the c++14 tag wiki, you will likely get more visibility.

– jaggedSpire
Mar 18 at 18:08












1 Answer
1






active

oldest

votes


















0














The answer seems rather straightforward:



template < class T >
struct CalculateCenter;

template< typename T >
struct CalculateCenter< Rectangle< T, V2 > >
static T doIt( )
/*...*/

;

template< typename T >
struct CalculateCenter< Polygon< T, V12 > >
static T doIt( )
/*...*/

;


[Live example]






share|improve this answer























  • Thanks! Did not see the forrest for the trees. :/

    – Hymir
    Mar 7 at 15:36











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047261%2fpartial-specialization-of-nested-template-template-class%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














The answer seems rather straightforward:



template < class T >
struct CalculateCenter;

template< typename T >
struct CalculateCenter< Rectangle< T, V2 > >
static T doIt( )
/*...*/

;

template< typename T >
struct CalculateCenter< Polygon< T, V12 > >
static T doIt( )
/*...*/

;


[Live example]






share|improve this answer























  • Thanks! Did not see the forrest for the trees. :/

    – Hymir
    Mar 7 at 15:36















0














The answer seems rather straightforward:



template < class T >
struct CalculateCenter;

template< typename T >
struct CalculateCenter< Rectangle< T, V2 > >
static T doIt( )
/*...*/

;

template< typename T >
struct CalculateCenter< Polygon< T, V12 > >
static T doIt( )
/*...*/

;


[Live example]






share|improve this answer























  • Thanks! Did not see the forrest for the trees. :/

    – Hymir
    Mar 7 at 15:36













0












0








0







The answer seems rather straightforward:



template < class T >
struct CalculateCenter;

template< typename T >
struct CalculateCenter< Rectangle< T, V2 > >
static T doIt( )
/*...*/

;

template< typename T >
struct CalculateCenter< Polygon< T, V12 > >
static T doIt( )
/*...*/

;


[Live example]






share|improve this answer













The answer seems rather straightforward:



template < class T >
struct CalculateCenter;

template< typename T >
struct CalculateCenter< Rectangle< T, V2 > >
static T doIt( )
/*...*/

;

template< typename T >
struct CalculateCenter< Polygon< T, V12 > >
static T doIt( )
/*...*/

;


[Live example]







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 at 15:33









AngewAngew

134k11258351




134k11258351












  • Thanks! Did not see the forrest for the trees. :/

    – Hymir
    Mar 7 at 15:36

















  • Thanks! Did not see the forrest for the trees. :/

    – Hymir
    Mar 7 at 15:36
















Thanks! Did not see the forrest for the trees. :/

– Hymir
Mar 7 at 15:36





Thanks! Did not see the forrest for the trees. :/

– Hymir
Mar 7 at 15:36



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047261%2fpartial-specialization-of-nested-template-template-class%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

Алба-Юлія

Захаров Федір Захарович