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”?
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
add a comment |
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
"We can use this like the following:Rectangle< int, V4 > a;" No we cannot - there is no definition forRectangle<T>whereTis notfloat
– 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
add a comment |
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
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
c++11 templates c++14 template-specialization partial-specialization
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 forRectangle<T>whereTis notfloat
– 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
add a comment |
"We can use this like the following:Rectangle< int, V4 > a;" No we cannot - there is no definition forRectangle<T>whereTis notfloat
– 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
add a comment |
1 Answer
1
active
oldest
votes
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]
Thanks! Did not see the forrest for the trees. :/
– Hymir
Mar 7 at 15:36
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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]
Thanks! Did not see the forrest for the trees. :/
– Hymir
Mar 7 at 15:36
add a comment |
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]
Thanks! Did not see the forrest for the trees. :/
– Hymir
Mar 7 at 15:36
add a comment |
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]
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]
answered Mar 7 at 15:33
AngewAngew
134k11258351
134k11258351
Thanks! Did not see the forrest for the trees. :/
– Hymir
Mar 7 at 15:36
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
"We can use this like the following:
Rectangle< int, V4 > a;" No we cannot - there is no definition forRectangle<T>whereTis notfloat– 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