The only requirement on the Size template parameter of the std::search_n() template is that it be convertible to integral type (25.1.9, p4). The converse is not required to hold. The program below fails to compile due to unwarranted assumptions in the libstdc++ implementation of the algorithm. Regards Martin $ cat t.cpp; g++ -c t.cpp #include <algorithm> struct Integral { operator int() const; }; namespace std { template int* search_n (int*, int*, Integral, const int&); } /build/contrib/gcc-3.2/include/c++/3.2/bits/stl_algo.h: In function `_ForwardIter std::search_n(_ForwardIter, _ForwardIter, _Integer, const _Tp&) [with _ForwardIter = int*, _Integer = Integral, _Tp = int]': t.cpp:7: instantiated from here /build/contrib/gcc-3.2/include/c++/3.2/bits/stl_algo.h:612: conversion from ` int' to non-scalar type `Integral' requested /build/contrib/gcc-3.2/include/c++/3.2/bits/stl_algo.h:617: no match for `-- Integral&' operator
Subject: Bug 11400 CVSROOT: /cvs/gcc Module name: gcc Changes by: paolo@gcc.gnu.org 2003-09-29 17:36:18 Modified files: libstdc++-v3 : ChangeLog libstdc++-v3/include/bits: istream.tcc stl_algo.h Added files: libstdc++-v3/testsuite/27_io/basic_istream/peek/char: 12296.cc libstdc++-v3/testsuite/25_algorithms/search_n: 11400.cc Log message: 2003-09-29 Paolo Carlini <pcarlini@unitus.it> PR libstdc++/12296 * include/bits/istream.tcc (peek): Set eofbit if sgetc returns eof. * testsuite/27_io/basic_istream/peek/char/12296.cc: New, from the PR. 2003-09-29 Nathan Myers <ncm@cantrip.org> Paolo Carlini <pcarlini@unitus.it> PR libstdc++/11400 * include/bits/stl_algo.h (search_n): Use iterator_traits<>::difference_type for __n. * testsuite/25_algorithms/search_n/11400.cc: New, from the PR. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&r1=1.1973&r2=1.1974 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/istream.tcc.diff?cvsroot=gcc&r1=1.50&r2=1.51 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_algo.h.diff?cvsroot=gcc&r1=1.35&r2=1.36 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/testsuite/25_algorithms/search_n/11400.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1
Fixed.
Subject: Bug 11400 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: paolo@gcc.gnu.org 2003-09-30 14:37:40 Modified files: libstdc++-v3 : ChangeLog libstdc++-v3/include/bits: istream.tcc stl_algo.h Log message: 2003-09-30 Paolo Carlini <pcarlini@unitus.it> PR libstdc++/12296 * include/bits/istream.tcc (peek): Set eofbit if sgetc returns eof. 2003-09-30 Nathan Myers <ncm@cantrip.org> Paolo Carlini <pcarlini@unitus.it> PR libstdc++/11400 * include/bits/stl_algo.h (search_n): Use iterator_traits<>::difference_type for __n. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.1464.2.147&r2=1.1464.2.148 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/istream.tcc.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.36.4.6&r2=1.36.4.7 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libstdc++-v3/include/bits/stl_algo.h.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.27&r2=1.27.20.1