On Mar 22, 10:51*pm, m0shbear <andrey....@gmail.com> wrote:
> I am using the following variant of std::search to simplify my code.
>
> template <class ForwardIterable1, class ForwardIterable2>
> auto search(ForwardIterable1&& _1, ForwardIterable2&& _2) ->
> decltype(_1.begin()) {
> * * * * return std::search(_1.begin(), _1.end(), _2.begin(),
> _2.end());
>
> }
>
> template <class ForwardIterable1, class ForwardIterable2, class
> BinaryPredicate>
> auto search(ForwardIterable1&& _1, ForwardIterable2&& _2,
> BinaryPredicate _p) -> decltype(_1.begin()) {
> * * * * return std::search(_1.begin(), _2.begin(), _p);
>
> }
>
> Two immediate questions arise:
> 1) Is '&&' appropriate to use here or should 'const&' be used instead?
> 2) Are there plans for this to be in the final c++0x (yes i know this
> question is better-suited to be asked on comp.std.c++) or will this
> probably a compiler extension which will only be useful after posting
> as a bugreport to $COMPILERVENDOR?
Corrections: change decltype(_1.begin()) to decltype(std::begin(_1))
change _1.begin() with std::begin(_1); likewise for _1.end() and for
_2.
Updated code should be:
template <class ForwardIterable1, class ForwardIterable2>
auto search(ForwardIterable1&& _1, ForwardIterable2&& _2) ->
decltype(std::begin(_1)) {
return std::search(std::begin(_1), std::end(_1),
std::begin(_2), std::end(_2));
}
template <class ForwardIterable1, class ForwardIterable2, class
BinaryPredicate>
auto search(ForwardIterable1&& _1, ForwardIterable2&& _2,
BinaryPredicate _p) -> decltype(std::begin(_1)) {
return std::search(std::begin(_1), std::end(_1),
std::begin(_2), std::end(_2), p);
}
I forgot that the N2930 iterator used the format of std::begin/end
instead of class-wrapping begin and end.
|