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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:39:14+00:00 2026-05-23T20:39:14+00:00

I have a template statistics class that has range parameters. template <typename T> class

  • 0

I have a template statistics class that has range parameters.

template <typename T>
class limitStats
{
public:
    limitStats(T mx, T min) :
      max(mx),
      min(mn),
      range(mx-mn)
    {;}

private:
    const T max;
    const T min;
    const T range;
}

I would like to put default values of maximum and minimum allowable values, but the minimum value is not the same for floating point and integer types.

Normally I can write

T min_val = numeric_limits<T>::isinteger ? numeric_limits<T>::min() : -numeric_limits<T>::max();

I have found that I can’t use it as a default parameter

limitStats(T mx = std::numeric_limts<T>::max(), 
           T mn = numeric_limits<T>::isinteger ? numeric_limits<T>::min() : -numeric_limits<T>::max())

Is there a way of achieving something like this?

  • 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-23T20:39:15+00:00Added an answer on May 23, 2026 at 8:39 pm

    You might want to rethink your design. What are you trying to do with your limitStats that std::numeric_limits doesn’t provide?

    Don’t replicate the badness of the design of std::numeric_limits. For example, std::numeric_limits<double>::min() is terribly misnamed. The minimum double is the additive inverse of the maximum double. std::numeric_limits is an abuse of notation and an abuse of templates. In my opinion, of course.

    Your idea for min is ill-formed. Think about your default with respect to limitStats<unsigned int>.

    With the defaults, your range is invalid for signed integers. For unsigned ints it replicates max, assuming you fix the problem with limitStats<unsigned int>::min. For floating point types, it is either invalid or replicates max, depending on what you mean by limitStats<floating_point_type>::min.

    Does it even make sense to allow default values? You wouldn’t even have this question if you simply don’t provide defaults and make the default constructor private/unimplemented.

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

Sidebar

Related Questions

I have a template class that is only valid for couple of template parameters:
I have template < typename threadFuncParamT > class ThreadWrapper { public: static int ThreadRoutineFunction(void*
I have a template class that I serialize (call it C), for which I
I have a template class like below. template<int S> class A { private: char
I have some template code that I would prefer to have stored in a
I have a template I made that sets variables that rarely change, call my
I have a data.frame in R that looks like this: score rms template aln_id
I have template function compare defined as below. #include<iostream> using namespace std; template<typename T>
I have a template called client_details.html that displays user , note and datetime .
I am running Django trunk and have template Autoescaping on (default). Do I need

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.