GNU C++ has two binary operators >? and <? which provide min and max
but without any issues with
side effects as the normal macros have.
My question is, does any one know the exact priority of these
operators ?
Its not documented as far as I can see.
Thanks
Jeremy
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Use std::min and std::max. They don't have any side effects either,
and they're not limited to one implementation, and they're fully
documented in the Standard.
Also, IIRC, <? and >? are deprecated.
In such situation it's always a good idea to use parentheses. But
intuitivly they should have same priority as less/greater then
operators.
Nevertheless I would rather use std::min and std::max from STL.
These are functions which don't suffer from the same problems
as macros, but should be inlined so there should be no overhead.
Cheers,
Marcin
Quoting the gcc documentation:
The G++ minimum and maximum operators (`<?' and `>?') and their
compound forms (`<?=') and `>?=') have been deprecated and are
now removed from G++. Code using these operators should be
modified to use `std::min' and `std::max' instead.
That's not to say your question isn't valid, but it may be difficult
to get an answer. Your best bet is either to read an older version
of the gcc documentation (perhaps you've already done that), or to
experiment with an older version of g++ that still supports them.
--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
The G++ minimum and maximum operators (`<?' and `>?') and their compound
forms (`<?=') and `>?=') have been deprecated and are now removed from
G++. Code using these operators should be modified to use std::min and
std::max instead.
So it doesn't really matter what their precedence is!
> *From:* Jeremy Hall <gcc....@gmail.com>
> *To:* undisclosed-recipients:;
> *Date:* Sat, 5 Mar 2011 14:03:34 CST
I agree that std::min/std::max should be used, where possible instead
of compiler-specific extensions like <? and >?. One possible reason for
still needing to use the extension forms is, when the min/max evaluation
has to open in a constant expression (I don't know these extension
functions, but I assume that they can be used in constant expressions).
Unfortunately std::min/std::max are not (yet) constexpr functions. This
may also be tricky, depending on the current evolution of the core-rules
in regard to constexpr functions.
Greetings from Bremen,
Daniel Krügler
In that case, I'd use a macro, since there should be no side effects for
a const expression.
> GNU C++ has two binary operators >? and <? which provide min and max
> but without any issues with side effects as the normal macros have.
>
> My question is, does any one know the exact priority of these
> operators? Its not documented as far as I can see.
They're not just deprecated: they've been removed entirely from recent
versions of gcc. As others have said, you should consider using
std::max and std::min instead, but be aware that some (old or badly
behaved) headers may #define symbols called max and min. To answer
your question, they were in their own precedence level between == and
& and were left-to-right associative. It was possible to overload the
operators using the obvious syntax.
--
Richard Smith
I remember hearing lots of other "imperfections" with std::{min,max},
besides this. For example, std::min(1, 1L) doesn't compile, and neither
does ++std::min(x, y) (By the way, why isn't there a non-const overload?),
while both are possible in the macro version.
Basically, we want to be able to do whatever we can do with the macro
version, minus all the pitfalls of macros. And the template function
solution hasn't been able to meet the needs.
Can anyone tell why <? and ?> have been deprecated and removed from GCC?
I think they could be useful at times, though std::{min,max} will work
*most* of the time.
--
Seungbeom Kim
Personally I would appreciate if std::min/std::max became constexpr
functions for exactly these kind of purposes. One argument for providing
constexpr functions was to remove the second-class citizen status of
functions in constant expressions as outlined in
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2235.pdf
Actually the core-language state of the most recent draft *would* allow
for making these functions constexpr. But it is too late for C++0x to
make std::min/std::max constexpr-capable.
Greetings from Bremen,
Daniel Krügler