Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6336587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:05:10+00:00 2026-05-24T19:05:10+00:00

I have the following (partial) code in a class where I try to evaluate

  • 0

I have the following (partial) code in a class where I try to evaluate a value against a list of values via metaprogramming in C++11.

bool eval(GLenum value)
{
    return false;
};

template<GLenum One, GLenum... Others>
bool eval(GLenum value)
{
    if( value == One )
        return true;

    // Try out the rest
    return eval<Others...>(value);
};

gcc complains:

../emul/GLPart.h: In member function ‘bool
GLPart::eval(GLenum) [with unsigned int One = 519u,
unsigned int …Others = {}, unsigned int …ValidEnums = {512u, 513u,
514u, 515u, 516u, 517u, 518u, 519u}, GLenum = unsigned int]’:
../emul/GLPart.h:26:31: instantiated from ‘bool
GLPart::eval(GLenum) [with unsigned int One = 518u,
unsigned int …Others = {519u}, unsigned int …ValidEnums = {512u,
513u, 514u, 515u, 516u, 517u, 518u, 519u}, GLenum = unsigned int]’
../emul/GLPart.h:26:31: instantiated from ‘bool
GLPart::eval(GLenum) [with unsigned int One = 517u,
unsigned int …Others = {518u, 519u}, unsigned int …ValidEnums =
{512u, 513u, 514u, 515u, 516u, 517u, 518u, 519u}, GLenum = unsigned
int]’ ../emul/GLPart.h:26:31: instantiated from ‘bool
GLPart::eval(GLenum) [with unsigned int One = 516u,
unsigned int …Others = {517u, 518u, 519u}, unsigned int
…ValidEnums = {512u, 513u, 514u, 515u, 516u, 517u, 518u, 519u},
GLenum = unsigned int]’ ../emul/GLPart.h:26:31: instantiated from
‘bool GLPart::eval(GLenum) [with unsigned int One = 515u,
unsigned int …Others = {516u, 517u, 518u, 519u}, unsigned int
…ValidEnums = {512u, 513u, 514u, 515u, 516u, 517u, 518u, 519u},
GLenum = unsigned int]’ ../emul/GLPart.h:26:31: instantiated from
‘bool GLPart::eval(GLenum) [with unsigned int One = 514u,
unsigned int …Others = {515u, 516u, 517u, 518u, 519u}, unsigned int
…ValidEnums = {512u, 513u, 514u, 515u, 516u, 517u, 518u, 519u},
GLenum = unsigned int]’ ../emul/GLPart.h:26:31: instantiated from
‘bool GLPart::eval(GLenum) [with unsigned int One = 513u,
unsigned int …Others = {514u, 515u, 516u, 517u, 518u, 519u},
unsigned int …ValidEnums = {512u, 513u, 514u, 515u, 516u, 517u,
518u, 519u}, GLenum = unsigned int]’ ../emul/GLPart.h:26:31:
instantiated from ‘bool GLPart::eval(GLenum) [with
unsigned int One = 512u, unsigned int …Others = {513u, 514u, 515u,
516u, 517u, 518u, 519u}, unsigned int …ValidEnums = {512u, 513u,
514u, 515u, 516u, 517u, 518u, 519u}, GLenum = unsigned int]’
../emul/GLPart.h:31:43: instantiated from ‘bool
GLPart::Evaluate(GLenum) [with unsigned int …ValidEnums
= {512u, 513u, 514u, 515u, 516u, 517u, 518u, 519u}, GLenum = unsigned
int]’ alpha.cpp:8:7: instantiated from here ../emul/GLPart.h:26:31:
error: no matching function for call to ‘GLPart<512u, 513u, 514u,
515u, 516u, 517u, 518u, 519u>::eval(GLenum&)’

So it seems like it chokes on the last recursion when One has a value and Others don’t. In this case the template parameters should then be empty. Do I need to declare the ordinary eval in another way? Haven’t coded C++ in a while so it may be trivial but I just don’t get it 😉

When trying to add template<> to the first eval it chokes:

../emul/GLPart.h:14:11: error: explicit specialization in
non-namespace scope ‘class GLPart’ ../emul/GLPart.h:21:7:
error: too many template-parameter-lists ../emul/GLPart.h: In member
function ‘bool GLPart::Evaluate(GLenum)’:
../emul/GLPart.h:32:23: error: parameter packs not expanded with
‘…’: ../emul/GLPart.h:32:23: note: ‘ValidEnums’
../emul/GLPart.h:32:33: error: expected ‘,’ or ‘;’ before ‘…’ token

Solution:

template<GLenum One>
bool eval(GLenum value)
{
    return value == One;
};

template<GLenum One, GLenum Two, GLenum... Others>
bool eval(GLenum value)
{
    if( eval<One>(value) )
        return true;

    // Try out the rest
    return eval<Two, Others...>(value);
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:05:11+00:00Added an answer on May 24, 2026 at 7:05 pm

    Since this tends to produce lots of ambiguity errors, the variation that seems to work unambigously looks like this:

    template<GLenum One> 
    bool eval(GLenum value)
    {
        return value == One;
    };
    template<GLenum One, GLenum Two, GLenum... Others>
    bool eval(GLenum value)
    {
        if( value == One )
            return true;
    
        // Try out the rest
        return eval<Two, Others...>(value);
    };
    

    The first overload takes exactly one argument, the second at least two. Taking zero arguments probably doesn’t make sense anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: public partial class queryTerm : System.Web.UI.UserControl { private static
I have the following code: public partial class Form1 : Form { public BindingList<Class>
I have the following code: public partial class NewWindow: Window { public static readonly
I have the following code... public partial class DownloadFile : System.Web.UI.Page { protected void
I have the following code: public partial class AuditLog : IBusinessEntity { public BusinessEntityType
I have the following code in a partial view (using Spark): <span id=selectCount>0</span> video(s)
Consider the following code: partial class OurBusinessObject { partial void OnOurPropertyChanged() { if(ValidateOurProperty(this.OurProperty) ==
I have the following partial view code @model IEnumerable<PDoc.Web.Models.UserDocModel> @using MvcContrib.UI.Grid; @using MvcContrib.UI.Pager; @using
I have the following code: XAML: <Window x:Class=ContextMenuIssue.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml Title=MainWindow Height=350 Width=525> <Grid>
In my partial class containing the DataSet event I have the following: protected override

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.