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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:21:55+00:00 2026-05-18T06:21:55+00:00

Would you write the following simple container any other way or it’s totally sensible

  • 0

Would you write the following simple container any other way or it’s totally sensible as it is:

template <typename T, bool small_>
struct TransType
{
   typedef const T& param_type;
};

template <typename T>
struct TransType<T, true>
{
   typedef const T param_type;
};

template <class T>
class Container:public TransType<T,sizeof(T)<=sizeof(void*)> {
 public:
  param_type getVal(){
   return obj;
  }
  void setVal(param_type input){
   containment=input;
  }
 private:
  T containment;
};
  • 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-18T06:21:56+00:00Added an answer on May 18, 2026 at 6:21 am

    Look into Boost.CallTraits. Namely, boost::call_traits<T>::param_type.

    You shouldn’t need the client to specify whether the type is small or not, that’s the metafunction’s job. Nor is there really a need to inherit from anything.

    In fact your code right now is ill-formed. Because param_type isn’t a dependent type, the lookup is done without taking into consideration the base class; and will not be found. You’d need to either explicitly qualify it with the base class, add a using-directive, or re-typedef it.

    You just want to end up with:

    template <typename T>
    struct Container
    {
        //typedef typename boost::call_traits<T>::param_type param_type;
        typedef typename TransType<T>::param_type param_type;
    
        // ...
    };
    

    By:

    namespace detail
    {
        template <typename T, bool small_>
        struct TransType
        {
           typedef const T& param_type;
        };
    
        template <typename T>
        struct TransType<T, true>
        {
           typedef const T param_type;
        };
    }
    
    template <typename T>
    struct TransType<T>
    {
       typedef detail::TransType<T, sizeof(T)<=sizeof(void*)> param_type;
    };
    

    Now the condition is automatic, and there’s no base class hassle.

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

Sidebar

Related Questions

Following on from this question what would be the best way to write a
How would I write the following C# code in F#? namespace Shared { public
I would like to write the following SQL in HQL so it executes as
Using MySQL syntax, how would I write a query to return the following (I
I am trying to write a very thin hypervisor that would have the following
Do you know any library that will help doing that? I would write a
I would like to write the following code in c#. a) small console application
I wrote this simple class that provides buffering for general output operation: template <typename
In Perl, I would write: $x = abbbc; $x =~ s/(b+)/z/; print Replaced $1
I want to make my CMS work like this, if you would write certain

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.