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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:43:18+00:00 2026-05-16T22:43:18+00:00

I have two structs: // —– non-const —– struct arg_adapter { EArgType type; //

  • 0

I have two structs:

  // ----- non-const -----
  struct arg_adapter
  {
      EArgType type;  // fmtA, fmtB, ...

      union
      {
        TypeA * valueA;
        TypeB * valueB;
        // ... more types
      }

      arg_adapter(TypeA & value) : type(fmtA), valueA(&value) {}
      arg_adapter(TypeB & value) : type(fmtB), valueB(&value) {}
      // ...
  }

  // ----- const version -----
  struct const_arg_adapter
  {
      EArgType type;  // fmtA, fmtB, ...

      union
      {
        TypeA const * valueA;
        TypeB const * valueB;
        // ... more types
      }

      arg_adapter(TypeA const & value) : type(fmtA), valueA(&value) {}
      arg_adapter(TypeB const & value) : type(fmtB), valueB(&value) {}
      // ...
  }

They are supposed to be used in methods such as:

  Convert(const_arg_adapter from, arg_adapter to)

There are multiple TypeX’ (about 5, may become more), most of them primitive. This is to avoid maintaining different prototypes.

Now my question 😉

Is there a way to make the const-ness a template parameter?
My goal is to maintain only one struct, i.e.

template <Qualifier CONSTNESS>
struct arg_adapter_t
{
   ...
   CONSTNESS TypeA * valueA;
   ...
}
  • 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-16T22:43:18+00:00Added an answer on May 16, 2026 at 10:43 pm

    You can make it accept a metafunction and you can apply any transformation you like

    template<template<typename> class F>
    struct arg_adapter
    {
        EArgType type;  // fmtA, fmtB, ...
    
        union
        {
          typename F<TypeA>::type * valueA;
          typename F<TypeB>::type * valueB;
          // ... more types
        };
    
        arg_adapter(typename F<TypeA>::type & value) : type(fmtA), valueA(&value) {}
        arg_adapter(typename F<TypeB>::type & value) : type(fmtB), valueB(&value) {}
        // ...
    };
    
    typename arg_adapter<boost::add_const> const_adapter;
    typename arg_adapter<boost::mpl::identity> nonconst_adapter;
    

    Or accept a metafunction class to get more flexibility (including the ability to make F have default arguments not known to your arg_adapter and such.

    template<typename F>
    struct arg_adapter
    {
        EArgType type;  // fmtA, fmtB, ...
    
        union
        {
          typename apply<F, TypeA>::type * valueA;
          typename apply<F, TypeB>::type * valueB;
          // ... more types
        };
    
        arg_adapter(typename apply<F, TypeA>::type & value) : type(fmtA), valueA(&value) {}
        arg_adapter(typename apply<F, TypeB>::type & value) : type(fmtB), valueB(&value) {}
        // ...
    };
    
    typename arg_adapter< lambda< boost::add_const<_> >::type > const_adapter;
    typename arg_adapter< lambda< boost::mpl::identity<_> >::type > nonconst_adapter;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two structs: template <typename T> struct Odp { T m_t; T operator=(const
So, I have two structs: struct coordinate { float x; float y; } struct
The code is in C. I have two type of objects ( structs )
I have two arrays of structs. array_of_structs1 array_of_structs2 The struct class looks like this,
I have three structs, one of which inherits from the other two: typedef struct
I have two structs of the same type, the fields are comprised of strings.
If I have two structs: struct A { float x, y; inline A operator*(A
In a C++ program I have two classes (structs) like struct A { int
I have two structs pointers to pointers typedef struct Square { ... ... }Square;
I have an array of structs. The struct has two function pointers. Each element

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.