Passing template type parameter as a type of template non-type parameter












1















Just curious: with C++17 and later we can use an auto placeholder for non-type template parameters:



template<typename A, auto B>
class C {
public:
A foo() { return B; }
};


But can we pass instead of auto the template type parameter A?



example.cpp



template<typename A, A B>
class C {
public:
A foo() { return B; }
};

int main()
{
C<int, 5> c;
std::cout << c.foo() << std::endl;

return 0;
}


Well in practice we can, and clang with -std=c++11 allows to do that.



$ g++ -std=c++11 example.cpp
$ ./a.out
5


But what about the Standard? I didn't find any explicit rule for this.
Thanks!










share|improve this question

























  • I think its possible, except for the string literals. See this

    – JeJo
    Nov 22 '18 at 10:20











  • I've edited to your question to include the language-lawyer tag. That ought to draw the crowd you're looking for (i.e. references to the Standard).

    – Jon Harper
    Nov 22 '18 at 10:23
















1















Just curious: with C++17 and later we can use an auto placeholder for non-type template parameters:



template<typename A, auto B>
class C {
public:
A foo() { return B; }
};


But can we pass instead of auto the template type parameter A?



example.cpp



template<typename A, A B>
class C {
public:
A foo() { return B; }
};

int main()
{
C<int, 5> c;
std::cout << c.foo() << std::endl;

return 0;
}


Well in practice we can, and clang with -std=c++11 allows to do that.



$ g++ -std=c++11 example.cpp
$ ./a.out
5


But what about the Standard? I didn't find any explicit rule for this.
Thanks!










share|improve this question

























  • I think its possible, except for the string literals. See this

    – JeJo
    Nov 22 '18 at 10:20











  • I've edited to your question to include the language-lawyer tag. That ought to draw the crowd you're looking for (i.e. references to the Standard).

    – Jon Harper
    Nov 22 '18 at 10:23














1












1








1


0






Just curious: with C++17 and later we can use an auto placeholder for non-type template parameters:



template<typename A, auto B>
class C {
public:
A foo() { return B; }
};


But can we pass instead of auto the template type parameter A?



example.cpp



template<typename A, A B>
class C {
public:
A foo() { return B; }
};

int main()
{
C<int, 5> c;
std::cout << c.foo() << std::endl;

return 0;
}


Well in practice we can, and clang with -std=c++11 allows to do that.



$ g++ -std=c++11 example.cpp
$ ./a.out
5


But what about the Standard? I didn't find any explicit rule for this.
Thanks!










share|improve this question
















Just curious: with C++17 and later we can use an auto placeholder for non-type template parameters:



template<typename A, auto B>
class C {
public:
A foo() { return B; }
};


But can we pass instead of auto the template type parameter A?



example.cpp



template<typename A, A B>
class C {
public:
A foo() { return B; }
};

int main()
{
C<int, 5> c;
std::cout << c.foo() << std::endl;

return 0;
}


Well in practice we can, and clang with -std=c++11 allows to do that.



$ g++ -std=c++11 example.cpp
$ ./a.out
5


But what about the Standard? I didn't find any explicit rule for this.
Thanks!







c++ c++11 templates language-lawyer c++17






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 10:21









Jon Harper

2,9482929




2,9482929










asked Nov 22 '18 at 9:12









Stepan DyatkovskiyStepan Dyatkovskiy

475




475













  • I think its possible, except for the string literals. See this

    – JeJo
    Nov 22 '18 at 10:20











  • I've edited to your question to include the language-lawyer tag. That ought to draw the crowd you're looking for (i.e. references to the Standard).

    – Jon Harper
    Nov 22 '18 at 10:23



















  • I think its possible, except for the string literals. See this

    – JeJo
    Nov 22 '18 at 10:20











  • I've edited to your question to include the language-lawyer tag. That ought to draw the crowd you're looking for (i.e. references to the Standard).

    – Jon Harper
    Nov 22 '18 at 10:23

















I think its possible, except for the string literals. See this

– JeJo
Nov 22 '18 at 10:20





I think its possible, except for the string literals. See this

– JeJo
Nov 22 '18 at 10:20













I've edited to your question to include the language-lawyer tag. That ought to draw the crowd you're looking for (i.e. references to the Standard).

– Jon Harper
Nov 22 '18 at 10:23





I've edited to your question to include the language-lawyer tag. That ought to draw the crowd you're looking for (i.e. references to the Standard).

– Jon Harper
Nov 22 '18 at 10:23












2 Answers
2






active

oldest

votes


















1















But can we pass instead of "auto" template type parameter defined at left?




Sure. It's the old way.



But the auto way permit to avoid to pass the type A.



In C++17 you can write



template <auto B>
class C {
public:
auto foo() { return B; }
};


so there is no needs to pass the type A.



I don't know a way to do the same in C++11/C++14.



I mean: if you want, in C++11/C++14 pass a value to a template... if the type is fixed, there is no problem



template <int I>


but the type itself can be different, in C++11/C++14 you have to pass first the type, then the value as in your example.cpp



template <typename T, T A>


The problem, in the old way, is that if you want to call that type of template, you have to be redundant and write something as



C<decltype(x), x>  some_C_variable;


and the only ways I know to avoid this redundancies is pass through a make function (something as make_tuple()) or a C-style macro.



In C++17 you can simply write



C<x>   some_C_variable


and, inside the C template class/struct, the type of x can be obtained from decltype(B).



For C++17 standard references...



First of all, the auto is defined a "placeolder"



From 10.1.7.4 (The auto specifier), point 1




The auto and decltype(auto) type-specifiers are used to designate a placeholder type that will be replaced later by deduction from an initializer.




This was true also in C++11/C++14



But C++17 standard add, for "Template parameters" (17.1), in point 4 enumeration, the new point 4.6





  1. A non-type template-parameter shall have one of the following (optionally cv-qualified) types:


[...]



(4.6) a type that contains a placeholder type (10.1.7.4)







share|improve this answer


























  • Thanks! May be you know any standard reference, or just link to cppreference where this possibility is described?

    – Stepan Dyatkovskiy
    Nov 22 '18 at 10:19






  • 1





    @StepanDyatkovskiy - I'm not a language lawyer so I've difficult to find the exact reference; for cppreference you can see the auto page (see point 8)

    – max66
    Nov 22 '18 at 10:26











  • @StepanDyatkovskiy - added a couple of C++17 standard references; hope it helps.

    – max66
    Nov 22 '18 at 10:47



















1














Template parameters can be divided in:



1. Type parameters
2. Non type parameters
3. Template template parameters


In your case, the statement A B is a non type template parameter whose type is the template type parameter A.



Keep in mind, in your example you do:



return B;


the above statement would fail on types A that are not copy constructible (This is easily expressed by a concept).



Keep in mind(and as was pointed in the comments), C++17 mandates copy elision.






share|improve this answer





















  • 1





    "In your case, the statement A B is a non type template parameter whose type is the template type parameter A." I know that. The whole question is it allowed by standard or not.

    – Stepan Dyatkovskiy
    Nov 22 '18 at 10:04













  • @StepanDyatkovskiy since it names a feature, i.e. a non template parameter why wouldn't ? I can take a look at the standard later but I would be surprised if that wasn't the case.

    – KostasRim
    Nov 22 '18 at 10:42











  • In C++17 return B does not require that A be copy or move constructible, due to mandatory copy/move elision of prvalues.

    – Oktalist
    Nov 22 '18 at 11:35











  • @Oktalist I had that written(if you see the history of edits) but I removed it to narrow it down. Sine you mentioned it should be back up there to avoid confusion. Thanks for pointing out. (even if pre C++17 were copy elision was not guaranteed, most compilers I know would elide the copy)

    – KostasRim
    Nov 22 '18 at 12:38











  • Pre C++17, a move or copy constructor was still required, even if it's elided.

    – Oktalist
    Nov 22 '18 at 14:30











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%2f53427361%2fpassing-template-type-parameter-as-a-type-of-template-non-type-parameter%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1















But can we pass instead of "auto" template type parameter defined at left?




Sure. It's the old way.



But the auto way permit to avoid to pass the type A.



In C++17 you can write



template <auto B>
class C {
public:
auto foo() { return B; }
};


so there is no needs to pass the type A.



I don't know a way to do the same in C++11/C++14.



I mean: if you want, in C++11/C++14 pass a value to a template... if the type is fixed, there is no problem



template <int I>


but the type itself can be different, in C++11/C++14 you have to pass first the type, then the value as in your example.cpp



template <typename T, T A>


The problem, in the old way, is that if you want to call that type of template, you have to be redundant and write something as



C<decltype(x), x>  some_C_variable;


and the only ways I know to avoid this redundancies is pass through a make function (something as make_tuple()) or a C-style macro.



In C++17 you can simply write



C<x>   some_C_variable


and, inside the C template class/struct, the type of x can be obtained from decltype(B).



For C++17 standard references...



First of all, the auto is defined a "placeolder"



From 10.1.7.4 (The auto specifier), point 1




The auto and decltype(auto) type-specifiers are used to designate a placeholder type that will be replaced later by deduction from an initializer.




This was true also in C++11/C++14



But C++17 standard add, for "Template parameters" (17.1), in point 4 enumeration, the new point 4.6





  1. A non-type template-parameter shall have one of the following (optionally cv-qualified) types:


[...]



(4.6) a type that contains a placeholder type (10.1.7.4)







share|improve this answer


























  • Thanks! May be you know any standard reference, or just link to cppreference where this possibility is described?

    – Stepan Dyatkovskiy
    Nov 22 '18 at 10:19






  • 1





    @StepanDyatkovskiy - I'm not a language lawyer so I've difficult to find the exact reference; for cppreference you can see the auto page (see point 8)

    – max66
    Nov 22 '18 at 10:26











  • @StepanDyatkovskiy - added a couple of C++17 standard references; hope it helps.

    – max66
    Nov 22 '18 at 10:47
















1















But can we pass instead of "auto" template type parameter defined at left?




Sure. It's the old way.



But the auto way permit to avoid to pass the type A.



In C++17 you can write



template <auto B>
class C {
public:
auto foo() { return B; }
};


so there is no needs to pass the type A.



I don't know a way to do the same in C++11/C++14.



I mean: if you want, in C++11/C++14 pass a value to a template... if the type is fixed, there is no problem



template <int I>


but the type itself can be different, in C++11/C++14 you have to pass first the type, then the value as in your example.cpp



template <typename T, T A>


The problem, in the old way, is that if you want to call that type of template, you have to be redundant and write something as



C<decltype(x), x>  some_C_variable;


and the only ways I know to avoid this redundancies is pass through a make function (something as make_tuple()) or a C-style macro.



In C++17 you can simply write



C<x>   some_C_variable


and, inside the C template class/struct, the type of x can be obtained from decltype(B).



For C++17 standard references...



First of all, the auto is defined a "placeolder"



From 10.1.7.4 (The auto specifier), point 1




The auto and decltype(auto) type-specifiers are used to designate a placeholder type that will be replaced later by deduction from an initializer.




This was true also in C++11/C++14



But C++17 standard add, for "Template parameters" (17.1), in point 4 enumeration, the new point 4.6





  1. A non-type template-parameter shall have one of the following (optionally cv-qualified) types:


[...]



(4.6) a type that contains a placeholder type (10.1.7.4)







share|improve this answer


























  • Thanks! May be you know any standard reference, or just link to cppreference where this possibility is described?

    – Stepan Dyatkovskiy
    Nov 22 '18 at 10:19






  • 1





    @StepanDyatkovskiy - I'm not a language lawyer so I've difficult to find the exact reference; for cppreference you can see the auto page (see point 8)

    – max66
    Nov 22 '18 at 10:26











  • @StepanDyatkovskiy - added a couple of C++17 standard references; hope it helps.

    – max66
    Nov 22 '18 at 10:47














1












1








1








But can we pass instead of "auto" template type parameter defined at left?




Sure. It's the old way.



But the auto way permit to avoid to pass the type A.



In C++17 you can write



template <auto B>
class C {
public:
auto foo() { return B; }
};


so there is no needs to pass the type A.



I don't know a way to do the same in C++11/C++14.



I mean: if you want, in C++11/C++14 pass a value to a template... if the type is fixed, there is no problem



template <int I>


but the type itself can be different, in C++11/C++14 you have to pass first the type, then the value as in your example.cpp



template <typename T, T A>


The problem, in the old way, is that if you want to call that type of template, you have to be redundant and write something as



C<decltype(x), x>  some_C_variable;


and the only ways I know to avoid this redundancies is pass through a make function (something as make_tuple()) or a C-style macro.



In C++17 you can simply write



C<x>   some_C_variable


and, inside the C template class/struct, the type of x can be obtained from decltype(B).



For C++17 standard references...



First of all, the auto is defined a "placeolder"



From 10.1.7.4 (The auto specifier), point 1




The auto and decltype(auto) type-specifiers are used to designate a placeholder type that will be replaced later by deduction from an initializer.




This was true also in C++11/C++14



But C++17 standard add, for "Template parameters" (17.1), in point 4 enumeration, the new point 4.6





  1. A non-type template-parameter shall have one of the following (optionally cv-qualified) types:


[...]



(4.6) a type that contains a placeholder type (10.1.7.4)







share|improve this answer
















But can we pass instead of "auto" template type parameter defined at left?




Sure. It's the old way.



But the auto way permit to avoid to pass the type A.



In C++17 you can write



template <auto B>
class C {
public:
auto foo() { return B; }
};


so there is no needs to pass the type A.



I don't know a way to do the same in C++11/C++14.



I mean: if you want, in C++11/C++14 pass a value to a template... if the type is fixed, there is no problem



template <int I>


but the type itself can be different, in C++11/C++14 you have to pass first the type, then the value as in your example.cpp



template <typename T, T A>


The problem, in the old way, is that if you want to call that type of template, you have to be redundant and write something as



C<decltype(x), x>  some_C_variable;


and the only ways I know to avoid this redundancies is pass through a make function (something as make_tuple()) or a C-style macro.



In C++17 you can simply write



C<x>   some_C_variable


and, inside the C template class/struct, the type of x can be obtained from decltype(B).



For C++17 standard references...



First of all, the auto is defined a "placeolder"



From 10.1.7.4 (The auto specifier), point 1




The auto and decltype(auto) type-specifiers are used to designate a placeholder type that will be replaced later by deduction from an initializer.




This was true also in C++11/C++14



But C++17 standard add, for "Template parameters" (17.1), in point 4 enumeration, the new point 4.6





  1. A non-type template-parameter shall have one of the following (optionally cv-qualified) types:


[...]



(4.6) a type that contains a placeholder type (10.1.7.4)








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 10:46

























answered Nov 22 '18 at 10:16









max66max66

37k74166




37k74166













  • Thanks! May be you know any standard reference, or just link to cppreference where this possibility is described?

    – Stepan Dyatkovskiy
    Nov 22 '18 at 10:19






  • 1





    @StepanDyatkovskiy - I'm not a language lawyer so I've difficult to find the exact reference; for cppreference you can see the auto page (see point 8)

    – max66
    Nov 22 '18 at 10:26











  • @StepanDyatkovskiy - added a couple of C++17 standard references; hope it helps.

    – max66
    Nov 22 '18 at 10:47



















  • Thanks! May be you know any standard reference, or just link to cppreference where this possibility is described?

    – Stepan Dyatkovskiy
    Nov 22 '18 at 10:19






  • 1





    @StepanDyatkovskiy - I'm not a language lawyer so I've difficult to find the exact reference; for cppreference you can see the auto page (see point 8)

    – max66
    Nov 22 '18 at 10:26











  • @StepanDyatkovskiy - added a couple of C++17 standard references; hope it helps.

    – max66
    Nov 22 '18 at 10:47

















Thanks! May be you know any standard reference, or just link to cppreference where this possibility is described?

– Stepan Dyatkovskiy
Nov 22 '18 at 10:19





Thanks! May be you know any standard reference, or just link to cppreference where this possibility is described?

– Stepan Dyatkovskiy
Nov 22 '18 at 10:19




1




1





@StepanDyatkovskiy - I'm not a language lawyer so I've difficult to find the exact reference; for cppreference you can see the auto page (see point 8)

– max66
Nov 22 '18 at 10:26





@StepanDyatkovskiy - I'm not a language lawyer so I've difficult to find the exact reference; for cppreference you can see the auto page (see point 8)

– max66
Nov 22 '18 at 10:26













@StepanDyatkovskiy - added a couple of C++17 standard references; hope it helps.

– max66
Nov 22 '18 at 10:47





@StepanDyatkovskiy - added a couple of C++17 standard references; hope it helps.

– max66
Nov 22 '18 at 10:47













1














Template parameters can be divided in:



1. Type parameters
2. Non type parameters
3. Template template parameters


In your case, the statement A B is a non type template parameter whose type is the template type parameter A.



Keep in mind, in your example you do:



return B;


the above statement would fail on types A that are not copy constructible (This is easily expressed by a concept).



Keep in mind(and as was pointed in the comments), C++17 mandates copy elision.






share|improve this answer





















  • 1





    "In your case, the statement A B is a non type template parameter whose type is the template type parameter A." I know that. The whole question is it allowed by standard or not.

    – Stepan Dyatkovskiy
    Nov 22 '18 at 10:04













  • @StepanDyatkovskiy since it names a feature, i.e. a non template parameter why wouldn't ? I can take a look at the standard later but I would be surprised if that wasn't the case.

    – KostasRim
    Nov 22 '18 at 10:42











  • In C++17 return B does not require that A be copy or move constructible, due to mandatory copy/move elision of prvalues.

    – Oktalist
    Nov 22 '18 at 11:35











  • @Oktalist I had that written(if you see the history of edits) but I removed it to narrow it down. Sine you mentioned it should be back up there to avoid confusion. Thanks for pointing out. (even if pre C++17 were copy elision was not guaranteed, most compilers I know would elide the copy)

    – KostasRim
    Nov 22 '18 at 12:38











  • Pre C++17, a move or copy constructor was still required, even if it's elided.

    – Oktalist
    Nov 22 '18 at 14:30
















1














Template parameters can be divided in:



1. Type parameters
2. Non type parameters
3. Template template parameters


In your case, the statement A B is a non type template parameter whose type is the template type parameter A.



Keep in mind, in your example you do:



return B;


the above statement would fail on types A that are not copy constructible (This is easily expressed by a concept).



Keep in mind(and as was pointed in the comments), C++17 mandates copy elision.






share|improve this answer





















  • 1





    "In your case, the statement A B is a non type template parameter whose type is the template type parameter A." I know that. The whole question is it allowed by standard or not.

    – Stepan Dyatkovskiy
    Nov 22 '18 at 10:04













  • @StepanDyatkovskiy since it names a feature, i.e. a non template parameter why wouldn't ? I can take a look at the standard later but I would be surprised if that wasn't the case.

    – KostasRim
    Nov 22 '18 at 10:42











  • In C++17 return B does not require that A be copy or move constructible, due to mandatory copy/move elision of prvalues.

    – Oktalist
    Nov 22 '18 at 11:35











  • @Oktalist I had that written(if you see the history of edits) but I removed it to narrow it down. Sine you mentioned it should be back up there to avoid confusion. Thanks for pointing out. (even if pre C++17 were copy elision was not guaranteed, most compilers I know would elide the copy)

    – KostasRim
    Nov 22 '18 at 12:38











  • Pre C++17, a move or copy constructor was still required, even if it's elided.

    – Oktalist
    Nov 22 '18 at 14:30














1












1








1







Template parameters can be divided in:



1. Type parameters
2. Non type parameters
3. Template template parameters


In your case, the statement A B is a non type template parameter whose type is the template type parameter A.



Keep in mind, in your example you do:



return B;


the above statement would fail on types A that are not copy constructible (This is easily expressed by a concept).



Keep in mind(and as was pointed in the comments), C++17 mandates copy elision.






share|improve this answer















Template parameters can be divided in:



1. Type parameters
2. Non type parameters
3. Template template parameters


In your case, the statement A B is a non type template parameter whose type is the template type parameter A.



Keep in mind, in your example you do:



return B;


the above statement would fail on types A that are not copy constructible (This is easily expressed by a concept).



Keep in mind(and as was pointed in the comments), C++17 mandates copy elision.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 12:39

























answered Nov 22 '18 at 9:31









KostasRimKostasRim

1,4591925




1,4591925








  • 1





    "In your case, the statement A B is a non type template parameter whose type is the template type parameter A." I know that. The whole question is it allowed by standard or not.

    – Stepan Dyatkovskiy
    Nov 22 '18 at 10:04













  • @StepanDyatkovskiy since it names a feature, i.e. a non template parameter why wouldn't ? I can take a look at the standard later but I would be surprised if that wasn't the case.

    – KostasRim
    Nov 22 '18 at 10:42











  • In C++17 return B does not require that A be copy or move constructible, due to mandatory copy/move elision of prvalues.

    – Oktalist
    Nov 22 '18 at 11:35











  • @Oktalist I had that written(if you see the history of edits) but I removed it to narrow it down. Sine you mentioned it should be back up there to avoid confusion. Thanks for pointing out. (even if pre C++17 were copy elision was not guaranteed, most compilers I know would elide the copy)

    – KostasRim
    Nov 22 '18 at 12:38











  • Pre C++17, a move or copy constructor was still required, even if it's elided.

    – Oktalist
    Nov 22 '18 at 14:30














  • 1





    "In your case, the statement A B is a non type template parameter whose type is the template type parameter A." I know that. The whole question is it allowed by standard or not.

    – Stepan Dyatkovskiy
    Nov 22 '18 at 10:04













  • @StepanDyatkovskiy since it names a feature, i.e. a non template parameter why wouldn't ? I can take a look at the standard later but I would be surprised if that wasn't the case.

    – KostasRim
    Nov 22 '18 at 10:42











  • In C++17 return B does not require that A be copy or move constructible, due to mandatory copy/move elision of prvalues.

    – Oktalist
    Nov 22 '18 at 11:35











  • @Oktalist I had that written(if you see the history of edits) but I removed it to narrow it down. Sine you mentioned it should be back up there to avoid confusion. Thanks for pointing out. (even if pre C++17 were copy elision was not guaranteed, most compilers I know would elide the copy)

    – KostasRim
    Nov 22 '18 at 12:38











  • Pre C++17, a move or copy constructor was still required, even if it's elided.

    – Oktalist
    Nov 22 '18 at 14:30








1




1





"In your case, the statement A B is a non type template parameter whose type is the template type parameter A." I know that. The whole question is it allowed by standard or not.

– Stepan Dyatkovskiy
Nov 22 '18 at 10:04







"In your case, the statement A B is a non type template parameter whose type is the template type parameter A." I know that. The whole question is it allowed by standard or not.

– Stepan Dyatkovskiy
Nov 22 '18 at 10:04















@StepanDyatkovskiy since it names a feature, i.e. a non template parameter why wouldn't ? I can take a look at the standard later but I would be surprised if that wasn't the case.

– KostasRim
Nov 22 '18 at 10:42





@StepanDyatkovskiy since it names a feature, i.e. a non template parameter why wouldn't ? I can take a look at the standard later but I would be surprised if that wasn't the case.

– KostasRim
Nov 22 '18 at 10:42













In C++17 return B does not require that A be copy or move constructible, due to mandatory copy/move elision of prvalues.

– Oktalist
Nov 22 '18 at 11:35





In C++17 return B does not require that A be copy or move constructible, due to mandatory copy/move elision of prvalues.

– Oktalist
Nov 22 '18 at 11:35













@Oktalist I had that written(if you see the history of edits) but I removed it to narrow it down. Sine you mentioned it should be back up there to avoid confusion. Thanks for pointing out. (even if pre C++17 were copy elision was not guaranteed, most compilers I know would elide the copy)

– KostasRim
Nov 22 '18 at 12:38





@Oktalist I had that written(if you see the history of edits) but I removed it to narrow it down. Sine you mentioned it should be back up there to avoid confusion. Thanks for pointing out. (even if pre C++17 were copy elision was not guaranteed, most compilers I know would elide the copy)

– KostasRim
Nov 22 '18 at 12:38













Pre C++17, a move or copy constructor was still required, even if it's elided.

– Oktalist
Nov 22 '18 at 14:30





Pre C++17, a move or copy constructor was still required, even if it's elided.

– Oktalist
Nov 22 '18 at 14:30


















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%2f53427361%2fpassing-template-type-parameter-as-a-type-of-template-non-type-parameter%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

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?