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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:27:08+00:00 2026-05-26T05:27:08+00:00

I have a class, called DynamicTexture that takes in the width and height of

  • 0

I have a class, called DynamicTexture that takes in the width and height of a texture as template parameters. The parameters are used to instantiate a fixed size table (which is also a template class).

In my case, I am instantiating the DynamicTexture for various powers of two width/height (so 2×2, 4×4, 8×8, 16×16, 32×32 etc. all the way to 4096×4096). That means I have a lot of declarations like this:

DynamicTexture<2, 2>       dTexture2;
DynamicTexture<4, 4>       dTexture4;
...
DynamicTexture<4096, 4096> dTexture4096;

Now the question is, can I automate that process somehow? Furthermore, I am selecting the approxiate dTexture by quering a variable of type unsigned int (which shows the current size selected by the user) and then displaying the texture:

if (currTexSize == 2) dTexture2->show();
else if (currTexSize == 4) dTexture4->show();
...
else { dTexture4096->show(); }

Again, any way to avoid the long list of if statements?

NOTE: I am not sure how to phrase the title for this particular question. Feel free to re-word it.

  • 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-26T05:27:08+00:00Added an answer on May 26, 2026 at 5:27 am

    Now the question is, can I automate that process somehow?

    You can do it with some advanced metaprogramming tricks:

    template< int Width, int Height >
    struct textures_holder
        : textures_holder< Width * 2, Height * 2 >
    {
        typedef textures_holder< Width * 2, Height * 2 > base_t;
    
        void show( int currTexSize ) const
        {
            if( currTexSize == Width ) // or is it == Height?
                _texture->show();
            else
                base_t::show( currTexSize );
        }
    
        DynamicTexture< Width, Height > _texture;
    };
    
    template<>
    struct textures_holder< 4096, 4096 >
    {
        void show( int currTexSize ) const
        {
            _texture->show();
        }
    };
    

    then you would create an object of type textures_holder< 1, 1 > and get a variable for each of the power of 2 dimensions up to 4096.

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

Sidebar

Related Questions

I have a class called DatabaseHelper that wraps a DbConnection. What's the proper way
I have a class called UserInfo that contains details about a given user. There
I have a class called Question that has a property called Type. Based on
I have one class called Person that basically looks like: public class Person {
I have a class called forest and a property called fixedPositions that stores 100
I have a class called Image and a class that extends it called ImageSheet
I have a container class (called Atom) that I want to store objects of
I have a class called Foo that has a function that looks like the
I have a class called Partner, that I need to Submit all the info
I have a class called Foo that defines a list of objects of type

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.