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

  • Home
  • SEARCH
  • 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 7762461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:24:35+00:00 2026-06-01T14:24:35+00:00

Assume I have an enum, and I want each enum value to be associated

  • 0

Assume I have an enum, and I want each enum value to be associated with a certain type. Say the standard type is double, and if I want it to be something else I need to specify it explicitly.

Q1: Is this the preferred way to implement such a thing?

enum A {
    v1,
    v2,
    v3
};

// for every value of A, the standard type is double
template<A a>
struct A_info {
    typedef double type;
};

// other types for certain values can be specified using specialization
template<>
struct A_info<v2> {
    typedef size_t type;
};

Then, assume I have some function template, and I want to call the function depending on the type associated with a value of the enum:

template<typename T>
void foo() { /* do something */ }

template<A a>
void bar() { 
    foo< typename A_info<a>::type >(); 
}

This works fine. Now assume, I have another function depending on a variadic template list, and I want to do something similar as above …

template<typename ... T>
void foo_multiple() { /* stuff */ }

template<A ... a>
void bar_multiple() {  
    foo_multiple< /* ??? */ > ();
}

Q2: How to implement this? Is this possible, anyway?

  • 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-06-01T14:24:37+00:00Added an answer on June 1, 2026 at 2:24 pm

    Just expand the variadic parameter pack with the pattern you want:

    template<A ... a>
    void bar_multiple() {  
        foo_multiple<typename A_info<a>::type...> ();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume, that we have an enumered type: enum DataType { INT, DOUBLE };
Assume I have a generic type P which is an Enum, that is <P
I have come across some c code where the there is an enum type
Assume I have a Posts table with field Owner of type Person (which has
Assume I have some enum like the following: enum Towns { Rome, Napoli, Modena
How can I group Enum values? Assume I have an enum like public enum
In my code I have a domain object with an Enum type in it.
How to convert all elements from enum to string? Assume I have: public enum
Assume i have an enumeration : namespace System.Windows.Forms { public enum DialogResult { None,
assume i have a huge input form, which of course representing classes. i need

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.