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 6670787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:18:37+00:00 2026-05-26T03:18:37+00:00

I have a set of types related with a one-to-one relation, for example: TypeA

  • 0

I have a set of types related with a one-to-one relation, for example:

TypeA ---> Type1
TypeB ---> Type2 
TypeC ---> Type3

I know these relation at compile time.

Then, I have a template class that depends on this two types:

template<class T1,class T2>
class MyClass
{
  T1 foo;
  T2 bar;
};

Now, the user of my library will type something like:

MyClass<TypeA,Type1> x;

This is inconvenient because there is a dependency between the two types and it should be enough for the user specify only the first type.

Also, mixing the two types shouldn’t be possible:

MyClass<TypeA,Type2> y; //it should not compile

I am not very familiar with template meta programming, I got the impression that this is doable task, but I may be wrong.

The number of types involved is big, however I am happy to run a script to generate the code if necessary.

Do you know if it is possible or I am wasting my time? Do you have any ideas to point me on the right direction?

  • 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-26T03:18:37+00:00Added an answer on May 26, 2026 at 3:18 am
    template<class T>
    struct get_mapped;
    
    template<>
    struct get_mapped<TypeA>{
        typedef Type1 type;
    };
    
    // and so on....
    
    
    template<class T>
    class MyClass{
        typedef typename get_mapped<T>::type T2;
    
        T foo;
        T2 bar;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of types templated on an integer N, and a class
I have a field aliases of type java.util.Set in one Entity . This Set
I have a list of vectors - the set of types is known and
I have your run of the mill nested set hierarchy type setup with the
I have a products table with a column of type SET (called especialidad), with
I have a set of SQL statements formatted like so: INSERT INTO reports.workload (workload_id,event_time,event_type_id,agent_id)
I have a mysql table field set as time type which stores data in
I have terminal.app set to accept utf-8 and in bash I can type unicode
In my servlet I have the following code: response.setContentType(application/json);//set json content type PrintWriter out
I have a data type that contains a set and a method that expects

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.