std::max: if versus ?:
Paolo Carlini
paolo.carlini@oracle.com
Fri Sep 21 10:10:00 GMT 2012
On 09/20/2012 01:55 PM, Marc Glisse wrote:
> The reason I am asking is that if I add ?: support for vector types (Ã
> la OpenCL), with "if" std::max will still fail on vectors, but with ?:
> it would suddenly become accepted.
So I went ahead and tested the below - I'll apply it later - as a
tiny-tiny encouragement ;)
Thanks,
Paolo.
/////////////////////
-------------- next part --------------
2012-09-21 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/stl_algobase.h (max, min): Use conditional operator.
-------------- next part --------------
Index: include/bits/stl_algobase.h
===================================================================
--- include/bits/stl_algobase.h (revision 191604)
+++ include/bits/stl_algobase.h (working copy)
@@ -195,10 +195,8 @@
{
// concept requirements
__glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
- //return __b < __a ? __b : __a;
- if (__b < __a)
- return __b;
- return __a;
+
+ return __b < __a ? __b : __a;
}
/**
@@ -218,10 +216,8 @@
{
// concept requirements
__glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
- //return __a < __b ? __b : __a;
- if (__a < __b)
- return __b;
- return __a;
+
+ return __a < __b ? __b : __a;
}
/**
@@ -238,12 +234,7 @@
template<typename _Tp, typename _Compare>
inline const _Tp&
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
- {
- //return __comp(__b, __a) ? __b : __a;
- if (__comp(__b, __a))
- return __b;
- return __a;
- }
+ { return __comp(__b, __a) ? __b : __a; }
/**
* @brief This does what you think it does.
@@ -259,12 +250,7 @@
template<typename _Tp, typename _Compare>
inline const _Tp&
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
- {
- //return __comp(__a, __b) ? __b : __a;
- if (__comp(__a, __b))
- return __b;
- return __a;
- }
+ { return __comp(__a, __b) ? __b : __a; }
// If _Iterator is a __normal_iterator return its base (a plain pointer,
// normally) otherwise return it untouched. See copy, fill, ...
More information about the Libstdc++
mailing list