468,512 Members | 1,423 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

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 20535
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by ma740988 | last post: by
3 posts views Thread by red floyd | last post: by
5 posts views Thread by Joe C | last post: by
2 posts views Thread by ma740988 | last post: by
12 posts views Thread by ma740988 | last post: by
18 posts views Thread by ma740988 | last post: by
5 posts views Thread by Michele Moccia | last post: by
6 posts views Thread by ma740988 | last post: by
1 post views Thread by Gennaro Prota | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.