|
From: Gerhard Wolf on 11 Jun 2008 15:42 Hi, Daniel T. kindly posted me this snippet. Unfortunately it causes a: Templates must be a class or a function (Borland error) expected nested-name-specifier before 'iterator_traits' (GNU g++ error) so what is the STL replacement for this code? ---------------------------------------------------- template < typename It > typename iterator_traits<It>::value_type // <- find_most_prevalent(It begin, It end) { typedef typename iterator_traits<It>::value_type T; T result; int count = 0; while (begin != end) { T value = *begin; It newEnd = remove(begin, end, value); int newCount = distance(newEnd, end); if (newCount > count) { result = value; count = newCount; } end = newEnd; } return result; } ----------------------------------------------------
From: Mike Wahler on 11 Jun 2008 16:29 "Gerhard Wolf" <quisquiliae(a)gmx.de> wrote in message news:6bao5nF3af1s1U1(a)mid.individual.net... > Hi, > > Daniel T. kindly posted me this snippet. Unfortunately > it causes a: > Templates must be a class or a function (Borland error) > expected nested-name-specifier before 'iterator_traits' (GNU g++ error) > > so what is the STL replacement for this code? It looks like STL code to me. :-) FWIS, your code compiles OK with MSVC++ Express, once I #included <iterator>, and qualified 'iterator_traits', with 'std::' -Mike > ---------------------------------------------------- > template < typename It > > typename iterator_traits<It>::value_type // <- > find_most_prevalent(It begin, It end) > { > typedef typename iterator_traits<It>::value_type T; > T result; > int count = 0; > while (begin != end) { > T value = *begin; > It newEnd = remove(begin, end, value); > int newCount = distance(newEnd, end); > if (newCount > count) { > result = value; > count = newCount; > } > end = newEnd; > } > return result; > } > ----------------------------------------------------
From: Daniel T. on 12 Jun 2008 08:20 On Jun 11, 3:42 pm, Gerhard Wolf <quisquil...(a)gmx.de> wrote: > Hi, > > Daniel T. kindly posted me this snippet. Unfortunately > it causes a: > Templates must be a class or a function (Borland error) > expected nested-name-specifier before 'iterator_traits' (GNU g++ error) > > so what is the STL replacement for this code? > ---------------------------------------------------- > template < typename It > > typename iterator_traits<It>::value_type // <- > find_most_prevalent(It begin, It end) > { > typedef typename iterator_traits<It>::value_type T; > T result; > int count = 0; > while (begin != end) { > T value = *begin; > It newEnd = remove(begin, end, value); > int newCount = distance(newEnd, end); > if (newCount > count) { > result = value; > count = newCount; > } > end = newEnd; > } > return result;} > > ---------------------------------------------------- Don't be using that solution when Eric Pruneau provided a better one... Converting his algorithm to use iterators is trivial.
|
Pages: 1 Prev: template problem Next: (Job) - C++ Programmer - NYC, NY - with great client |