|
|
Wanted: Help implementing minimal iterator
I've been google searching for help and reading Josuttis's book "The
Standard C++ Library" and cannot find a simple recipie (cookbook approach)
for recreating a minimal iterator.
Here is what I have so far that works:
//std::ostream_iterator<ClusterPseudoContainer<DUMMY002::vector_bool_t>::ite
rator > out(oss," ");
//std::copy( ccDirty.begin(), ccDirty.end(), out);
for(ClusterPseudoContainer<DUMMY002::vector_bool_t>::iterator ii =
ccDirty.begin(); ii != ccDirty.end(); ++ii)
oss << " " << *ii;
I've defined the operator++ for the inner const_iterator and iterator
classes of ClusterPseudoContainer. operator* returns an instance of class
Cluster, another inner class. Operator<< is defined for class Cluster.
I would like to use the above commented code. The commented code does not
work.
Microsoft MSVC7 says
"c:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\xutility(1022): error C2679: binary '=' : no operator found
which takes a right-hand operand of type
'ClusterPseudoContainer<ContainerType>::Cluster' (or there is no acceptable
conversion)
with
[
ContainerType=std::vector<bool,std::allocator<bool>>
]
"
What is necessary to make the commented code work? g++ v3.2 error messages
are similar.
Thanks,
Siegfried
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
Siegfried
|
4/8/2006 10:06:48 AM |
|
"Siegfried Heintze" <siegfried@heintze.com> writes:
> I've been google searching for help and reading Josuttis's book "The
> Standard C++ Library" and cannot find a simple recipie (cookbook approach)
> for recreating a minimal iterator.
Try
http://www.boost.org/libs/iterator/doc/index.html#iterator-facade-and-adaptor
It's very easy for even experienced C++ programmers to create
incorrect "iterators" unless they use these libraries.
HTH,
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
David
|
4/9/2006 8:58:25 AM
|
|
In article <44367db0$1@mamba.>, Siegfried Heintze
<siegfried@heintze.com> wrote:
> I've been google searching for help and reading Josuttis's book "The
> Standard C++ Library" and cannot find a simple recipie (cookbook approach)
> for recreating a minimal iterator.
>
> Here is what I have so far that works:
>
> //std::ostream_iterator<ClusterPseudoContainer<DUMMY002::vector_bool_t>::ite
> rator > out(oss," ");
>
> //std::copy( ccDirty.begin(), ccDirty.end(), out);
>
> for(ClusterPseudoContainer<DUMMY002::vector_bool_t>::iterator ii =
> ccDirty.begin(); ii != ccDirty.end(); ++ii)
>
> oss << " " << *ii;
The commented out code and the explicit loop are different. Since
the error refers to operator '=' . Note that
std::ostream_iterator<T,...> has an std::ostream_iterator<T,...> &
operator = (const T &) and operator *() is an essential no op
returning
a reference to the iterator... so that *out = x reduces to some_stream
<< x << trailing C string . But you don't get there because you have
no conversion from YourContainer::iterator and
YourContainer::value_type. The required parameter to
ostream_iterator is the type being output not an iterator.
std::copy is a loop that has *begin = *out as a part of its body. The
this is where the operator '=' stuff is coming from. So to fix this
change the template argument of ostream_iterator accordingly.
If you really want to impliment custom iterators you should check out
boost's iterator library as it make implimentation of custom iterators
easier. But this looks like a misunderstanding of the template
arguments for std::ostream_iterator<T,Ch=char,Tr=std::allocator<Ch> > ,
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
0
|
|
|
|
Reply
|
cbarron413 (16)
|
4/9/2006 9:01:44 AM
|
|
|
2 Replies
97 Views
(page loaded in 0.085 seconds)
Similiar Articles: SMO (sequential minimal optimization) and matlab - comp.ai.neural ...... on matlab of SMO algorithm, can anyboby help me?? ... You probably do not want to implement SMO in matlab; rather you ... SMO (Sequential Minimal Optimization) code for Matlab ... [threeparttable] alignment of the tablenotes and space of \tnote ...Of course, if implementing would be much ... Thank you for your help and best regards, Stefan % ----- minimal example ... behavior of \tnote is what is wanted 99 ... peek() vs unget(): which is better? - comp.lang.c++.moderated ...... in loops an std::istreambuf_iterator ... Unless I wanted to handle different input encodings. But then, neither <locale> nor <locale.h> are much help; in UTF-8, the ... Non-member operator overloading, linker complains - comp.lang.c++ ...... const Matrix<T, d, e>& m ); etc. should help ... mRes( m ); > Matrix<T, d, e>::data_type::iterator ... will complain. ... is also useful when I want to implement an ... boost multi index - possible? - comp.lang.c++.moderatedBut if i want all entries containing say a1, how to ... boost/utility.hpp> #include <iostream> #include <iterator ... just couple of questions more: > 1. how to implement ... Simple code encryption (xor) problem - comp.lang.asm.x86 ...I'm learning to code in masm and I wanted to write ... the Keylength mov ecx, 0 ;zeroing the main iterator ... finite element), then pure speed coding with minimal ... Direct form II transposed implementation - comp.dspI'd like to implement 2nd or 3rd order IIR low-pass filter ... if you have a value of 0 in an integrator and you want ... why would using a DF2T help over using a simple DF1? which ntpd ? OpenBSD openntpd, BSD ntpd, other ? - comp.protocols ...... computing the time drift of the server's clock. Thanks for help ... implement is the the clock frequency correction that was wanted here, although an SNTP could implement it ... Java Collections List : Converting from List '... returns a list like this:- List > Next I want ... Note that with a little effort, you can implement a .NET ... Override public java.util.Iterator<S> iterator ... Full example of memoir documentclass preamble - comp.text.tex ...... latex/bog/ (in Danish) Remember to post minimal ... of deciding what you need before you look how to implement ... you've said nothing about what you want to do; the ... Help With Iterator Constructor Without Implementing Iterator ...Help with iterator constructor without implementing Iterator interface ... return false; } // You might want to ... should be able to do this with only minimal ... Implementing Iterator - Activity Stream - Java Programming ForumUn can create your own iterator implementing that ... the next() method, this will help u ... that variable and you don't want that. Build a separate class for the Iterator ... 7/26/2012 2:27:52 AM
|
|
|
|
|
|
|
|
|