public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* a g++ compile warning
@ 2002-03-29  8:35 Luke Chang
  2002-03-29  9:20 ` g++ 2.95.2 - auto_ptr John Love-Jensen
  0 siblings, 1 reply; 3+ messages in thread
From: Luke Chang @ 2002-03-29  8:35 UTC (permalink / raw)
  To: 'gcc-help@gcc.gnu.org'

[-- Attachment #1: Type: text/plain, Size: 786 bytes --]

Hi,

Attached is a C++ file that I created.  It compiles and runs and
gives the correct output when compiled with GNU g++ compiler 
(version 3.0) on Sun Solaris, but I always get the following 
comiple warnings.  Tried without success to get rid of them.
Please help.  Thanks.

Luke Chang
Calix Networks
Lowell, MA

luke.cpp: In function `RandomIterator& _bsearch(RandomIterator,
RandomIterator, 
   T, std::random_access_iterator_tag) [with RandomIterator = 
   std::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, T
= 
   int]':
luke.cpp:13:   instantiated from `RandomIterator& bsearch(RandomIterator,
RandomIterator, T) [with RandomIterator = std::__normal_iterator<int*,
std::vector<int, std::allocator<int> > >, T = int]'
luke.cpp:68:   instantiated from here



[-- Attachment #2: luke.cpp --]
[-- Type: application/octet-stream, Size: 2214 bytes --]

#include <iostream>
#include <list>
#include <iterator>
#include <vector>
#include <utility>
using namespace std;

const unsigned short int list_size = 10; // same as but better than #define

template <class RandomIterator, class T>
RandomIterator& bsearch(RandomIterator first, RandomIterator last, T val) {
  typename iterator_traits<RandomIterator>::iterator_category i_c;
  return _bsearch(first, last, val, i_c); 
} // RandomIterator& bsearch ()

template <class RandomIterator, class T>
RandomIterator& _bsearch(RandomIterator first, RandomIterator last, T val, random_access_iterator_tag t) {
  typename iterator_traits<RandomIterator>::difference_type dist;
  RandomIterator probe, top, bot; 

  cout << "In RandomIterator& _bsearch()." << endl;
  bot = first;
  top = last - 1;
  while (top > bot) {
    dist = top - bot;
    probe = bot + dist;
    cout << "*probe is " << *probe << endl;
    if ((*probe) == val) {
      return probe;
    }
    else {
      if ((*probe) < val) {
        bot = probe + 1; 
      }
      else { 
        top = probe - 1;
      }
    } // else
  } // while (top > bot)

  return last; // if we get here
} // RandomIterator& _bsearch ()

template <class FwdIterator, class T>
FwdIterator& _bsearch(FwdIterator first, FwdIterator last, T val, forward_iterator_tag t) {
  cout << "In FwdIterator& _bsearch()." << endl;
  while (first != last) {
    if ((*first) == val) {
      return first;
    }
    first++;
  } // while (first != last)

  return last; // if we get here
} // FwdIterator& _bsearch ()

int main() {
  vector<int> vect;
  list<int> lst;
  int i;

  for (i = 0; i < list_size; i++) {
    vect.push_back(i);
    lst.push_back(i);
  }

  cout << "searching vector..." << endl;
  cout << *bsearch(vect.begin(), vect.end(), 5) << endl;
  cout << "searching list..." << endl;
  cout << *bsearch(lst.begin(), lst.end(), 5) << endl;

  return 0;
} // int main()

// The output is:
//
// searching vector...
// In RandomIterator& _bsearch().
// *probe is 9
// *probe is 8
// *probe is 7
// *probe is 6
// *probe is 5
// 5
// searching list...
// In FwdIterator& _bsearch().
// 5

^ permalink raw reply	[flat|nested] 3+ messages in thread

* g++ 2.95.2 - auto_ptr
  2002-03-29  8:35 a g++ compile warning Luke Chang
@ 2002-03-29  9:20 ` John Love-Jensen
  2002-03-30  1:13   ` Franz Fehringer
  0 siblings, 1 reply; 3+ messages in thread
From: John Love-Jensen @ 2002-03-29  9:20 UTC (permalink / raw)
  To: 'gcc-help@gcc.gnu.org'

(C++ lib 2.10)

Is this supposed to fail...

extern auto_ptr<Foo> NewFooFactory();
auto_ptr<Foo> foo;
foo = NewFooFactory(); // Compiler error.

...?

Or is there a bug in the compiler? Or a flaw in the <memory> header file?

--Eljay





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: g++ 2.95.2 - auto_ptr
  2002-03-29  9:20 ` g++ 2.95.2 - auto_ptr John Love-Jensen
@ 2002-03-30  1:13   ` Franz Fehringer
  0 siblings, 0 replies; 3+ messages in thread
From: Franz Fehringer @ 2002-03-30  1:13 UTC (permalink / raw)
  To: gcc-help

> (C++ lib 2.10)
> 
> Is this supposed to fail...
> 
> extern auto_ptr<Foo> NewFooFactory();
> auto_ptr<Foo> foo;
> foo = NewFooFactory(); // Compiler error.

Either

auto_ptr<Foo> foo = NewFooFactory();

or

auto_ptr<Foo> foo;
foo.reset(NewFooFactory());

Franz

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-03-30  9:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-29  8:35 a g++ compile warning Luke Chang
2002-03-29  9:20 ` g++ 2.95.2 - auto_ptr John Love-Jensen
2002-03-30  1:13   ` Franz Fehringer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).