473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

std::fill arrays

I saw that using std::fill was the way to go for setting all elements
of an array to some value in one foul swoop. However when I tryed it I
am getting an error.

Can I only use this for vectors or can I use it for a regular array?

what I called:
std::fill(m_start_times[0], m_start_times[8], 0);

error:
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\xutility(1136): error C2100: illegal indirection

// TEMPLATE FUNCTION fill
template<class _FwdIt,
class _Tyinline
void fill(_FwdIt _First, _FwdIt _Last, const _Ty& _Val)
{ // copy _Val through [_First, _Last)
for (; _First != _Last; ++_First)
*_First = _Val;
}

Jul 20 '06 #1
2 21087
cp***@austin.rr.com wrote:
I saw that using std::fill was the way to go for setting all elements
of an array to some value in one foul swoop. However when I tryed it I
am getting an error.

Can I only use this for vectors or can I use it for a regular array?

what I called:
std::fill(m_start_times[0], m_start_times[8], 0);
The arguments to 'fill' have to comply with 'iterator' traits. Elements
of the array don't. You need to use pointers:

std::fill(m_start_times + 0, m_start_times + 8, 0);
>
error:
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\xutility(1136): error C2100: illegal indirection

// TEMPLATE FUNCTION fill
template<class _FwdIt,
class _Tyinline
void fill(_FwdIt _First, _FwdIt _Last, const _Ty& _Val)
{ // copy _Val through [_First, _Last)
for (; _First != _Last; ++_First)
*_First = _Val;
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 20 '06 #2

<cp***@austin.rr.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>I saw that using std::fill was the way to go for setting all elements
of an array to some value in one foul swoop. However when I tryed it I
am getting an error.

Can I only use this for vectors or can I use it for a regular array?

what I called:
std::fill(m_start_times[0], m_start_times[8], 0);
std::fill(&m_start_times[0], &m_start_times[8], 0);

or

std::fill(m_start_times, m_start_times + 8, 0);

The second argument should be the address of the
'one-past-the-end' element; e.g. your example above
assumes an eight element array (indices 0 through
7).

-Mike
>
error:
c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\xutility(1136): error C2100: illegal indirection
-Mike
Jul 21 '06 #3

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

Similar topics

8
by: ma740988 | last post by:
Consider: # include <iostream> using std::cout; using std::cin; using std::endl; # include <list> using std::list;
3
by: red floyd | last post by:
I got an error by using std::fill to set an array of pointers to 0. e.g.: class XXX; XXX* v; std::fill(v, v+30, 0); // <-- ERROR -- cant' match template type I have to either explicitly...
5
by: Joe C | last post by:
I'm a hobbiest, and made the forray into c++ from non-c type languages about a year ago. I was "cleaning up" some code I wrote to make it more "c++ like" and have a few questions. I'm comfortable...
2
by: ma740988 | last post by:
The hierachy for standard exception lists: bad_alloc, bad_cast, bad_typeid, logic_error, ios_base::failure, runtime_error and bad_exception runtime_error and logic_error has subsets. The...
12
by: ma740988 | last post by:
I've allocated 4K memory and I'd like to use std::fill to fill each 1K with a different value. Note: I could easily use a vector/deque but I'm interested in a C style array. int main() { int...
18
by: ma740988 | last post by:
Trying to get more acclimated with the use of function objects. As part of my test, consider: # include <vector> # include <iostream> # include <algorithm> #include <stdexcept> #include...
5
by: Michele Moccia | last post by:
Simple newbie question: I want to set an int array to value 5 int i; int val=5; std::uninitialized_fill(&i, &i, val); OR std::uninitialized_fill(i, i+3, val);
6
by: ma740988 | last post by:
I've been perusing for some time now - I suppose some of the algorithms in Josuttis. 'Today', I do alot of funny math on data resident within memory. As part of this. I find myself using...
1
by: Gennaro Prota | last post by:
Hi, I have the following function template template< typename T, std::size_t n > void secure_fill( volatile T ( &arr ), const T & value = T() ) { for( std::size_t i( 0 ); i < n; ++i ) {...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.