delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/08/03:49:49

Date: Wed, 8 Mar 2000 09:59:12 +0200 (WET)
From: Andris Pavenis <pavenis AT lanet DOT lv>
To: Robin Johnson <robbat2 AT home DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: convert STL vector to *int
In-Reply-To: <38C52111.D5C5C3EE@home.com>
Message-ID: <Pine.A41.4.05.10003080954280.59450-100000@ieva05.lanet.lv>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: dj-admin AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com


On Tue, 7 Mar 2000, Robin Johnson wrote:

> Hi,
> 
> I need some help trying to convert all the elements of an STL vector array <int>
> to an *int array, for use with the Allegro polygon function.
> I am currently using libgpp for the STL. I had some code that worked with TC and
> most real mode compilers, using a few assembler shortcuts that of course don't
> work in protected mode. Anybody willing to lend a hand?
> 
> source: vector <int> v_list;
> dest: *int p_list;
> 


Simple example:


#include <algorithm>
#include <vector>
#include <iterator>

template <class T> 
T * to_array (vector<T> & from)
{
  T * ret = new T [from.size()];
  copy (from.begin(), frome.end(), ret);
  return ret;
}

Don't forget to free returned array after use.



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019