error while generalizing my variadic template functionWhy is double not allowed as a non-type template parameter?Can templates only be implemented in header files?Calling variadic argument function from template classSpecialization of variadic template functionerror defining std::function pointer to an instance of a function template, which is a member of a templated class?run-time calculations with non-type variadic templatesVariadic template function overloadingCall member method of a variadic class template with a member fieldstd::bind with variadic template functionC++ errors with Variadic templateC++ Variadic Template to Evaluate Pointer to Member

Why the color Red in Us, what is the significance?

!I!n!s!e!r!t! !n!b!e!t!w!e!e!n!

Chess software to analyze games

Why should someone be willing to write a strong recommendation even if that means losing a undergraduate from their lab?

Are unaudited server logs admissible in a court of law?

Combining extension tube with adapter

Starships without computers?

What happened after the end of the Truman Show?

How to think about joining a company whose business I do not understand?

insert several equation in one frame in beamer

Multicolumn in table not centered

Has there ever been a truly bilingual country prior to the contemporary period?

Use of vor in this sentence

Can others monetize my project with GPLv3?

Default camera device to show screen instead of physical camera

Unbiased estimator of exponential of measure of a set?

What is "super" in superphosphate?

Are there categories whose internal hom is somewhat 'exotic'?

How can I train a replacement without letting my bosses and the replacement know?

Designing a prison for a telekinetic race

Are there any OR challenges that are similar to kaggle's competitions?

Are there reliable, formulaic ways to form chords on the guitar?

Is this kind of description not recommended?

Would it be illegal for Facebook to actively promote a political agenda?



error while generalizing my variadic template function


Why is double not allowed as a non-type template parameter?Can templates only be implemented in header files?Calling variadic argument function from template classSpecialization of variadic template functionerror defining std::function pointer to an instance of a function template, which is a member of a templated class?run-time calculations with non-type variadic templatesVariadic template function overloadingCall member method of a variadic class template with a member fieldstd::bind with variadic template functionC++ errors with Variadic templateC++ Variadic Template to Evaluate Pointer to Member






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I implemented the template function below using variadic, but I am having difficulties in making it more generic. I am using MS VS C++ 2017.



This function essentially checks if an integer value is one of the values provided int templates argument. In theory should be equivalent to a list of logical OR.



template<int TFirst, int...TArgs>
constexpr bool foo(int&& a)


int iii = 3;
assert(foo<1, 2, 3>(std::forward<int>(iii)); // ok!


I would like to make this function even more generic using other numeric types like double or class enums or even objects.



I tried the code below. It builds with integers, but NOT with doubles.



 template<typename T>
struct check

template<T TFirst, T...TArgs>
static constexpr bool foo(T&& a)

if constexpr (sizeof...(TArgs) > 0)
return a == TFirst
;

// test
int iii = 3;
double ddd = 4.0;

check<int>::foo<1, 2, 3>(std::forward<int>(iii)); // ok
check<double>::foo<1.0, 2.0, 3.0>(std::forward < double >(ddd )); // non ok


Error I have with double is



 error C2993: 'T': illegal type for non-type template parameter 'TFirst'
error C2672: 'check<double>::foo': no matching overloaded function found


Is there any fix this or better way to make my function more generic?










share|improve this question
























  • You can't use double values as template parameters, see the linked question for background information. There's no way around it, you will have to come up with some alternative approach that does not involve double template parameters.

    – Sam Varshavchik
    Mar 27 at 12:31











  • @SamVarshavchik Can we not close this as a dupe but instead acknowledge they can't do what they have because of the dupe so how can they work around it.

    – NathanOliver
    Mar 27 at 12:36











  • I see..so is like using literals string for template..interesting. I didn't think about it at all.Thanks for pointing me to the right response; I googled for similar questions but I was not able to find anything like that.

    – Abruzzo Forte e Gentile
    Mar 27 at 12:57












  • @AbruzzoForteeGentile FWIW, you could write the code like this

    – NathanOliver
    Mar 27 at 13:01











  • @Nathan. Wow! That's pretty hard-core! I never seen using the '...' like that? In fact I don't understand much how your function works (sorry). I am used to recursively call of a variadic template with less argument...I have no idea how your function is expanding. Can you point me to some useful tip for further reading or investigation? I found this usage truly amazing.

    – Abruzzo Forte e Gentile
    Mar 27 at 13:44

















3















I implemented the template function below using variadic, but I am having difficulties in making it more generic. I am using MS VS C++ 2017.



This function essentially checks if an integer value is one of the values provided int templates argument. In theory should be equivalent to a list of logical OR.



template<int TFirst, int...TArgs>
constexpr bool foo(int&& a)


int iii = 3;
assert(foo<1, 2, 3>(std::forward<int>(iii)); // ok!


I would like to make this function even more generic using other numeric types like double or class enums or even objects.



I tried the code below. It builds with integers, but NOT with doubles.



 template<typename T>
struct check

template<T TFirst, T...TArgs>
static constexpr bool foo(T&& a)

if constexpr (sizeof...(TArgs) > 0)
return a == TFirst
;

// test
int iii = 3;
double ddd = 4.0;

check<int>::foo<1, 2, 3>(std::forward<int>(iii)); // ok
check<double>::foo<1.0, 2.0, 3.0>(std::forward < double >(ddd )); // non ok


Error I have with double is



 error C2993: 'T': illegal type for non-type template parameter 'TFirst'
error C2672: 'check<double>::foo': no matching overloaded function found


Is there any fix this or better way to make my function more generic?










share|improve this question
























  • You can't use double values as template parameters, see the linked question for background information. There's no way around it, you will have to come up with some alternative approach that does not involve double template parameters.

    – Sam Varshavchik
    Mar 27 at 12:31











  • @SamVarshavchik Can we not close this as a dupe but instead acknowledge they can't do what they have because of the dupe so how can they work around it.

    – NathanOliver
    Mar 27 at 12:36











  • I see..so is like using literals string for template..interesting. I didn't think about it at all.Thanks for pointing me to the right response; I googled for similar questions but I was not able to find anything like that.

    – Abruzzo Forte e Gentile
    Mar 27 at 12:57












  • @AbruzzoForteeGentile FWIW, you could write the code like this

    – NathanOliver
    Mar 27 at 13:01











  • @Nathan. Wow! That's pretty hard-core! I never seen using the '...' like that? In fact I don't understand much how your function works (sorry). I am used to recursively call of a variadic template with less argument...I have no idea how your function is expanding. Can you point me to some useful tip for further reading or investigation? I found this usage truly amazing.

    – Abruzzo Forte e Gentile
    Mar 27 at 13:44













3












3








3








I implemented the template function below using variadic, but I am having difficulties in making it more generic. I am using MS VS C++ 2017.



This function essentially checks if an integer value is one of the values provided int templates argument. In theory should be equivalent to a list of logical OR.



template<int TFirst, int...TArgs>
constexpr bool foo(int&& a)


int iii = 3;
assert(foo<1, 2, 3>(std::forward<int>(iii)); // ok!


I would like to make this function even more generic using other numeric types like double or class enums or even objects.



I tried the code below. It builds with integers, but NOT with doubles.



 template<typename T>
struct check

template<T TFirst, T...TArgs>
static constexpr bool foo(T&& a)

if constexpr (sizeof...(TArgs) > 0)
return a == TFirst
;

// test
int iii = 3;
double ddd = 4.0;

check<int>::foo<1, 2, 3>(std::forward<int>(iii)); // ok
check<double>::foo<1.0, 2.0, 3.0>(std::forward < double >(ddd )); // non ok


Error I have with double is



 error C2993: 'T': illegal type for non-type template parameter 'TFirst'
error C2672: 'check<double>::foo': no matching overloaded function found


Is there any fix this or better way to make my function more generic?










share|improve this question














I implemented the template function below using variadic, but I am having difficulties in making it more generic. I am using MS VS C++ 2017.



This function essentially checks if an integer value is one of the values provided int templates argument. In theory should be equivalent to a list of logical OR.



template<int TFirst, int...TArgs>
constexpr bool foo(int&& a)


int iii = 3;
assert(foo<1, 2, 3>(std::forward<int>(iii)); // ok!


I would like to make this function even more generic using other numeric types like double or class enums or even objects.



I tried the code below. It builds with integers, but NOT with doubles.



 template<typename T>
struct check

template<T TFirst, T...TArgs>
static constexpr bool foo(T&& a)

if constexpr (sizeof...(TArgs) > 0)
return a == TFirst
;

// test
int iii = 3;
double ddd = 4.0;

check<int>::foo<1, 2, 3>(std::forward<int>(iii)); // ok
check<double>::foo<1.0, 2.0, 3.0>(std::forward < double >(ddd )); // non ok


Error I have with double is



 error C2993: 'T': illegal type for non-type template parameter 'TFirst'
error C2672: 'check<double>::foo': no matching overloaded function found


Is there any fix this or better way to make my function more generic?







c++ variadic-templates variadic-functions






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 12:17









Abruzzo Forte e GentileAbruzzo Forte e Gentile

6,07121 gold badges74 silver badges146 bronze badges




6,07121 gold badges74 silver badges146 bronze badges















  • You can't use double values as template parameters, see the linked question for background information. There's no way around it, you will have to come up with some alternative approach that does not involve double template parameters.

    – Sam Varshavchik
    Mar 27 at 12:31











  • @SamVarshavchik Can we not close this as a dupe but instead acknowledge they can't do what they have because of the dupe so how can they work around it.

    – NathanOliver
    Mar 27 at 12:36











  • I see..so is like using literals string for template..interesting. I didn't think about it at all.Thanks for pointing me to the right response; I googled for similar questions but I was not able to find anything like that.

    – Abruzzo Forte e Gentile
    Mar 27 at 12:57












  • @AbruzzoForteeGentile FWIW, you could write the code like this

    – NathanOliver
    Mar 27 at 13:01











  • @Nathan. Wow! That's pretty hard-core! I never seen using the '...' like that? In fact I don't understand much how your function works (sorry). I am used to recursively call of a variadic template with less argument...I have no idea how your function is expanding. Can you point me to some useful tip for further reading or investigation? I found this usage truly amazing.

    – Abruzzo Forte e Gentile
    Mar 27 at 13:44

















  • You can't use double values as template parameters, see the linked question for background information. There's no way around it, you will have to come up with some alternative approach that does not involve double template parameters.

    – Sam Varshavchik
    Mar 27 at 12:31











  • @SamVarshavchik Can we not close this as a dupe but instead acknowledge they can't do what they have because of the dupe so how can they work around it.

    – NathanOliver
    Mar 27 at 12:36











  • I see..so is like using literals string for template..interesting. I didn't think about it at all.Thanks for pointing me to the right response; I googled for similar questions but I was not able to find anything like that.

    – Abruzzo Forte e Gentile
    Mar 27 at 12:57












  • @AbruzzoForteeGentile FWIW, you could write the code like this

    – NathanOliver
    Mar 27 at 13:01











  • @Nathan. Wow! That's pretty hard-core! I never seen using the '...' like that? In fact I don't understand much how your function works (sorry). I am used to recursively call of a variadic template with less argument...I have no idea how your function is expanding. Can you point me to some useful tip for further reading or investigation? I found this usage truly amazing.

    – Abruzzo Forte e Gentile
    Mar 27 at 13:44
















You can't use double values as template parameters, see the linked question for background information. There's no way around it, you will have to come up with some alternative approach that does not involve double template parameters.

– Sam Varshavchik
Mar 27 at 12:31





You can't use double values as template parameters, see the linked question for background information. There's no way around it, you will have to come up with some alternative approach that does not involve double template parameters.

– Sam Varshavchik
Mar 27 at 12:31













@SamVarshavchik Can we not close this as a dupe but instead acknowledge they can't do what they have because of the dupe so how can they work around it.

– NathanOliver
Mar 27 at 12:36





@SamVarshavchik Can we not close this as a dupe but instead acknowledge they can't do what they have because of the dupe so how can they work around it.

– NathanOliver
Mar 27 at 12:36













I see..so is like using literals string for template..interesting. I didn't think about it at all.Thanks for pointing me to the right response; I googled for similar questions but I was not able to find anything like that.

– Abruzzo Forte e Gentile
Mar 27 at 12:57






I see..so is like using literals string for template..interesting. I didn't think about it at all.Thanks for pointing me to the right response; I googled for similar questions but I was not able to find anything like that.

– Abruzzo Forte e Gentile
Mar 27 at 12:57














@AbruzzoForteeGentile FWIW, you could write the code like this

– NathanOliver
Mar 27 at 13:01





@AbruzzoForteeGentile FWIW, you could write the code like this

– NathanOliver
Mar 27 at 13:01













@Nathan. Wow! That's pretty hard-core! I never seen using the '...' like that? In fact I don't understand much how your function works (sorry). I am used to recursively call of a variadic template with less argument...I have no idea how your function is expanding. Can you point me to some useful tip for further reading or investigation? I found this usage truly amazing.

– Abruzzo Forte e Gentile
Mar 27 at 13:44





@Nathan. Wow! That's pretty hard-core! I never seen using the '...' like that? In fact I don't understand much how your function works (sorry). I am used to recursively call of a variadic template with less argument...I have no idea how your function is expanding. Can you point me to some useful tip for further reading or investigation? I found this usage truly amazing.

– Abruzzo Forte e Gentile
Mar 27 at 13:44












0






active

oldest

votes










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%2f55377013%2ferror-while-generalizing-my-variadic-template-function%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















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%2f55377013%2ferror-while-generalizing-my-variadic-template-function%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

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해