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?
Signedness could be determined at compile-time if you wish to merge maxSigned with maxUnsigned.