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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:11:00+00:00 2026-05-26T21:11:00+00:00

make C++ functions or structs, classes (using meta-programming) determining maximum value for signed and

  • 0

make C++ functions or structs, classes (using meta-programming) determining maximum value for signed and unsigned type, according to compilers architecture. One for signed and second for unsigned numbers.

Requirements:

  • no header files
  • self adjusting to variable sizes (no stdint.h)
  • no compiler warnings about possible overflow

Clarification:

After comment’s I am surprised, on reaction for non typical C++ problem. I’ve learned it’s good to stress out, that problem is not homework and not from the moon, but it’s practical domain.

For all interested in application of this stuff… first of all: it is not homework :). And it’s practical, answerable question based on actual problems that I face – as in SO.FAQ is suggested . Thanks you for tips about climits etc, but I am looking for “smart piece of code”. For sure climits, limits are well tested and good pieces of code, but they are huge and not necessarily “smart,tricky”. We are looking here for smart solutions (not “huge-any” solutions), aren’t we? Even thou, climits suggestions are ok, as start point. For those interested about area, where including header files is not allowed, and size of source code is relevant, there are few: experiments with compilers, program transformations, preparing problemsets for programming contests, etc. Actually tree of them are relevant to problems I am currently struggling. So I don’t think it’s (SO.FAQ)too localized, and I think, it’s for sure, question for (SO.FAQ)enthusiast programmers. If you think that even all of this, there is something wrong with this question, please let me know – I don’t want to make mistake again. If it’s ok, please let me know, what I could do better to not get it downvoted?

  • 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-26T21:11:01+00:00Added an answer on May 26, 2026 at 9:11 pm

    Signedness could be determined at compile-time if you wish to merge maxSigned with maxUnsigned.

    #include <iostream>
    #include <cstddef> // for pytdiff_t, intptr_t
    
    template <typename T> static inline  bool is_signed() { 
        return ~T(0) < T(1);
    }
    template <typename T> static inline  T min_value() {
        return is_signed<T>() ? ~T(0) << (sizeof(T)*8-1) : T(0); 
    }
    template <typename T> static inline  T max_value() { 
        return ~min_value<T>();
    }
    
    #define REPORT(type) do{ std::cout\
        << "<" #type "> is " << (is_signed<type>() ? "signed" : "unsigned")\
        << ", with lower limit " << min_value<type>()\
        << " and upper limit " << max_value<type>()\
        << std::endl; }while(false)
    
    int main(int argc, char* argv[]) {
        REPORT(char);  // min, max not numeric
        REPORT(int);
        REPORT(unsigned);
        REPORT(long long);
        REPORT(unsigned long long);
        REPORT(ptrdiff_t);
        REPORT(size_t);
        REPORT(uintptr_t);
        REPORT(intptr_t);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make functions Double -> Double an instance of the Num typeclass.
I'm trying to solve a problem that anonymous functions make much, much easier, and
In this SO thread, Brian Postow suggested a solution involving fake anonymous functions: make
We are attempting to only make available certain functions to be run based on
I use functions like the following to make temporary tables out of crosstabs queries.
I want to make sure that a set of functions have the same signature
What do you think - which functions should be implemented to make work with
I'm trying to make a PHP regex to extract functions from php source code.
How do you make your application multithreaded ? Do you use asynch functions ?
I have two functions that are very similar and i'd like to make a

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.