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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:43:20+00:00 2026-05-22T11:43:20+00:00

That is my question. I’m just curious what the consensus is on limiting the

  • 0

That is my question. I’m just curious what the consensus is on limiting the types that can be passed in to a generic function or class. I thought I had read at some point, that if you’re doing generic programming, it was generally better to leave things open instead of trying to close them down (don’t recall the source).

I’m writing a library that has some internal generic functions, and I feel that they should only allow types within the library to be used with them, simply because that’s how I mean for them to be used. On the other hand, I’m not really sure my effort to lock things down is worth it.

Anybody maybe have some sources for statistics or authoritative commentary on this topic? I’m also interested in sound opinions. Hopefully that doesn’t invalidate this question altogether :\

Also, are there any tags here on SO that equate to “best-practice”? I didn’t see that one specifically, but it seems like it’d be helpful to be able to bring up all best-practice info for a given SO topic… maybe not, just a thought.

Edit: One answer so far mentioned that the type of library I’m doing would be significant. It’s a database library that ends up working with STL containers, variadics (tuple), Boost Fusion, things of that nature. I can see how that would be relevant, but I’d also be interested in rules of thumb for determining which way to go.

  • 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-22T11:43:21+00:00Added an answer on May 22, 2026 at 11:43 am

    Always leave it as open as possible – but make sure to

    • document the required interface and behaviour for valid types to use with your generic code.
    • use a type’s interface characteristics (traits) to determine whether to allow/disallow it. Don’t base your decision on the type name.
    • produce reasonable diagnosis if
      someone uses a wrong type. C++
      templates are great at raising tons
      of deeply-nested errors if they get instanced with
      the wrong types – using type traits, static assertions and related techniques, one can easily produce more succinct error messages.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had that question in mind for a long time. Theoretically, jQuery core function
a question that a co-interviewer asked in interviews. I always thought it was a
I was pretty sure that the answer to that question was, Never, ever can
The second part of that question is key. If you are one of a
Yes, there is a similar question here . However, that question doesn't seem to
My good friend, Wikipedia, didn't give me a very good response to that question.
A question that has pondered me for the last while. I am primarily a
Simple question that keeps bugging me. Should I HTML encode user input right away
A question that occasionally arises is what is the best way to determine the
Here's a question that's been haunting me for a year now. The root question

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.