472,977 Members | 1,601 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,977 software developers and data experts.

std::uninitialized_fill

Simple newbie question:

I want to set an int array to value 5

int i[3];
int val=5;
std::uninitialized_fill(&i[0], &i[3], val);
OR
std::uninitialized_fill(i, i+3, val);

I need to pass as last iterator an out of index reference to completly fill
the array.
I think because std::uninitialized_fill do something like "while ( First !=
Last ) {...do something...}"
So my iterator will be incremented out of index? Is it dangerous?

Many thanks

Michele
Feb 23 '06 #1
5 2261
JE
Michele Moccia wrote:
Simple newbie question:

I want to set an int array to value 5

int i[3];
int val=5;


<snip>

std::fill( i, i + sizeof(i)/sizeof(*i), val );

Leave uninitialized_fill alone, unless you're writing allocators or
something...

Feb 24 '06 #2
Michele Moccia wrote:
I want to set an int array to value 5

int i[3];
int val=5;
std::uninitialized_fill(&i[0], &i[3], val);
OR
std::uninitialized_fill(i, i+3, val);
.... or:

template <typename T, int size>
T* begin(T(&array)[size]) { return array; }
template <typename T, int size>
T* end(T(&array)[size]) { return array + T; }

int main()
{
int i[3];
std::fill(begin(i), end(i), 5);
}
I need to pass as last iterator an out of index reference to completly
fill the array.


The pointer to the element one past the last array element is always
defined. Thus, it is safe to pass this pointer as an argument to a
function and, in fact, the STL algorithms take heavy advantage of
this features. Note, however, that you may not dereference this
pointer!
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Feb 24 '06 #3
JE
Michele Moccia wrote:
Simple newbie question:

I want to set an int array to value 5

int i[3];
int val=5;


<snip>

std::fill( i, i + sizeof(i)/sizeof(*i), val );

Leave uninitialized_fill alone, unless you're writing allocators or
something...

Feb 24 '06 #4
Dietmar Kuehl wrote:
[redacted
template <typename T, int size>
T* end(T(&array)[size]) { return array + T; } I assume you mean { return array + size; }

Feb 24 '06 #5
red floyd wrote:
Dietmar Kuehl wrote:
[redacted
template <typename T, int size>
T* end(T(&array)[size]) { return array + T; }

I assume you mean { return array + size; }


Yes, of course: I just typed the code without testing it...
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Feb 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Lasse Skyum | last post by:
I'm currently learning STL and I hate not knowing what is gooing on "inside" STL... not because I really _need_ to know it to develop my game project, but that's just my nature... like most of you...
2
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray =...
4
by: Steven T. Hatton | last post by:
Are the Standard Headers as described in ISO/IEC 14882:2003 available in source file form as they appear in the standard? What I mean by this is, for example 20.4 describes the Header<memory> and...
822
by: Turamnvia Suouriviaskimatta | last post by:
I 'm following various posting in "comp.lang.ada, comp.lang.c++ , comp.realtime, comp.software-eng" groups regarding selection of a programming language of C, C++ or Ada for safety critical...
4
by: Hora | last post by:
Hi Guys I'm reading Andrew Koenig and Barbara E. Moo 's book, Accelerated C++. It's the best works for newbie I ever read. The way the authors introduce the language is very interesting. In...
4
by: Urs Thuermann | last post by:
I have some old code I've written several years ago that doesn't compile with newer versions of GCC. The code allocates an array of objects that need to be initialized by calling a constructor...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.